如何在 mac 上为 google protobuf 设置 LD_LIBRARY_PATH(也许还有 DYLD_)?

How to set LD_LIBRARY_PATH (and maybe DYLD_ as well) for google protobuf on mac?

protobuf 2.5 已经安装(通过 brew)并且在路径中:

$which protoc
/usr/local/opt/protobuf@2.5/bin/protoc

编译时(caffe)没有找到:估计是库路径设置问题。

ld: library not found for -lprotobuf
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [.build_release/lib/libcaffe.so.1.0.0-rc3] Error 1

需要更新哪些环境变量?我不清楚

是哪个组合
LD_LIBRARY_PATH
DYLD_LIBRARY_PATH
LIBRARY_PATH

需要

另外:下面的路径/usr/local/Cellar/protobuf@2.5/2.5.0/lib使用正确吗?

$ll /usr/local/Cellar/protobuf@2.5/2.5.0/lib
total 12392
-r--r--r--   1 boescst  admin  1120832 Feb 26  2013 libprotoc.a
-r--r--r--   1 boescst  admin  1536576 Feb 26  2013 libprotobuf.a
-r--r--r--   1 boescst  admin   215672 Feb 26  2013 libprotobuf-lite.a
drwxr-xr-x  12 boescst  admin      408 Feb 26  2013 .
drwxr-xr-x   4 boescst  admin      136 Mar 12 11:46 pkgconfig
-r--r--r--   1 boescst  admin   659108 Mar 12 11:46 libprotoc.dylib
-r--r--r--   1 boescst  admin   659108 Mar 12 11:46 libprotoc.8.dylib
-r--r--r--   1 boescst  admin   930424 Mar 12 11:46 libprotobuf.dylib
-r--r--r--   1 boescst  admin   930424 Mar 12 11:46 libprotobuf.8.dylib
-r--r--r--   1 boescst  admin   138008 Mar 12 11:46 libprotobuf-lite.dylib
-r--r--r--   1 boescst  admin   138008 Mar 12 11:46 libprotobuf-lite.8.dylib
drwxr-xr-x  11 boescst  admin      374 Mar 12 11:46 ..

最后:我是否需要在该目录中创建任何符号链接 - 以使调用程序(caffe 在我的例子中)能够找到库?

包含的库在 Makefile 中显示如下:

INCLUDE_DIRS += $(BLAS_INCLUDE)
LIBRARY_DIRS += $(BLAS_LIB)
LIBRARY_DIRS += /usr/local/Cellar/protobuf@2.5/2.5.0/lib


LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_CONFIG) 
        $(foreach library,$(LIBRARIES),-l$(library))

那么有没有一种方法可以打印出这些库 - 而无需求助于生成 265K 行的 make -d

编译时returns报错:

clang: error: linker command failed with exit code 1 (use -v to see invocation)

这表示无法找到试图链接的特定库。在大多数情况下,通常需要通知编译器相关库的实际位置。有几种方法可以做到这一点,这取决于构建某些东西的方式。由于您使用的是 Makefile 添加以下环境变量应该可以解决问题:

LIBRARY_PATH=/usr/local/Cellar/protobuf@2.5/2.5.0/lib:$LIBRA‌​RY_PATH

这会在环境中临时添加库位置,以便编译器能够找到它。

注意:在无法识别 LIBRARY_PATH 的情况下,LIBRARY_DIRS 是要使用的正确变量。