linux - CMake 链接节俭

标签 linux cmake thrift

我正在尝试在 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/

相关文章:

C++:构建选项 "-j"是什么意思?

java - 如何将生成的源文件夹添加到 Gradle 和 IntelliJ 中的源路径?

java - Thrift TNonblockingServer EOF 异常

linux - PuTTY:Linux 窗口 - 如何在函数执行期间更新窗口标题?

linux - 客户端证书 clientcert.pem 尚未激活

c - linux中的标准输入是什么意思?

linux - 使用 bash 在文件中查找字符串

opencv - 在树莓派上使用cmake构建opencv时出错

c++ - 使用 QT5_ADD_RESOURCES 和使用 CMake 进行多线程编译时损坏的资源 .cpp 文件

java - 关于thrift函数返回列表