无法链接动态库:通过Xcode进行编译

时间:2017-05-13 14:53:59

标签: c++ makefile xcode7 dylib

我的项目结构如下: 项目> SRC> main.cpp中

main.cpp调用对动态库(.dylib)具有依赖性的方法。在我的/ usr / local / bin中,动态库的名称为libgismo.dylib,但它是一个指向libgismo.0.8.1.dylib的别名

我的make文件是:

# Targets
SRCPATH = ./src
GISMOPATH = /usr/local/include/gismo

CXX = g++
INCLUDE = -I/usr/local/bin -I/usr/local/include -I$(GISMOPATH) -I/usr/local/lib
DYLD_LIBRARY_PATH = -L/usr/local/lib
LIBS = -libgismo
all: main
main : $(SRCPATH)/main.cpp
     @$(CXX) $(INCLUDE) $(SRCPATH)/main.cpp -o main $(DYLD_LIBRARY_PATH) $(LIBS)
     $(info Compiling main)
clean :
     @rm main

但是当我通过Xcode构建它时会产生以下错误:

ld: library not found for -libgismo.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1
Command /Applications/Xcode.app/Contents/Developer/usr/bin/make failed with exit code 2

输出到:

$ make -n 

g++ -I/usr/local/bin -I/usr/local/include -I/usr/local/include/gismo -I/usr/local/lib ./src/main.cpp -o main -L/usr/local/lib/ -libgismo

$ ls -l /usr/local/lib/*gismo*

-rw-r--r--  1 root  wheel     1337 May 14 11:35 /usr/local/lib/gismoConfig.cmake
-rw-r--r--  1 root  wheel      366 May 14 11:35 /usr/local/lib/gismoConfigVersion.cmake
-rw-r--r--  1 root  wheel     3900 May 14 11:34 /usr/local/lib/gismoUse.cmake
-rwxr-xr-x  1 root  wheel  9195544 May 14 11:52 /usr/local/lib/libgismo.0.8.1.dylib
lrwxr-xr-x  1 root  wheel       20 May 12 10:23 /usr/local/lib/libgismo.0.dylib -> libgismo.0.8.1.dylib
lrwxr-xr-x  1 root  wheel       16 May 12 10:23 /usr/local/lib/libgismo.dylib -> libgismo.0.dylib

我该如何解决这个问题?

谢谢!

0 个答案:

没有答案