• <small id='XBzcm'></small><noframes id='XBzcm'>

  • <tfoot id='XBzcm'></tfoot>
    <i id='XBzcm'><tr id='XBzcm'><dt id='XBzcm'><q id='XBzcm'><span id='XBzcm'><b id='XBzcm'><form id='XBzcm'><ins id='XBzcm'></ins><ul id='XBzcm'></ul><sub id='XBzcm'></sub></form><legend id='XBzcm'></legend><bdo id='XBzcm'><pre id='XBzcm'><center id='XBzcm'></center></pre></bdo></b><th id='XBzcm'></th></span></q></dt></tr></i><div id='XBzcm'><tfoot id='XBzcm'></tfoot><dl id='XBzcm'><fieldset id='XBzcm'></fieldset></dl></div>
    1. <legend id='XBzcm'><style id='XBzcm'><dir id='XBzcm'><q id='XBzcm'></q></dir></style></legend>

          <bdo id='XBzcm'></bdo><ul id='XBzcm'></ul>

        如何让 CMake 在 Ubuntu 上识别 pthread?

        时间:2023-08-26
          <bdo id='yc5Rt'></bdo><ul id='yc5Rt'></ul>
          • <tfoot id='yc5Rt'></tfoot>
            <legend id='yc5Rt'><style id='yc5Rt'><dir id='yc5Rt'><q id='yc5Rt'></q></dir></style></legend>
            <i id='yc5Rt'><tr id='yc5Rt'><dt id='yc5Rt'><q id='yc5Rt'><span id='yc5Rt'><b id='yc5Rt'><form id='yc5Rt'><ins id='yc5Rt'></ins><ul id='yc5Rt'></ul><sub id='yc5Rt'></sub></form><legend id='yc5Rt'></legend><bdo id='yc5Rt'><pre id='yc5Rt'><center id='yc5Rt'></center></pre></bdo></b><th id='yc5Rt'></th></span></q></dt></tr></i><div id='yc5Rt'><tfoot id='yc5Rt'></tfoot><dl id='yc5Rt'><fieldset id='yc5Rt'></fieldset></dl></div>
              <tbody id='yc5Rt'></tbody>

                <small id='yc5Rt'></small><noframes id='yc5Rt'>

                  本文介绍了如何让 CMake 在 Ubuntu 上识别 pthread?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果我直接在命令行上用 g++ 编译,我可以看到我需要的一切都在那里:

                  If I compile on the command-line with g++ directly, I can see everything I need is there:

                  $ g++ -pthread test.cpp
                  $ ldd a.out
                      linux-vdso.so.1 =>  (0x00007fffd05b3000)
                      libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f4a1ba8d000)
                      libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4a1b870000)
                      ...more...
                  

                  然后我尝试为这个 5 行测试应用程序创建一个简单的 cmake 文件:

                  Then I try to create a simple cmake file for this 5-line test app:

                  $ cat CMakeLists.txt 
                  PROJECT ( Test CXX )
                  CMAKE_MINIMUM_REQUIRED ( VERSION 2.8 )
                  FIND_PACKAGE ( Threads REQUIRED )
                  ADD_EXECUTABLE ( test test.cpp )
                  TARGET_LINK_LIBRARIES ( test ${CMAKE_THREAD_LIBS_INIT} )
                  

                  但是,我不明白为什么 CMake 没有找到它需要用于 Threads 的内容:

                  However, I cannot figure out why CMake doesn't find what it needs to use for Threads:

                  $ cd build/
                  $ cmake ..
                  CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:97 (MESSAGE):
                    Could NOT find Threads (missing: Threads_FOUND)
                  Call Stack (most recent call first):
                    /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:288 (_FPHSA_FAILURE_MESSAGE)
                    /usr/share/cmake-2.8/Modules/FindThreads.cmake:166 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
                    CMakeLists.txt:4 (FIND_PACKAGE)
                  -- Configuring incomplete, errors occurred!
                  

                  推荐答案

                  哦,这太痛苦了!我可能为此浪费了 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:

                  PROJECT ( Test CXX )
                  

                  ...将 C 作为一种语言包含进来:

                  ...to include C as a language:

                  PROJECT ( Test C CXX )
                  

                  然后删除build,重新创建它,然后一切正常:

                  Then delete build, recreate it, and everything then works:

                  rm -rf build
                  mkdir build
                  cd build
                  cmake ..
                  

                  这篇关于如何让 CMake 在 Ubuntu 上识别 pthread?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 CMake 在 VS2017 中启用/std:c++17 下一篇:通过 dll 边界传递对 STL 向量的引用

                  相关文章

                  <tfoot id='wVvqA'></tfoot>

                    <i id='wVvqA'><tr id='wVvqA'><dt id='wVvqA'><q id='wVvqA'><span id='wVvqA'><b id='wVvqA'><form id='wVvqA'><ins id='wVvqA'></ins><ul id='wVvqA'></ul><sub id='wVvqA'></sub></form><legend id='wVvqA'></legend><bdo id='wVvqA'><pre id='wVvqA'><center id='wVvqA'></center></pre></bdo></b><th id='wVvqA'></th></span></q></dt></tr></i><div id='wVvqA'><tfoot id='wVvqA'></tfoot><dl id='wVvqA'><fieldset id='wVvqA'></fieldset></dl></div>
                      <bdo id='wVvqA'></bdo><ul id='wVvqA'></ul>

                    <small id='wVvqA'></small><noframes id='wVvqA'>

                  1. <legend id='wVvqA'><style id='wVvqA'><dir id='wVvqA'><q id='wVvqA'></q></dir></style></legend>