Skip to content

Instantly share code, notes, and snippets.

@KMACREATOR
Created June 4, 2024 17:31
Show Gist options
  • Save KMACREATOR/8d7e7009a4027536647df0b90a6bfe34 to your computer and use it in GitHub Desktop.
Save KMACREATOR/8d7e7009a4027536647df0b90a6bfe34 to your computer and use it in GitHub Desktop.

#lab03 Выполнил студент группы ИУ8-24 Конов Михаил

computer@MLK:~$ export GITHUB_USERNAME=KMACREATOR
computer@MLK:~$ cd ${GITHUB_USERNAME}/workspace
computer@MLK:~/KMACREATOR/workspace$ pushd .
~/KMACREATOR/workspace ~/KMACREATOR/workspace
computer@MLK:~/KMACREATOR/workspace$ source scripts/activate
computer@MLK:~/KMACREATOR/workspace$ git clone git@github.com:${GITHUB_USERNAME}/lab02.git projects/lab03
Клонирование в «projects/lab03»...
remote: Enumerating objects: 32, done.
remote: Counting objects: 100% (32/32), done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 32 (delta 4), reused 20 (delta 2), pack-reused 0
Получение объектов: 100% (32/32), 6.08 КиБ | 6.08 МиБ/с, готово.
Определение изменений: 100% (4/4), готово.
computer@MLK:~/KMACREATOR/workspace$ cd projects/lab03
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ git remote remove origin
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ git remote add origin git@github.com:${GITHUB_USERNAME}/lab03.git
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ g++ -std=c++11 -I./include -c sources/print.cpp
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ ls print.o
print.o
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ nm print.o | grep print
00000000000000a1 t _GLOBAL__sub_I__Z5printRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERSo
0000000000000000 T _Z5printRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERSo
000000000000002a T _Z5printRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERSt14basic_ofstreamIcS2_E
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ ar rvs print.a print.o
ar: создаётся print.a
a - print.o
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ file print.a
print.a: current ar archive
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ g++ -std=c++11 -I./include -c examples/example1.cpp
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ ls example1.o
example1.o
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ g++ example1.o print.a -o example1
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ ./example1 && echo
hello
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ g++ -std=c++11 -I./include -c examples/example2.cpp
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ nm example2.o
                 U __cxa_atexit
                 U __dso_handle
0000000000000000 V DW.ref.__gxx_personality_v0
                 U _GLOBAL_OFFSET_TABLE_
0000000000000173 t _GLOBAL__sub_I_main
                 U __gxx_personality_v0
0000000000000000 T main
                 U __stack_chk_fail
                 U _Unwind_Resume
0000000000000126 t _Z41__static_initialization_and_destruction_0ii
                 U _Z5printRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERSt14basic_ofstreamIcS2_E
                 U _ZNSaIcEC1Ev
                 U _ZNSaIcED1Ev
                 U _ZNSt14basic_ofstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode
                 U _ZNSt14basic_ofstreamIcSt11char_traitsIcEED1Ev
                 U _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1EPKcRKS3_
                 U _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev
                 U _ZNSt8ios_base4InitC1Ev
                 U _ZNSt8ios_base4InitD1Ev
0000000000000000 r _ZStL19piecewise_construct
0000000000000000 b _ZStL8__ioinit
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ g++ example2.o print.a -o example2
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ ./example2
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cat log.txt && echo
hello
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ rm -rf example1.o example2.o print.o
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ rm -rf print.a
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ rm -rf example1 example2
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ rm -rf log.txt
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cat > CMakeLists.txt <<EOF
> cmake_minimum_required(VERSION 3.4)
> project(print)
> EOF
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cat >> CMakeLists.txt <<EOF
> set(CMAKE_CXX_STANDARD 11)
> set(CMAKE_CXX_STANDARD_REQUIRED ON)
> EOF
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cat >> CMakeLists.txt <<EOF
> add_library(print STATIC \${CMAKE_CURRENT_SOURCE_DIR}/sources/print.cpp)
> EOF
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cat >> CMakeLists.txt <<EOF
> include_directories(\${CMAKE_CURRENT_SOURCE_DIR}/include)
> EOF
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cmake -H. -B_build
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/computer/KMACREATOR/workspace/projects/lab03/_build
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cmake --build _build
Scanning dependencies of target print
[ 50%] Building CXX object CMakeFiles/print.dir/sources/print.cpp.o
[100%] Linking CXX static library libprint.a
[100%] Built target print
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cat >> CMakeLists.txt <<EOF
> 
> add_executable(example1 \${CMAKE_CURRENT_SOURCE_DIR}/examples/example1.cpp)
> add_executable(example2 \${CMAKE_CURRENT_SOURCE_DIR}/examples/example2.cpp)
> EOF
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cat >> CMakeLists.txt <<EOF
> 
> target_link_libraries(example1 print)
> target_link_libraries(example2 print)
> EOF
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cmake --build _build
-- Configuring done
-- Generating done
-- Build files have been written to: /home/computer/KMACREATOR/workspace/projects/lab03/_build
[ 33%] Built target print
Scanning dependencies of target example2
[ 50%] Building CXX object CMakeFiles/example2.dir/examples/example2.cpp.o
[ 66%] Linking CXX executable example2
[ 66%] Built target example2
Scanning dependencies of target example1
[ 83%] Building CXX object CMakeFiles/example1.dir/examples/example1.cpp.o
[100%] Linking CXX executable example1
[100%] Built target example1
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cmake --build _build --target print
[100%] Built target print
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cmake --build _build --target example1
[ 50%] Built target print
[100%] Built target example1
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cmake --build _build --target example2
[ 50%] Built target print
[100%] Built target example2
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ ls -la _build/libprint.a
-rw-rw-r-- 1 computer computer 3286 июн  4 20:07 _build/libprint.a
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ _build/example1 && echo
hello
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ 
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ _build/example2
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cat log.txt && echo
hello
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ rm -rf log.txt
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ git clone git@github.com:tp-labs/lab03 tmp
Клонирование в «tmp»...
remote: Enumerating objects: 91, done.
remote: Counting objects: 100% (30/30), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 91 (delta 23), reused 21 (delta 21), pack-reused 61
Получение объектов: 100% (91/91), 1.02 МиБ | 1.37 МиБ/с, готово.
Определение изменений: 100% (41/41), готово.
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ mv -f tmp/CMakeLists.txt .
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ rm -rf tmp
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.4)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(BUILD_EXAMPLES "Build examples" OFF)

project(print)

add_library(print STATIC ${CMAKE_CURRENT_SOURCE_DIR}/sources/print.cpp)

target_include_directories(print PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
)

if(BUILD_EXAMPLES)
  file(GLOB EXAMPLE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/examples/*.cpp")
  foreach(EXAMPLE_SOURCE ${EXAMPLE_SOURCES})
    get_filename_component(EXAMPLE_NAME ${EXAMPLE_SOURCE} NAME_WE)
    add_executable(${EXAMPLE_NAME} ${EXAMPLE_SOURCE})
    target_link_libraries(${EXAMPLE_NAME} print)
    install(TARGETS ${EXAMPLE_NAME}
      RUNTIME DESTINATION bin
    )
  endforeach(EXAMPLE_SOURCE ${EXAMPLE_SOURCES})
endif()

install(TARGETS print
    EXPORT print-config
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION include)
install(EXPORT print-config DESTINATION cmake)
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cmake -H. -B_build -DCMAKE_INSTALL_PREFIX=_install
-- Configuring done
-- Generating done
-- Build files have been written to: /home/computer/KMACREATOR/workspace/projects/lab03/_build
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ cmake --build _build --target install
[100%] Built target print
Install the project...
-- Install configuration: ""
-- Installing: /home/computer/KMACREATOR/workspace/projects/lab03/_install/lib/libprint.a
-- Installing: /home/computer/KMACREATOR/workspace/projects/lab03/_install/include
-- Installing: /home/computer/KMACREATOR/workspace/projects/lab03/_install/include/print.hpp
-- Installing: /home/computer/KMACREATOR/workspace/projects/lab03/_install/cmake/print-config.cmake
-- Installing: /home/computer/KMACREATOR/workspace/projects/lab03/_install/cmake/print-config-noconfig.cmake
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ tree _install
_install
|-- cmake
|   |-- print-config-noconfig.cmake
|   `-- print-config.cmake
|-- include
|   `-- print.hpp
`-- lib
    `-- libprint.a

4 directories, 4 files
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ git add CMakeLists.txt
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ git commit -m"added CMakeLists.txt"
[main e8b191d] added CMakeLists.txt
 1 file changed, 36 insertions(+)
 create mode 100644 CMakeLists.txt
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ git push origin main
Перечисление объектов: 35, готово.
Подсчет объектов: 100% (35/35), готово.
При сжатии изменений используется до 4 потоков
Сжатие объектов: 100% (23/23), готово.
Запись объектов: 100% (35/35), 6.77 КиБ | 6.77 МиБ/с, готово.
Всего 35 (изменения 5), повторно использовано 31 (изменения 4)
remote: Resolving deltas: 100% (5/5), done.
To github.com:KMACREATOR/lab03.git
 * [new branch]      main -> main
computer@MLK:~/KMACREATOR/workspace/projects/lab03$ popd
~/KMACREATOR/workspace
computer@MLK:~/KMACREATOR/workspace$ export LAB_NUMBER=03
computer@MLK:~/KMACREATOR/workspace$ git clone git@github.com:tp-labs/lab${LAB_NUMBER} tasks/lab${LAB_NUMBER}
Клонирование в «tasks/lab03»...
remote: Enumerating objects: 91, done.
remote: Counting objects: 100% (30/30), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 91 (delta 23), reused 21 (delta 21), pack-reused 61
Получение объектов: 100% (91/91), 1.02 МиБ | 1.64 МиБ/с, готово.
Определение изменений: 100% (41/41), готово.
computer@MLK:~/KMACREATOR/workspace$ mkdir reports/lab${LAB_NUMBER}
computer@MLK:~/KMACREATOR/workspace$ cp tasks/lab${LAB_NUMBER}/README.md reports/lab${LAB_NUMBER}/REPORT.md
computer@MLK:~/KMACREATOR/workspace$ cd reports/lab${LAB_NUMBER}
computer@MLK:~/KMACREATOR/workspace/reports/lab03$ edit REPORT.md
computer@MLK:~/KMACREATOR/workspace/reports/lab03 gist REPORT.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment