我正在尝试将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头文件。
#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
然而,旧图书馆肯定已经安装好了。
如何链接修复此问题并在CMake文件中正确链接它们?