我想使用CMake从libfoo.a创建一个liboo.so。
到目前为止我已经
了include_directories(third-party/includes)
find_library(${thirdparty_LIBRARIES} foo PATHS third-party/lib)
add_library(boo SHARED empty.cpp)
target_link_libraries(boo ${thirdparty_LIBRARIES})
add_executable(runBoo main.cpp)
target_link_libraries(runBoo boo)
其中main调用函数来自libfoo.so。但引发错误:
main.cpp:(.text+0x26): undefined reference to `Foo::Foo()'
main.cpp:(.text+0x50): undefined reference to `Foo::sayHello(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
我猜这些符号没有添加,因为empty.cpp没有使用它们,但我不确定这是问题以及如何克服它。
我见过CMake: how create a single shared library from all static libraries of subprojects?,但我现在更愿意坚持使用较低版本的cmake。
我也看过how to link static library into dynamic library in gcc但我无法让它工作,而且我还在使用CMake。
答案 0 :(得分:0)
只是一个愚蠢的错误。更正的代码是:
include_directories(third-party/includes)
find_library(thirdparty_LIBRARIES foo PATHS third-party/lib) //remove the ${}!
add_library(boo SHARED empty.cpp)
target_link_libraries(boo ${thirdparty_LIBRARIES})
add_executable(runBoo main.cpp)
target_link_libraries(runBoo boo)