我正在尝试在 CMake 中链接 thrift,以便我可以编译我的测试应用程序。
cmake_minimum_required(VERSION 3.10)
project(TestApp)
set(CMAKE_CXX_STANDARD 11)
add_executable(TestApp main.cpp)
target_link_libraries(TestApp -lthrift --static -pthread )
这是一个简单的测试应用程序,包括 thrift header 。
#include <iostream>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/transport/TSocket.h>
#include <thrift/transport/TBufferTransports.h>
#include <thrift/transport/TTransportUtils.h>
#include <thrift/stdcxx.h>
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
int main() {
std::cout << "BlaBlaBla" << std::endl;
return 0;
}
当我尝试编译上面显示的代码片段时,出现链接器错误提示:
/opt/JetBrains/apps/CLion/ch-0/181.5087.36/bin/cmake/bin/cmake --build /home/user/Documents/Projects/TestApp/cmake-build-debug --target TestApp -- -j 2
[ 50%] Linking CXX executable TestApp
/usr/bin/ld: cannot find -lthrift
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/TestApp.dir/build.make:95: TestApp] Error 1
make[2]: *** [CMakeFiles/Makefile2:68: CMakeFiles/TestApp.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:80: CMakeFiles/TestApp.dir/rule] Error 2
make: *** [Makefile:118: TestApp] Error 2
但是,肯定安装了 thrift 库。 如何链接解决此问题并在 CMake 文件中正确链接它们?
最佳答案
通过从 github https://github.com/apache/thrift 克隆 thrift 存储库解决了这个问题。
然后我只是按照那里的构建说明进行操作。
我确实运行了 ./bootstrap.sh
和 ./configure
,然后是 make
,然后是 sudo make install
。
现在链接器可以识别 -lthrift
标志。
关于linux - CMake 链接节俭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51046316/