详细输出:
--trace-expand
use g++ compile c files:
set_source_files_properties(filename.c PROPERTIES LANGUAGE CXX )
指定g++,gcc:
CC=.../gcc CXX=.../g++ cmake .....
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)