Clang 未能在 non-standard 位置找到 header 文件

Clang failing to find header files in non-standard location

我目前正在尝试构建 OpenPose。首先,我将尝试描述环境,然后描述从中出现的错误。 Caffe 是从源代码构建的,完全位于 [/Users...]/openpose/3rdparty 而不是通常的位置(出于隐私考虑,我在 post 中编辑了文件路径的某些部分)。它的所有包含文件都可以在 [/Users...]/openpose/3rdparty/caffe/include/caffe 中找到。输入此命令后:

make -j`sysctl -n hw.logicalcpu` CXXFLAGS=-I[/Users/..]/openpose/3rdparty/caffe/include

随后出现此错误:

[  0%] Building CXX object src/openpose/CMakeFiles/openpose.dir/core/arrayCpuGpu.cpp.o
[  1%] Building CXX object src/openpose/CMakeFiles/openpose.dir/face/faceExtractorCaffe.cpp.o
[  1%] Building CXX object src/openpose/CMakeFiles/openpose.dir/hand/handExtractorCaffe.cpp.o
[  2%] Building CXX object src/openpose/CMakeFiles/openpose.dir/net/bodyPartConnectorCaffe.cpp.o
[  2%] Building CXX object src/openpose/CMakeFiles/openpose.dir/net/maximumCaffe.cpp.o
[  2%] Building CXX object src/openpose/CMakeFiles/openpose.dir/net/netCaffe.cpp.o
[  2%] Building CXX object src/openpose/CMakeFiles/openpose.dir/net/netOpenCv.cpp.o
[  2%] Building CXX object src/openpose/CMakeFiles/openpose.dir/net/nmsCaffe.cpp.o
[/Users/..]/openpose/src/openpose/core/arrayCpuGpu.cpp:3:14: fatal error: 'caffe/blob.hpp' file not found
    #include <caffe/blob.hpp>
             ^~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [src/openpose/CMakeFiles/openpose.dir/core/arrayCpuGpu.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
[/Users/etc..]/openpose/src/openpose/net/maximumCaffe.cpp:3:14: fatal error: 'caffe/blob.hpp' file not found
    #include <caffe/blob.hpp>
             ^~~~~~~~~~~~~~~~
1 error generated.
[/Users..]/openpose/src/openpose/net/nmsCaffe.cpp:3:14: fatal error: 'caffe/blob.hpp' file not found
    #include <caffe/blob.hpp>
             ^~~~~~~~~~~~~~~~
[/Users..]/openpose/src/openpose/net/netCaffe.cpp:6:14: fatal error: 'caffe/net.hpp' file not found
    #include <caffe/net.hpp>
             ^~~~~~~~~~~~~~~
[/Users..]/openpose/src/openpose/net/netOpenCv.cpp:7:14: fatal error: 'caffe/net.hpp' file not found
    #include <caffe/net.hpp>
             ^~~~~~~~~~~~~~~
[/Users..]/openpose/src/openpose/net/bodyPartConnectorCaffe.cpp:3:14: fatal error: 'caffe/blob.hpp' file 1not error  generatedfound.

    #include <caffe/blob.hpp>
             ^~~~~~~~~~~~~~~~
make[2]: *** [src/openpose/CMakeFiles/openpose.dir/net/maximumCaffe.cpp.o] Error 1
make[2]: *** [src/openpose/CMakeFiles/openpose.dir/net/nmsCaffe.cpp.o] Error 1
[/Users..]/openpose/src/openpose/face/faceExtractorCaffe.cpp:3:14: fatal error: 'caffe/blob.hpp' file not found
    #include <caffe/blob.hpp>
             ^~~~~~~~~~~~~~~~
[/Users..]/openpose/src/openpose/hand/handExtractorCaffe.cpp:3:14: fatal error: 'caffe/blob.hpp' file not found
    #include <caffe/blob.hpp>
             ^~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [src/openpose/CMakeFiles/openpose.dir/net/netCaffe.cpp.o] Error 1
1 error generated.
make[2]: *** [src/openpose/CMakeFiles/openpose.dir/net/bodyPartConnectorCaffe.cpp.o] Error 1
1 error generated.
make[2]: *** [src/openpose/CMakeFiles/openpose.dir/net/netOpenCv.cpp.o] Error 1
1 error generated.
1 error generated.
make[2]: *** [src/openpose/CMakeFiles/openpose.dir/face/faceExtractorCaffe.cpp.o] Error 1
make[2]: *** [src/openpose/CMakeFiles/openpose.dir/hand/handExtractorCaffe.cpp.o] Error 1
make[1]: *** [src/openpose/CMakeFiles/openpose.dir/all] Error 2
make: *** [all] Error 2

为什么 clang 找不到 blob.hpp 和另一个 headers?我希望它导航到 openpose/3rdparty/caffe/include,然后从那里找到 caffe/blob.hpp 以及其他 headers。我是 make/c++ 的新手,所以除了将 CXXFLAGS 直接添加到 Makefile 而不是通过终端传递它之外,我没有尝试过很多其他方法(没有用)。 这是生成文件:https://pastebin.com/yY7R9jVe

您正在使用cmake。 cmake 生成的 makefile 不符合“标准”makefile 约定;特别是他们不使用 CXXFLAGS 变量。

当您使用 cmake 时,您不需要通过更改 make 的调用来修改编译器选项。相反,您需要通过编辑 CMakeLists.txt 文件或向用于生成 makefile 的 cmake 命令行提供覆盖值来修改编译器选项。