【问题标题】:make throws error looking for boost libraries查找 boost 库时抛出错误
【发布时间】:2021-09-02 15:29:39
【问题描述】:

我正在尝试编译一个使用 Boost 的 C++ 项目。我已经在 Windows 机器上尝试过这个(首先尝试使用 cygwin,然后使用 Visual Studio)以及 Macbook。我继续遇到cmake 会发现 Boost 就好了,但make 会告诉我它找不到它需要寻找的第一个 boost 库的问题。我试过使用make -I/path/to/boost/parent/directory/ 并且输出是相同的。

我在下面附上了cmake ..make 的Mac 终端输出。我还将包括我采取的步骤,并尝试剖析问题:

  1. brew install boost
  2. git clone git-repo
  3. mkdir buildcmake ..make

我还重新安装了 boost,重新安装了 brew,并检查了编译器是否使用了正确的包含路径。 CMakeLists.txtfind_package(Boost REQUIRED) 行。执行所有这些操作会产生如下所示的相同结果。

任何解决此问题的帮助将不胜感激。

mudly@MyMac build % cmake ..

-- The C compiler identification is AppleClang 12.0.5.12050022
-- The CXX compiler identification is AppleClang 12.0.5.12050022
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost: /usr/local/lib/cmake/Boost-1.76.0/BoostConfig.cmake (found version "1.76.0")  
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES) 
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES) 
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND) 
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/mudly/source/matching/matching/build
mudly@MyMac build % make

[ 10%] Building CXX object CMakeFiles/matching_distance_test.dir/tests/test_bifiltration.cpp.o
[ 20%] Building CXX object CMakeFiles/matching_distance_test.dir/tests/test_common.cpp.o
In file included from /Users/mudly/source/matching/matching/tests/test_common.cpp:9:
In file included from /Users/mudly/source/matching/matching/include/matching_distance.h:19:
In file included from /Users/mudly/source/matching/matching/../bottleneck/include/bottleneck.h:41:
In file included from /Users/mudly/source/matching/matching/../bottleneck/include/bottleneck_detail.h:41:
In file included from /Users/mudly/source/matching/matching/../bottleneck/include/bound_match.h:36:
In file included from /Users/mudly/source/matching/matching/../bottleneck/include/neighb_oracle.h:37:
/Users/mudly/source/matching/matching/../bottleneck/include/dnn/geometry/euclidean-fixed.h:4:10: fatal error: 'boost/operators.hpp' file not found

#include <boost/operators.hpp>

         ^~~~~~~~~~~~~~~~~~~~~

1 error generated.
make[2]: *** [CMakeFiles/matching_distance_test.dir/tests/test_common.cpp.o] Error 1
make[1]: *** [CMakeFiles/matching_distance_test.dir/all] Error 2
make: *** [all] Error 2

【问题讨论】:

  • "...使用 make -I/path/to/boost/..." 这应该是 boost 的父目录,因为 #include &lt;boost/operators.hpp&gt; 包括 boost/在要包含的文件的名称中。
  • @RichardCritten 感谢您的来信。我在编辑计算机上的实际路径方面是一个骑士,但我确实使用了父目录。我将编辑帖子以反映更准确的路径
  • 查看make 用来调用编译器的确切命令可能会有所帮助(确保所需的标志在那里并且它们与系统上的目录结构相匹配)。跨度>

标签: c++ macos boost cmake


【解决方案1】:

我已经解决了这个问题。在 CMake 文件中添加行 include_directories(/path/to/libraries/) 就足够了。

【讨论】:

  • 在大多数情况下,include_directories 实际上足以解决“找不到文件”编译器错误。但是您希望我们提供什么样的帮助,因为我们不知道 CMakeLists.txt 的内容,除了它的单行 (find_package(Boost REQUIRED))?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-11-28
  • 1970-01-01
  • 1970-01-01
  • 2019-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多