Skip to content

Instantly share code, notes, and snippets.

@Aruise
Created May 31, 2019 03:52
Show Gist options
  • Select an option

  • Save Aruise/4527b4d7f501115ec7c4a23ac6c9f4d9 to your computer and use it in GitHub Desktop.

Select an option

Save Aruise/4527b4d7f501115ec7c4a23ac6c9f4d9 to your computer and use it in GitHub Desktop.
Lav3

Tutorial

$ export GITHUB_USERNAME=<имя_пользователя>
$ export GITHUB_USERNAME=<имя_пользователя> #создание имени 
$ cd ${GITHUB_USERNAME}/workspace
$ pushd .
$ source scripts/activate
$ cd ${GITHUB_USERNAME}/workspace #переход в папку workspace
$ pushd . #запоминание текущего каталога
$ source scripts/activate выполнение скрипта
$ git clone https://github.com/${GITHUB_USERNAME}/lab02.git projects/lab03
$ cd projects/lab03
$ git remote remove origin
$ git remote add origin https://github.com/${GITHUB_USERNAME}/lab03.git
$ git clone https://github.com/${GITHUB_USERNAME}/lab02.git projects/lab03 #создание копии репозитория
$ cd projects/lab03 #переход в папку lab03
$ git remote remove origin #удаление соединения с репозиторием
$ git remote add origin https://github.com/${GITHUB_USERNAME}/lab03.git #создание новой связи с репозиторием
$ g++ -std=c++11 -I./include -c sources/print.cpp
$ g++ -std=c++11 -I./include -c sources/print.cpp  
$ ls print.o
$ nm print.o | grep print
$ ar rvs print.a print.o
$ file print.a
$ g++ -std=c++11 -I./include -c examples/example1.cpp
$ nm print.o | grep print #вывод информации о файле
$ ar rvs print.a print.o #добавление файла в архив
$ file print.a #печать файла
$ g++ -std=c++11 -I./include -c examples/example1.cpp #компиляция файла
$ ls example1.o
$ g++ example1.o print.a -o example1
$ ./example1 && echo
$ g++ example1.o print.a -o example1 #сборка
$ ./example1 && echo #вывести результат
$ g++ -std=c++11 -I./include -c examples/example2.cpp
$ nm example2.o
$ g++ example2.o print.a -o example2
$ ./example2
$ cat log.txt && echo
$ g++ -std=c++11 -I./include -c examples/example2.cpp  #аналогично, 
$ nm example2.o                             #как
$ g++ example2.o print.a -o example2         #в
$ ./example2                                #предыдущем блоке
$ cat log.txt && echo    #создание файла и запись в него результат прогораммы
```ShellSession #удаление файлоа
$ rm -rf example1.o example2.o print.o
$ rm -rf print.a
$ rm -rf example1 example2
$ rm -rf log.txt
$ cat > CMakeLists.txt <<EOF
$ cat > CMakeLists.txt <<EOF #запись в файл до EOF
cmake_minimum_required(VERSION 3.4)
project(print)
EOF
$ cat >> CMakeLists.txt <<EOF
$ cat >> CMakeLists.txt <<EOF #запись в файл до EOF
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
EOF
$ cat >> CMakeLists.txt <<EOF
$ cat >> CMakeLists.txt <<EOF #запись в файл до EOF
add_library(print STATIC \${CMAKE_CURRENT_SOURCE_DIR}/sources/print.cpp)
EOF
$ cat >> CMakeLists.txt <<EOF
$ cat >> CMakeLists.txt <<EOF #запись в файл до EOF
include_directories(\${CMAKE_CURRENT_SOURCE_DIR}/include)
EOF
$ cmake -H. -B_build
$ cmake -H. -B_build #сборка
$ cmake --build _build
$ cat >> CMakeLists.txt <<EOF
$ cat >> CMakeLists.txt <<EOF #запись в файл

add_executable(example1 \${CMAKE_CURRENT_SOURCE_DIR}/examples/example1.cpp)
add_executable(example1 \${CMAKE_CURRENT_SOURCE_DIR}/examples/example1.cpp) #компиляция
add_executable(example2 \${CMAKE_CURRENT_SOURCE_DIR}/examples/example2.cpp)
EOF
$ cat >> CMakeLists.txt <<EOF

target_link_libraries(example1 print)
target_link_libraries(example1 print) #компоновка
target_link_libraries(example2 print)
EOF
```ShellSession #сборка
$ cmake --build _build
$ cmake --build _build --target print
$ cmake --build _build --target example1
$ cmake --build _build --target example2
$ ls -la _build/libprint.a
$ _build/example1 && echo
$ ls -la _build/libprint.a #печать
$ _build/example1 && echo #запуск программы
hello
$ _build/example2
$ cat log.txt && echo
$ _build/example2 #запуск программы
$ cat log.txt && echo #создание файла и зарись в него
hello
$ rm -rf log.txt
$ rm -rf log.txt #удаление файла
$ git clone https://github.com/tp-labs/lab03 tmp
$ mv -f tmp/CMakeLists.txt .
$ rm -rf tmp
$ git clone https://github.com/tp-labs/lab03 tmp #копирование репозитория
$ mv -f tmp/CMakeLists.txt . #перемещаем файл в текущую папку
$ rm -rf tmp #удаление
$ cat CMakeLists.txt
$ cat CMakeLists.txt 
$ cmake -H. -B_build -DCMAKE_INSTALL_PREFIX=_install
$ cmake --build _build --target install
$ cmake --build _build --target install #вывод дерева проекта
$ tree _install
$ git add CMakeLists.txt
$ git commit -m"added CMakeLists.txt"
$ git push origin master
$ git add CMakeLists.txt #добавление файла в репозиторий
$ git commit -m"added CMakeLists.txt" #коммит
$ git push origin master #соединение репозиториев

Report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment