如何让 CMake 在 Ubuntu 上识别 pthread?
问题描述
如果我直接在命令行上用 g++ 编译,我可以看到我需要的一切都在那里:
If I compile on the command-line with g++ directly, I can see everything I need is there:
然后我尝试为这个 5 行测试应用程序创建一个简单的 cmake 文件:
Then I try to create a simple cmake file for this 5-line test app:
但是,我不明白为什么 CMake 没有找到它需要用于 Threads
的内容:
However, I cannot figure out why CMake doesn't find what it needs to use for Threads
:
推荐答案
哦,这太痛苦了!我可能为此浪费了 2 个小时.解决办法如下:
Oh, this was was a pain! I probably lost 2 hours on this. Here is the solution:
CMake 使用简短的C"应用程序来测试/尝试事物.如果 CMakeLists.txt 声明项目使用了 C++,而没有列出 C,那么其中一些 shorts 测试错误地失败了,然后 cmake 认为这些东西没有找到.
CMake uses short 'C' applications to test/try things. If the CMakeLists.txt states that C++ is used for the project, without also listing C, then some of those shorts tests incorrectly fail, and cmake then thinks those things aren't found.
解决方案是从这里更改 CMakeLists 的第一行:
The solution was to change the first line of CMakeLists from this:
...将 C 作为一种语言包含进来:
...to include C as a language:
然后删除build
,重新创建它,然后一切正常:
Then delete build
, recreate it, and everything then works:
这篇关于如何让 CMake 在 Ubuntu 上识别 pthread?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!