C++ 如何使用CMake为静态库(不使用源文件)创建共享库包装器?

C++ 如何使用CMake为静态库(不使用源文件)创建共享库包装器?,c++,cmake,shared-libraries,static-libraries,C++,Cmake,Shared Libraries,Static Libraries,我想使用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(runBo

我想使用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> >)'
main.cpp:(.text+0x26):对“Foo::Foo()”的未定义引用
main.cpp:(.text+0x50):对“Foo::sayHello(std::basic_string)”的未定义引用
我猜这些符号没有添加,因为empty.cpp没有使用它们,但我不确定这是问题所在,以及如何克服它

我看到了,但我现在更愿意使用较低版本的cmake


我也看到了,但我无法让它工作,我正在使用CMake。

只是一个愚蠢的错误。更正后的代码为:

   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)

可以设置Try(CMAKE_SHARED_LINKER_FLAGS“-Wl,--导出所有符号”)@Archie/usr/bin/ld:无法识别的选项“-export-all-symbols”哦,Try-导出动态。抱歉,无法立即尝试。哎呀,愚蠢的错误${thirdparty_LIBRARIES}应该是thirdparty_LIBRARIES。现在它起作用了。您评论的标志不是必需的。