[英]Include search path on Mac OS X Yosemite 10.10.1
I just to change the include search path order (I believe). 我只是想改变包含搜索路径顺序(我相信)。
/usr/local/include
first.
/usr/local/include
。
But it doesn't change because of duplicate. 但由于重复,它不会改变。 How can I change it?
我该怎么改变它?
I suppose there's default setting, because paths I don't specify appears. 我想有默认设置,因为我没有指定的路径出现。 Like
/usr/include/c++/4.2.1
, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include
像
/usr/include/c++/4.2.1
, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include
Machida-no-MacBook-Air:caffe machidahiroaki$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -v ...
@(#)PROGRAM:ld PROJECT:ld64-241.9
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7m armv7em
Library search paths:
/usr/lib
/usr/local/lib
Framework search paths:
/Library/Frameworks/
/System/Library/Frameworks/
Machida-no-MacBook-Air:caffe machidahiroaki$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -v ... @(#)PROGRAM:ld PROJECT:ld64-241.9 configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7m armv7em Library search paths: /usr/lib /usr/local/lib Framework search paths: /Library/Frameworks/ /System/Library/Frameworks/
For sure this is the ld
done in make
. 肯定这是在
make
完成的ld
。
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -dylib -arch x86_64 -macosx_version_min 10.10.0 -t -o .build_debug/lib/libcaffe.so -L/usr/local/lib -L/usr/lib -L/usr/local/atlas/lib .build_debug/src/caffe/proto/caffe.pb.o .build_debug/src/caffe/proto/caffe_pretty_print.pb.o .build_debug/src/caffe/blob.o .build_debug/src/caffe/common.o .build_debug/src/caffe/data_transformer.o .build_debug/src/caffe/internal_thread.o .build_debug/src/caffe/layer_factory.o .build_debug/src/caffe/layers/absval_layer.o .build_debug/src/caffe/layers/accuracy_layer.o .build_debug/src/caffe/layers/argmax_layer.o .build_debug/src/caffe/layers/base_data_layer.o .build_debug/src/caffe/layers/bnll_layer.o .build_debug/src/caffe/layers/concat_layer.o .build_debug/src/caffe/layers/contrastive_loss_layer.o .build_debug/src/caffe/layers/conv_layer.o .build_debug/src/caffe/layers/cudnn_conv_layer.o .build_debug/src/caffe/layers/cudnn_pooling_layer.o .build_debug/src/caffe/layers/cudnn_relu_layer.o .build_debug/src/caffe/layers/cudnn_sigmoid_layer.o .build_debug/src/caffe/layers/cudnn_softmax_layer.o .build_debug/src/caffe/layers/cudnn_tanh_layer.o .build_debug/src/caffe/layers/data_layer.o .build_debug/src/caffe/layers/dropout_layer.o .build_debug/src/caffe/layers/dummy_data_layer.o .build_debug/src/caffe/layers/eltwise_layer.o .build_debug/src/caffe/layers/euclidean_loss_layer.o .build_debug/src/caffe/layers/flatten_layer.o .build_debug/src/caffe/layers/hdf5_data_layer.o .build_debug/src/caffe/layers/hdf5_output_layer.o .build_debug/src/caffe/layers/hinge_loss_layer.o .build_debug/src/caffe/layers/im2col_layer.o .build_debug/src/caffe/layers/image_data_layer.o .build_debug/src/caffe/layers/infogain_loss_layer.o .build_debug/src/caffe/layers/inner_product_layer.o .build_debug/src/caffe/layers/loss_layer.o .build_debug/src/caffe/layers/lrn_layer.o .build_debug/src/caffe/layers/memory_data_layer.o .build_debug/src/caffe/layers/multinomial_logistic_loss_layer.o .build_debug/src/caffe/layers/mvn_layer.o .build_debug/src/caffe/layers/neuron_layer.o .build_debug/src/caffe/layers/pooling_layer.o .build_debug/src/caffe/layers/power_layer.o .build_debug/src/caffe/layers/relu_layer.o .build_debug/src/caffe/layers/sigmoid_cross_entropy_loss_layer.o .build_debug/src/caffe/layers/sigmoid_layer.o .build_debug/src/caffe/layers/silence_layer.o .build_debug/src/caffe/layers/slice_layer.o .build_debug/src/caffe/layers/softmax_layer.o .build_debug/src/caffe/layers/softmax_loss_layer.o .build_debug/src/caffe/layers/split_layer.o .build_debug/src/caffe/layers/tanh_layer.o .build_debug/src/caffe/layers/threshold_layer.o .build_debug/src/caffe/layers/window_data_layer.o .build_debug/src/caffe/net.o .build_debug/src/caffe/solver.o .build_debug/src/caffe/syncedmem.o .build_debug/src/caffe/util/benchmark.o .build_debug/src/caffe/util/im2col.o .build_debug/src/caffe/util/insert_splits.o .build_debug/src/caffe/util/io.o .build_debug/src/caffe/util/math_functions.o .build_debug/src/caffe/util/upgrade_proto.o -framework Accelerate -lglog -lgflags -lprotobuf -lleveldb -lsnappy -llmdb -lboost_system -lhdf5_hl -lhdf5 -lopencv_core -lopencv_highgui -lopencv_imgproc -lpthread -lboost_thread-mt -lcblas -lstdc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib/darwin/libclang_rt.osx.a
So... where does this path /usr/include/c++/4.2.1
come from? 那么......这条路
/usr/include/c++/4.2.1
来自哪里?
Did I get some hints? 我得到了一些提示吗?
Machida-no-MacBook-Air:caffe machidahiroaki$ g++ -print-search-dirs install: /usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/ programs: =/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/bin/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/bin/ libraries: =/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/lib/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/lib/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../:/lib/x86_64-apple-darwin14.0.0/5.0.0/:/lib/:/usr/lib/x86_64-apple-darwin14.0.0/5.0.0/:/usr/lib/ Machida-no-MacBook-Air:caffe machidahiroaki$ clang++ -print-search-dirs programs: =/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin libraries: =/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0 M
I don't know if it has to do with the problem... 我不知道这是否与问题有关...
Machida-no-MacBook-Air:caffe machidahiroaki$ gcc -print-search-dirs install: /usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/ programs: =/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/bin/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/bin/ libraries: =/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/lib/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/lib/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../:/lib/x86_64-apple-darwin14.0.0/5.0.0/:/lib/:/usr/lib/x86_64-apple-darwin14.0.0/5.0.0/:/usr/lib/ Machida-no-MacBook-Air:caffe machidahiroaki$ gcc --version gcc (GCC) 5.0.0 20141005 (experimental) Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Wait,
export CFLAGS="-I/path/to/preferred/HDF5/hdf5.h"
would not work... 等等,
export CFLAGS="-I/path/to/preferred/HDF5/hdf5.h"
不起作用......
Specify nothing 什么都不指定
Machida-no-MacBook-Air:caffe machidahiroaki$ echo | "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -Wp,-v -stdlib=libstdc++ -x c++ - -fsyntax-only clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.0.0 #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.2.1 /usr/include/c++/4.2.1/backward /usr/local/include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list.
Can't specify a header file!!
无法指定头文件!!
Machida-no-MacBook-Air:caffe machidahiroaki$ echo | "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -Wp,-v -stdlib=libstdc++ -x c++ - -fsyntax-only -I/usr/local/include/hdf5.h clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.0.0 ignoring nonexistent directory "/usr/local/include/hdf5.h" #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.2.1 /usr/include/c++/4.2.1/backward /usr/local/include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list.
As expected, the duplicate directory is ignored and the order does not change.
正如所料,重复的目录被忽略, 订单不会改变。
Machida-no-MacBook-Air:caffe machidahiroaki$ echo | "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -Wp,-v -stdlib=libstdc++ -x c++ - -fsyntax-only -I/usr/local/include/ clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.0.0 ignoring duplicate directory "/usr/local/include" as it is a non-system directory that duplicates a system directory #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.2.1 /usr/include/c++/4.2.1/backward /usr/local/include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include /usr/include /System/Library/Frameworks (framework directory) /Library/Frameworks (framework directory) End of search list.
But, I found clang
's -include
option, which is able to specify a file! 但是,我找到了
clang
的-include
选项,它可以指定一个文件!
I'd like to change library search path...
我想改变图书馆搜索路径......
At compile time, you augment the library search path with -L
. 在编译时,使用
-L
扩充库搜索路径。 You cannot delete paths; 你无法删除路径; you can only add paths that have a "higher" preference than existing paths.
您只能添加比现有路径具有“更高”首选项的路径。
At runtime, you use DYLD_LIBRARY_PATH
, DYLD_FALLBACK_LIBRARY_PATH
and friends to change the library search path. 在运行时,您使用
DYLD_LIBRARY_PATH
, DYLD_FALLBACK_LIBRARY_PATH
和朋友来更改库搜索路径。 See dyld(1)
OS X Man Pages . 请参阅
dyld(1)
OS X手册页 。
Usually you use DYLD_LIBRARY_PATH
to ensure a particular library is loaded rather than the system one. 通常使用
DYLD_LIBRARY_PATH
来确保加载特定库而不是系统库。 Its a way to override default behavior. 它是一种覆盖默认行为的方法。
DYLD_FALLBACK_LIBRARY_PATH
is used to provide a library that's not a system one. DYLD_FALLBACK_LIBRARY_PATH
用于提供不是系统库的库。 Its less intrusive because you don't displace system paths. 它不那么具有侵入性,因为你不会取代系统路径。
I need /usr/local/include first...
我首先需要/ usr / local / include ...
Sounds a bit odd to me, but... 听起来有点奇怪,但......
$ export DYLD_LIBRARY_PATH=/usr/local/include
$ clang ...
IF you are cross-compiling from the command line, you should do something like this. 如果您从命令行进行交叉编译,则应该执行类似的操作。 The trick is to use
--sysroot
to automatically bring in the headers and libraries for the platform, rather than hacking them with -I
, -L
and -l
. 诀窍是使用
--sysroot
自动引入平台的头文件和库,而不是用-I
, -L
和-l
攻击它们。
# Put cross compile tools on the PATH first
export PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/:$PATH"
# C compiler
export CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
# C++ compiler
export CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
# SYSROOT brings in platform headers and libraries, No need for -I, -L and -l.
SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk
# Compiler flags
export CFLAGS="-march armv7 -march armv7s --sysroot=$SYSROOT"
# Compiler flags
export CXXFLAGS="-march armv7 -march armv7s --sysroot=$SYSROOT"
# Using defualt C++ runtime
$CXX $CXXFLAGS foo.c -o foo.exe
You can also specify GNU's runtime with -stdlib=libstdc++
, and LLVM's runtime with -stdlib=libc++
. 您还可以使用
-stdlib=libstdc++
指定GNU的运行时,使用-stdlib=libc++
指定LLVM的运行时。
Based on your updates: 根据您的更新:
<ld command and output omitted>
where does this path /usr/include/c++/4.2.1 come from??这个路径/usr/include/c++/4.2.1来自哪里?
/usr/include/c++/4.2.1
is not in your Library Search Path . /usr/include/c++/4.2.1
不在您的图书馆搜索路径中 。 Its just not there. 它只是不存在。
That's a header include path, and you specify it with -I
. 这是包含路径的标头,您可以使用
-I
指定它。
If you want to see your header include paths for libstdc++
and libc++
, do this: 如果要查看标题包含
libstdc++
和libc++
路径,请执行以下操作:
# GNU C++ runtime
$ echo | /usr/local/bin/clang++ -Wp,-v -stdlib=ibstdc++ -x c++ - -fsyntax-only
And: 和:
# LLVM C++ runtime
$ echo | /usr/local/bin/clang++ -Wp,-v -stdlib=libc++ -x c++ - -fsyntax-only
Here's what I get on OS X 10.8.5: 这是我在OS X 10.8.5上得到的:
libstdc++ (GNU) : libstdc ++(GNU) :
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/local/include
/usr/local/bin/../lib/clang/3.5.0/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory
libc++ (LLVM) : libc ++(LLVM) :
/usr/local/include
/usr/local/bin/../lib/clang/3.5.0/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
So /usr/include/c++/4.2.1
is a built-in compiler path when using GNU's libstdc++
(but not LLVM's libc++
). 所以
/usr/include/c++/4.2.1
是使用GNU的libstdc++
(而不是LLVM的libc++
)时的内置编译器路径。 I'll go even further and tell you its hard coded in LLVM/Clang sources (I build LLVM/Clang from source often): 我会更进一步告诉你它在LLVM / Clang源代码中的硬编码(我经常从源代码构建LLVM / Clang):
$ cd clang-sources/llvm
$ grep -R "/usr/include/c++/4.2.1" *
tools/clang/lib/Frontend/InitHeaderSearch.cpp: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
tools/clang/lib/Frontend/InitHeaderSearch.cpp: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
tools/clang/lib/Frontend/InitHeaderSearch.cpp: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
tools/clang/lib/Frontend/InitHeaderSearch.cpp: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
tools/clang/lib/Frontend/InitHeaderSearch.cpp: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
You can add additional include paths when building LLVM/Clang with --with-c-include-dirs
. 使用
--with-c-include-dirs
构建LLVM / Clang时,可以添加其他包含路径。
Based on your comment: "... If I delete ~/anaconda/include/hdf5.h..." . 根据你的评论: “......如果我删除〜/ anaconda / include / hdf5.h ......” 。 If you need a new path for the HDF5 package, then use something like:
如果您需要HDF5包的新路径,请使用以下内容:
export CPPFLAGS="-I/path/to/preferred/HDF5/hdf5.h"
export CFLAGS="-I/path/to/preferred/HDF5/hdf5.h"
export CXXFLAGS="-I/path/to/preferred/HDF5/hdf5.h"
export LDFLAGS="-L/path/to/preferred/HDF5/lib"
./configure ...
You need it in CPPFLAGS
too because the autotools might run some tests with it. 你在
CPPFLAGS
也需要它,因为autotools可能会用它运行一些测试。
Then, at runtime: 然后,在运行时:
export DYLD_LIBRARY_PATH=/path/to/preferred/HDF5/lib
./run_the_executable
And you can side step DYLD_LIBRARY_PATH
IF you perform static linking against HDF5. 如果您对HDF5执行静态链接,则可以执行步骤
DYLD_LIBRARY_PATH
。 But be aware the OS X linker always uses a shared object or dynalib if its available. 但请注意,OS X链接器始终使用共享对象或dynalib( 如果可用)。 Effectively, it ignores your request for static linking.
实际上,它忽略了您对静态链接的请求。 You will have to
mv
shared object or dynalib off-path while leaving an archive on-path. 您将需要
mv
共享对象或dynalib偏离路径,同时在路径上保留存档。
To muddy the waters a little more... If you are saying "library" when you really want to say "framework", then see this Stack Overflow question about using the -framework
option: Clang(LLVM) compile with frameworks . 让水更
-framework
...如果你在说“框架”的时候说“库”,那么请参阅Stack Overflow关于使用-framework
选项的问题: Clang(LLVM)用框架编译 。
You can go into your project settings and make changes to edit your library search paths very easily. 您可以进入项目设置并进行更改以轻松编辑库搜索路径。
See how I opened up the settings in this test project screenshot? 看看我如何在这个测试项目截图中打开设置? There's no paths in my own project there right now;
我现在的项目中没有路径; but in your project, there will certainly be duplicate paths (or multiple paths that resolve to the same place).
但在您的项目中,肯定会有重复的路径(或多个路径可以解析到同一个地方)。
gcc -V
gcc -V
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.