2013-04-09 34 views
0

我想使用CMake从libfoo.a创建一个liboo.so。如何使用CMake为静态库(不使用源文件)创建共享库包装?

到目前为止,我有

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) 

,其中来自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

尝试可以设置(CMAKE_SHARED_LINKER_FLAGS “轮候册, - 出口的所有符号”) – Archie 2013-04-09 13:44:31

+0

@Archie在/ usr/bin中/ LD:无法识别的选项“--export-所有符号' – quimnuss 2013-04-09 13:48:10

+0

哦,试试--export-dynamic。抱歉,无法立即尝试。 – Archie 2013-04-09 14:57:22

回答

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) 
相关问题