Missmiaom
5/7/2020 - 6:20 AM

cmake

skill

详细输出

--trace-expand

use g++ compile c files:

set_source_files_properties(filename.c PROPERTIES LANGUAGE CXX )

指定g++,gcc:

CC=.../gcc CXX=.../g++ cmake .....

指定protobuf

set(PROTOBUF_ROOT xxx)
set(Protobuf_USE_STATIC_LIBS ON)
set(Protobuf_INCLUDE_DIR ${PROTOBUF_ROOT}/include)
include(${PROTOBUF_ROOT}/lib64/cmake/protobuf/protobuf-config.cmake)
include(${PROTOBUF_ROOT}/lib64/cmake/protobuf/protobuf-module.cmake)
include(${PROTOBUF_ROOT}/lib64/cmake/protobuf/protobuf-options.cmake)
include(${PROTOBUF_ROOT}/lib64/cmake/protobuf/protobuf-targets.cmake)
find_package( Protobuf REQUIRED HINTS ${PROTOBUF_ROOT}/lib64/cmake/protobuf )

生成动态库链接静态库

ld执行时,默认会把静态库中不使用的函数过滤掉,导致生成的动态库文件不能包含所有的函数。所以需要配置ld的选项 --whole-archive

target_link_libraries(sdk 
 "-Wl,--whole-archive" #之后的库使用--whole-archive选项
 libstaic.a
 "-Wl,--no-whole-archive")  #之后的库不使用--whole-archive选项

指定安装目录

-DCMAKE_INSTALL_PREFIX=../install

添加编译参数

add_compile_options(-fPIC)