C++ 在 Mac OS X Yosemite 10.10.1 上包含搜索路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27948093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 20:53:54  来源:igfitidea点击:

Include search path on Mac OS X Yosemite 10.10.1

c++xcodemacososx-yosemiteclang++

提问by Hiroaki Machida

I just to change the include search path order (I believe).

我只是为了改变包含搜索路径的顺序(我相信)。



我想更改包含搜索路径。特别是,我/usr/local/include/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

 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.10.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test_common.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.9 -v -gdwarf-2 -coverage-file /Users/machidahiroaki/RubymineProjects/caffe/.build_debug/src/caffe/test/test_common.o -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0 -D DEBUG -D CPU_ONLY -I /usr/local/include -I /usr/local/include -I /Users/machidahiroaki/anaconda/include -I /Users/machidahiroaki/anaconda/include/python2.7 -I /Users/machidahiroaki/anaconda/lib/python2.7/site-packages/numpy/core/include -I .build_debug/src -I ./src -I ./include -I /usr/local/atlas/include -stdlib=libstdc++ -O0 -Wall -Wno-sign-compare -Wno-unneeded-internal-declaration -fdeprecated-macro -fdebug-compilation-dir /Users/machidahiroaki/RubymineProjects/caffe -ferror-limit 19 -fmessage-length 0 -pthread -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-slp -o .build_debug/src/caffe/test/test_common.o -x c++ src/caffe/test/test_common.cpp
clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.0.0
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
ignoring duplicate directory "/usr/local/include"
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:
 /Users/machidahiroaki/anaconda/include
 /Users/machidahiroaki/anaconda/include/python2.7
 /Users/machidahiroaki/anaconda/lib/python2.7/site-packages/numpy/core/include
 .build_debug/src
 ./src
 ./include
 /usr/local/atlas/include
 /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.


Library search paths

图书馆搜索路径

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 lddone in make.

可以肯定,这是ldmake.

 "/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.1come 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 -includeoption, which is able to specify a file!

但是,我找到了可以指定文件clang-include选项!

回答by jww

I'd like to change library search path...

我想更改库搜索路径...

At compile time, you augment the library search path with -L. You cannot delete paths; you can only add paths that have a "higher" preference than existing paths.

在编译时,您可以使用-L. 您不能删除路径;您只能添加比现有路径具有“更高”偏好的路径。

At runtime, you use DYLD_LIBRARY_PATH, DYLD_FALLBACK_LIBRARY_PATHand friends to change the library search path. See dyld(1)OS X Man Pages.

在运行时,您可以使用DYLD_LIBRARY_PATHDYLD_FALLBACK_LIBRARY_PATH和朋友来更改库搜索路径。请参阅dyld(1)OS X 手册页

Usually you use DYLD_LIBRARY_PATHto ensure a particular library is loaded rather than the system one. Its a way to override default behavior. DYLD_FALLBACK_LIBRARY_PATHis used to provide a library that's not a system one. Its less intrusive because you don't displace system paths.

通常DYLD_LIBRARY_PATH用于确保加载特定库而不是系统库。它是一种覆盖默认行为的方法。DYLD_FALLBACK_LIBRARY_PATH用于提供一个不是系统库的库。它的侵入性较小,因为您不会替换系统路径。

----------

----------

I need /usr/local/include first...

我首先需要 /usr/local/include ...

Sounds a bit odd to me, but...

对我来说听起来有点奇怪,但是...

$ export DYLD_LIBRARY_PATH=/usr/local/include
$ clang ...

----------

----------

IFyou are cross-compiling from the command line, you should do something like this. The trick is to use --sysrootto automatically bring in the headers and libraries for the platform, rather than hacking them with -I, -Land -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++.

您还可以使用 指定 GNU 的运行时-stdlib=libstdc++,使用-stdlib=libc++.

----------

----------

Based on your updates:

根据您的更新:

<ld command and output omitted>
where does this path /usr/include/c++/4.2.1 come from??

<ld command and output omitted>
这个路径/usr/include/c++/4.2.1 来自哪里??

/usr/include/c++/4.2.1is notin your Library Search Path. Its just not there.

/usr/include/c++/4.2.1不是在你的库搜索路径。它只是不存在。

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.1is a built-in compiler path when using GNU's libstdc++(but not LLVM's libc++). I'll go even further and tell you its hard coded in LLVM/Clang sources (I build LLVM/Clang from source often):

/usr/include/c++/4.2.1使用 GNU 的libstdc++(但不是 LLVM 的libc++)时,内置编译器路径也是如此。我会更进一步告诉你它在 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.

----------

----------

Based on your comment: "... If I delete ~/anaconda/include/hdf5.h...". If you need a new path for the HDF5 package, then use something like:

根据您的评论:"...如果我删除 ~/anaconda/include/hdf5.h..."。如果您需要 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 CPPFLAGStoo 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_PATHIFyou perform static linking against HDF5. But be aware the OS X linker always uses a shared object or dynalib ifits available. Effectively, it ignores your request for static linking. You will have to mvshared object or dynalib off-path while leaving an archive on-path.

DYLD_LIBRARY_PATH如果您对 HDF5 执行静态链接,您可以回避。但请注意,OS X 链接器始终使用共享对象或 dynalib(如果可用)。实际上,它会忽略您对静态链接的请求。您必须在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 -frameworkoption: Clang(LLVM) compile with frameworks.

再把水搅浑一点......如果你在真正想说“框架”时说“库”,那么请参阅有关使用该-framework选项的堆栈溢出问题:Clang(LLVM) compile with frameworks

回答by Michael Dautermann

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).

看看我是如何在这个测试项目截图中打开设置的?我自己的项目现在没有路径;但是在您的项目中,肯定会有重复的路径(或解析到同一位置的多个路径)。

enter image description here

在此处输入图片说明

回答by Eman Jayme

  • Open Terminal
  • Run gcc -V
  • Read the information and copy the include path. Mine is /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1
  • 打开终端
  • gcc -V
  • 阅读信息并复制包含路径。我的是/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1