# c-cpp **Repository Path**: webthree/c-cpp ## Basic Information - **Project Name**: c-cpp - **Description**: c-cpp项目集合演示库 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-04-26 - **Last Updated**: 2023-04-26 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # T-early > C语言学习展示 ### 手动编译链接 1. 预编译 ```shell gcc -E helloworld.c -o helloworld.i ``` 2. 编译汇编指令 ```shell gcc -S helloworld.i -o helloworld.s ``` 3. 生成目标文件 ```shell gcc -c helloworld.s -o helloworld.o ``` 4. 自动链接库得到可执行文件 ```shell gcc -v helloworld.o -o helloworld ``` #### 编译静态链接库 ```shell gcc -c helloworld.c ar rcs libhellowrold.a helloworld.o ar t libhellowrold.a gcc main.c libhellowrold.a -o helloworld ``` #### 编译动态链接库 ```shell # linux gcc -shared -fPIC helloworld.c -o libhellowrold.dll #widows gcc -shared -fPIC -Wl,--out-implib,libhellowrold.lib helloworld.c -o libhellowrold.dll objdump -t libhellowrold.dll gcc main.c -L. -lhelloworld -o helloworld # 加载链接库默认是运行路径,如果没有则找PATH路径 ``` ### CMAKE编译 #### 动态链接库子模块 ```cmake if (WIN32) set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS 1) endif () add_library(helloworld SHARED helloworld.c) install(TARGETS helloworld RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib/static ) ``` #### 静态链接库子模块 ```cmake add_library(helloworld STATIC helloworld.c) ``` #### 主模块配置 ```cmake set(CMAKE_INSTALL_PREFIX install) if (APPLE) set(CMAKE_INSTALL_RPATH @loader_path/../lib) elseif (UNIX) set(CMAKE_INSTALL_RPATH \$ORIGIN/../lib) endif () add_subdirectory(helloworld) target_link_libraries(main helloworld) install(TARGETS main RUNTIME DESTINATION bin) ``` #### 引入Conan生成配置 ```cmake include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) ```