ld库路径在OS X 10.9下不工作 [英] ld library path not working under OS X 10.9

查看:130
本文介绍了ld库路径在OS X 10.9下不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力弄清楚为什么 g ++ 无法将程序链接到 armadillo 图书馆。问题很简单:

  macbook-pro:arma-xc jmlopez $ g ++  -  4.9 inputs-arma.cpp -larmadillo 
ld:未找到-larmadillo的库
collect2:错误:ld返回1退出状态

可能我指定了库应该在哪里

  macbook-pro:arma-xc jmlopez $ ls -l / usr / lib / libarma * 
-rwxr-xr-x 1 root wheel 37928 Aug 18 14:30 /usr/lib/libarmadillo.4.32.2.dylib
lrwxr-xr-x 1 root wheel 25 Aug 18 14:30 /usr/lib/libarmadillo.4.dylib - > libarmadillo.4.32.2.dylib
lrwxr-xr-x 1 root wheel 20 Aug 18 14:30 /usr/lib/libarmadillo.dylib - > libarmadillo.4.dylib

让我们再试一次

  macbook-pro:arma-xc jmlopez $ g ++  -  4.9 -L / usr / lib inputs-arma.cpp -larmadillo 
ld:没有找到-larmadillo的库b $ b collect2:错误:ld返回1退出状态

确定,没有解决它。让我们看看发生了什么,因为这将使用 -v 选项,这将产生一些长输出。

  macbook-pro:arma-xc jmlopez $ g ++  -  4.9 -L / usr / lib inputs-arma.cpp -larmadillo -v 
使用内置的specs。
COLLECT_GCC = g ++ - 4.9
COLLECT_LTO_WRAPPER = / usr / local / Cellar / gcc / 4.9.1 / libexec / gcc / x86_64-apple-darwin13.3.0 / 4.9.1 / lto-wrapper
目标:x86_64-apple-darwin13.3.0
配置为:../configure --build = x86_64-apple-darwin13.3.0 --prefix = / usr / local / Cellar / gcc / 4.9.1 - enable-languages = c,c ++,objc,obj-c ++,fortran --program-suffix = -4.9 --with-gmp = / usr / local / opt / gmp --with-mpfr = / usr / local / opt / mpfr --with-mpc = / usr / local / opt / libmpc --with-cloog = / usr / local / opt / cloog --with-isl = / usr / local / opt / isl --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time = yes --enable-stage1-checking --enable-checking = release --enable-lto --disable-werror --with-pkgversion = 'Homebrew gcc 4.9.1'--with-bugurl = https://github.com/Homebrew/homebrew/issues --enable-plugin --disable-nls --enable-multilib --with-native-system-header -dir = / usr / include --with-sysroot = / Applications / Xcode.app / Contents / Developer / Platforms / MacOSX.platform / Developer / SDKs / MacOSX10.9.sdk
线程模型:posix
gcc version 4.9.1(Homebrew gcc 4.9.1)
COLLECT_GCC_OPTIONS =' - mmacosx-version-min = 10.9.3''-L / usr / lib''-v''-shared-libgcc'' -mtune = core2'
/usr/local/Cellar/gcc/4.9.1/libexec/gcc/x86_64-apple-darwin13.3.0/4.9.1/cc1plus -quiet -v -D__DYNAMIC__ inputs-arma.cpp -fPIC -quiet -dumpbase输入 - arma.cpp -mmacosx版本分钟= 10.9.3 -mtune = core2的-auxbase输入 - ARMA -version -o /var/folders/6x/ss29s2r51z5cv0_g1ffx0c0c0000gn/T//ccApA95Q.s
GNU C版本4.9.1,GMP版本6.0.0,MPFR版本3.1.2版本编译的GNU C ++(Homebrew gcc 4.9.1)版本4.9.1(x86_64-apple-darwin13.3.0)
p8,MPC版本1.0.2
GGC启发式:--param ggc-min-expand = 100 --param ggc-min-heapsize = 131072
忽略不存在的目录/Applications/Xcode.app/Contents /Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/local/include
忽略不存在的目录/usr/local/Cellar/gcc/4.9.1/lib/gcc/ x86_64-apple-darwin13.3.0 / 4.9.1 /../../../../ x86_64-apple-darwin13.3.0 / include
忽略不存在的目录/Applications/Xcode.app/Contents /Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/Library/Frameworks
#include...搜索从这里开始:
#include< ...> ;搜索从这里开始:
/ Users / jmlopez / github / excentury / excentury / extern / include
/ usr / include
/usr/local/Cellar/gcc/4.9.1/lib/gcc /x86_64-apple-darwin13.3.0/4.9.1/include/c++
/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/include /c++/x86_64-apple-darwin13.3.0
/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/include/c++/backward
/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/include
/usr/local/Cellar/gcc/4.9.1/lib /gcc/x86_64-apple-darwin13.3.0/4.9.1/include-fixed
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr / include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks
搜索结束列表。
GNU C ++(Homebrew gcc 4.9.1)版本4.9.1(x86_64-apple-darwin13.3.0)
由GNU C版本4.9.1,GMP版本6.0.0,MPFR版本3.1.2编译-p8,MPC版本1.0.2
GGC启发:--param GGC-分钟展开= 100 --param GGC-最小堆大小= 131072
编译器可执行文件的校验:5a051bcf2be886a5c6eb8ba33f338693
COLLECT_GCC_OPTIONS = '-mmacosx-version-min = 10.9.3''-L / usr / lib''-v''-shared-libgcc''-mtune = core2'
as -arch x86_64 -force_cpusubtype_ALL -o / var /folders/6x/ss29s2r51z5cv0_g1ffx0c0c0000gn/T//cchm9rVF.o /var/folders/6x/ss29s2r51z5cv0_g1ffx0c0c0000gn/T//ccApA95Q.s
COMPILER_PATH =的/ usr /本地/库/ GCC / 4.9.1 / libexec目录/ GCC /x86_64-apple-darwin13.3.0/4.9.1/:/usr/local/Cellar/gcc/4.9.1/libexec/gcc/x86_64-apple-darwin13.3.0/4.9.1/:/usr/local/Cellar /gcc/4.9.1/libexec/gcc/x86_64-apple-darwin13.3.0/:/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/: /usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/
LIBRARY_PATH = / usr / lib /:/ usr / local / Cellar / gcc / 4.9.1 / lib / gcc / x86_64-apple-darwin13.3.0 / 4.9.1 /:/ usr / local / Cellar / gcc / 4.9.1 / lib / gcc / x86_64-apple-darwin13.3.0 / 4.9.1 /../。 ./../:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib/
COLLECT_GCC_OPTIONS =' - mmacosx-version-min = 10.9.3''-L / usr / lib''-v''-shared-libgcc''-mtune = core2'
/usr/local/Cellar/gcc/4.9.1/libexec/gcc/ x86_64的 - 苹果darwin13.3.0 / 4.9.1 / collect2 -dynamic -arch x86_64的-macosx_version_min 10.9.3 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9。 sdk -weak_reference_mismatches non-weak -o a.out -L / usr / lib -L ​​/ usr / local / Cellar / gcc / 4.9.1 / lib / gcc / x86_64-apple-darwin13.3.0 / 4.9.1 -L / usr / local / Cellar / gcc / 4.9.1 / lib / gcc / x86_64-apple-darwin13.3.0 / 4.9.1 /../../ .. -L / Applications / Xcode.app / Contents / Developer / Platforms /MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib /var/folders/6x/ss29s2r51z5cv0_g1ffx0c0c0000gn/T//cchm9rVF.o -larmadillo -lstdc ++ -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem - v
collect2版本4.9.1
的/ usr / bin中/ LD -dynamic -arch x86_64的-macosx_version_min 10.9.3 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer /SDKs/MacOSX10.9.sdk -weak_reference_mismatches non-weak -o a.out -L / usr / lib -L ​​/ usr / local / Cellar / gcc / 4.9.1 / lib / gcc / x86_64-apple-darwin13.3.0 /4.9.1 -L / usr / local / Cellar / gcc / 4.9.1 / lib / gcc / x86_64-apple-darwin13.3.0 / 4.9.1 /../../...L/应用程序/ Xcode。应用/内容/开发/平台/ MacOSX.platform /开发商/软件开发工具包/ MacOSX10.9.sdk / usr / lib目录/var/folders/6x/ss29s2r51z5cv0_g1ffx0c0c0000gn/T//cchm9rVF.o -larmadillo -lstdc ++ -no_compact_unwind -lSystem -lgcc_ext .10.5 -lgcc -lSystem -v
@(#)计划:LD项目:ld64-236.4
配置为支持archs:ARMv6的ARMv7的armv7s arm64的i386 x86_64的armv6m armv7m armv7em
库搜索路径:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
/usr/local/Cellar/gcc/4.9.1 /lib/gcc/x86_64-apple-darwin13.3.0/4.9.1
/usr/local/Cellar/gcc/4.9.1/lib
/Applications/Xcode.app/Contents/Developer/Platforms /MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk / usr / lib
框架搜索路径:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/
ld:未找到-larmadillo的库:
collect2:error:ld返回1退出状态

重要信息在这里:

 库搜索路径:
/Applications/Xcode.app/Contents/Developer/平台/ MacOSX.platform / Developer / SDKs / MacOSX10.9.sdk / usr / lib
/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9。 1
/usr/local/Cellar/gcc/4.9.1/lib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/ usr / lib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib

不知道它不是在 / usr / lib 中查找。我试过指定这个目录首先
导出变量 LD_LIBRARY_PATH

  macbook-pro:arma-xc jmlopez $ export LD_LIBRARY_PATH = / usr / lib 
macbook-pro:arma-xc jmlopez $ g ++ - 4.9 -L / usr / lib inputs-arma.cpp -larmadillo
ld:未找到-larmadillo的库
collect2:错误:ld返回1退出状态

没有运气。最后,认为 ld 可能会损坏我这样做:

  macbook -pro:arma-xc jmlopez $ ln -s /usr/lib/libarmadillo.dylib /usr/local/Cellar/gcc/4.9.1/lib/libarmadillo.dylib 
macbook-pro:arma-xc jmlopez $ g ++ - 4.9 inputs-arma.cpp -larmadillo

我不知道如果有什么问题,我的系统,但似乎我没有办法指定其他路径 ld 寻找我的库。相反,我必须使用以下任何一种:

 库搜索路径:
/Applications/Xcode.app/Contents /Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0 /4.9.1
/usr/local/Cellar/gcc/4.9.1/lib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9 .sdk / usr / lib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib

有办法解决这个问题吗?注意,我使用自定义的自定义的 g ++ ,因为我认为xcode附带的那个破碎。在任何情况下,没有运气,至少自制的 g ++ 告诉我的图书馆被搜索的路径。



更新:



我决定看看是否可以添加另一个路径:

  g ++  -  4.9 -L / Users / jmlopez / -L / Users / jmlopez / Desktop -L / usr / lib inputs-arma.cpp -larmadillo -v 

现在搜索库的路径列表是:

 库搜索路径:
/ Users / jmlopez /
/ Users / jmlopez / Desktop
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ MacOSX10.9.sdk / usr / lib
/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1
/ usr / local / Cellar / gcc / 4.9.1 / lib
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
/应用程序/ Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib

/ usr / lib 在哪里?这个目录有什么特别之处, ld 拒绝在这个目录中查找。它搜索我的主目录和我的桌面。我尝试添加 / usr / local ,并将其添加到目录列表。我现在开始怀疑目录上的权限...任何想法?

解决方案

自己回答一个类似的问题。希望这将帮助。



您需要ld_library_path用于homebrew编译器,dyld_library_path用于os x以正确使用库。


$



export LD_LIBRARY_PATH = / usr / lib:$ LD_LIBRARY_PATH



export DYLD_LIBRARY_PATH = $ LD_LIBRARY_PATH:$ DYLD_LIBRARY_PATH



在OS X 10.9和10.10上使用homebrew gcc编译时,

I've been trying to figure out why g++ cannot link a program with the armadillo library. The problem is simple:

macbook-pro:arma-xc jmlopez$ g++-4.9 inputs-arma.cpp -larmadillo
ld: library not found for -larmadillo
collect2: error: ld returned 1 exit status

Perhaps I did specify where the library should be

macbook-pro:arma-xc jmlopez$ ls -l /usr/lib/libarma*
-rwxr-xr-x  1 root  wheel  37928 Aug 18 14:30 /usr/lib/libarmadillo.4.32.2.dylib
lrwxr-xr-x  1 root  wheel     25 Aug 18 14:30 /usr/lib/libarmadillo.4.dylib -> libarmadillo.4.32.2.dylib
lrwxr-xr-x  1 root  wheel     20 Aug 18 14:30 /usr/lib/libarmadillo.dylib -> libarmadillo.4.dylib

Let us try again

macbook-pro:arma-xc jmlopez$ g++-4.9 -L/usr/lib inputs-arma.cpp -larmadillo
ld: library not found for -larmadillo
collect2: error: ld returned 1 exit status

Ok, that did not fix it. Let us see what is going on, for this we will use the -v option which will generate some long output.

macbook-pro:arma-xc jmlopez$ g++-4.9 -L/usr/lib inputs-arma.cpp -larmadillo -v
Using built-in specs.
COLLECT_GCC=g++-4.9
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/4.9.1/libexec/gcc/x86_64-apple-darwin13.3.0/4.9.1/lto-wrapper
Target: x86_64-apple-darwin13.3.0
Configured with: ../configure --build=x86_64-apple-darwin13.3.0 --prefix=/usr/local/Cellar/gcc/4.9.1 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-4.9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-cloog=/usr/local/opt/cloog --with-isl=/usr/local/opt/isl --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --with-pkgversion='Homebrew gcc 4.9.1' --with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin --disable-nls --enable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
Thread model: posix
gcc version 4.9.1 (Homebrew gcc 4.9.1) 
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.3' '-L/usr/lib' '-v' '-shared-libgcc' '-mtune=core2'
 /usr/local/Cellar/gcc/4.9.1/libexec/gcc/x86_64-apple-darwin13.3.0/4.9.1/cc1plus -quiet -v -D__DYNAMIC__ inputs-arma.cpp -fPIC -quiet -dumpbase inputs-arma.cpp -mmacosx-version-min=10.9.3 -mtune=core2 -auxbase inputs-arma -version -o /var/folders/6x/ss29s2r51z5cv0_g1ffx0c0c0000gn/T//ccApA95Q.s
GNU C++ (Homebrew gcc 4.9.1) version 4.9.1 (x86_64-apple-darwin13.3.0)
    compiled by GNU C version 4.9.1, GMP version 6.0.0, MPFR version 3.1.2-p8, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/local/include"
ignoring nonexistent directory "/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/../../../../x86_64-apple-darwin13.3.0/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /Users/jmlopez/github/excentury/excentury/extern/include
 /usr/include
 /usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/include/c++
 /usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/include/c++/x86_64-apple-darwin13.3.0
 /usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/include/c++/backward
 /usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/include
 /usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/include-fixed
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks
End of search list.
GNU C++ (Homebrew gcc 4.9.1) version 4.9.1 (x86_64-apple-darwin13.3.0)
    compiled by GNU C version 4.9.1, GMP version 6.0.0, MPFR version 3.1.2-p8, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 5a051bcf2be886a5c6eb8ba33f338693
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.3' '-L/usr/lib' '-v' '-shared-libgcc' '-mtune=core2'
 as -arch x86_64 -force_cpusubtype_ALL -o /var/folders/6x/ss29s2r51z5cv0_g1ffx0c0c0000gn/T//cchm9rVF.o /var/folders/6x/ss29s2r51z5cv0_g1ffx0c0c0000gn/T//ccApA95Q.s
COMPILER_PATH=/usr/local/Cellar/gcc/4.9.1/libexec/gcc/x86_64-apple-darwin13.3.0/4.9.1/:/usr/local/Cellar/gcc/4.9.1/libexec/gcc/x86_64-apple-darwin13.3.0/4.9.1/:/usr/local/Cellar/gcc/4.9.1/libexec/gcc/x86_64-apple-darwin13.3.0/:/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/:/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/
LIBRARY_PATH=/usr/lib/:/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/:/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/../../../:/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib/
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.3' '-L/usr/lib' '-v' '-shared-libgcc' '-mtune=core2'
 /usr/local/Cellar/gcc/4.9.1/libexec/gcc/x86_64-apple-darwin13.3.0/4.9.1/collect2 -dynamic -arch x86_64 -macosx_version_min 10.9.3 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -weak_reference_mismatches non-weak -o a.out -L/usr/lib -L/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1 -L/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/../../.. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib /var/folders/6x/ss29s2r51z5cv0_g1ffx0c0c0000gn/T//cchm9rVF.o -larmadillo -lstdc++ -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v
collect2 version 4.9.1
/usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.9.3 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -weak_reference_mismatches non-weak -o a.out -L/usr/lib -L/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1 -L/usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1/../../.. -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib /var/folders/6x/ss29s2r51z5cv0_g1ffx0c0c0000gn/T//cchm9rVF.o -larmadillo -lstdc++ -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v
@(#)PROGRAM:ld  PROJECT:ld64-236.4
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 armv6m armv7m armv7em
Library search paths:
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
    /usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1
    /usr/local/Cellar/gcc/4.9.1/lib
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
Framework search paths:
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/
ld: library not found for -larmadillo
collect2: error: ld returned 1 exit status

The important information is here:

Library search paths:
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
    /usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1
    /usr/local/Cellar/gcc/4.9.1/lib
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib

Somehow it is not looking in /usr/lib. I have tried specifying this directory by first exporting the variable LD_LIBRARY_PATH

macbook-pro:arma-xc jmlopez$ export LD_LIBRARY_PATH=/usr/lib
macbook-pro:arma-xc jmlopez$ g++-4.9 -L/usr/lib inputs-arma.cpp -larmadillo
ld: library not found for -larmadillo
collect2: error: ld returned 1 exit status

No luck. Finally, thinking that ld might be broken I did this:

macbook-pro:arma-xc jmlopez$ ln -s /usr/lib/libarmadillo.dylib /usr/local/Cellar/gcc/4.9.1/lib/libarmadillo.dylib
macbook-pro:arma-xc jmlopez$ g++-4.9 inputs-arma.cpp -larmadillo

Now it works. I'm not sure if there is something wrong with my system but it seems that I have no way of specifying other paths for ld to look for my libraries. Instead I have to use any of the following:

Library search paths:
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
    /usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1
    /usr/local/Cellar/gcc/4.9.1/lib
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib

Is there a way to fix this? Notice that I'm using the g++ from homebrew since I thought that the one that came with xcode was broken. In any case, no luck, at least the homebrew g++ told me the paths where the library was being searched.

Update:

I decided to see if I could add another path:

g++-4.9 -L/Users/jmlopez/ -L/Users/jmlopez/Desktop -L/usr/lib inputs-arma.cpp -larmadillo -v

Now the list of paths where it searches for the libraries is:

Library search paths:
    /Users/jmlopez/
    /Users/jmlopez/Desktop
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
    /usr/local/Cellar/gcc/4.9.1/lib/gcc/x86_64-apple-darwin13.3.0/4.9.1
    /usr/local/Cellar/gcc/4.9.1/lib
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib
    /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib

Where is /usr/lib? What is so special about this directory that ld refuses to look in this directory. It searches in my home directory and in my Desktop. I tried adding /usr/local and it adds it to the list of directories. I'm now starting to wonder about the permissions on the directories... Any ideas?

解决方案

I ran into this thread trying to answer a similar question myself. Hopefully this will help out.

You need ld_library_path for the homebrew compiler to work and dyld_library_path for os x to appropriately use the library.

put the following exports somewhere where they can get sourced.

export LD_LIBRARY_PATH=/usr/lib:$LD_LIBRARY_PATH

export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH

This worked for me when compiling with homebrew gcc on OS X 10.9 and 10.10.

这篇关于ld库路径在OS X 10.9下不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆