我正在尝试将dylib链接到Mac上的makefile,但是Clang给出了这样的信息:
Undefined symbols for architecture x86_64:
"_zbesj_wrap", referenced from:
sp_bessel::besselJ(double, std::__1::complex<double>) in besselJ.o
"_zbesy_wrap", referenced from:
sp_bessel::besselJ(double, std::__1::complex<double>) in besselJ.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我在/ usr / lib中安装了库,在那里我可以看到libcomplex_bessel.0.6.0.dylib和libcomplex_bessel.dylib。 这是我的makefile:
OBJS = main.o besselJ.o
CC = c++
CFLAGS = -std=c++11 -stdlib=libc++
LIBS = -L/usr/lib -lcomplex_bessel
PROGRAM_NAME = test
all: $(PROGRAM_NAME)
$(PROGRAM_NAME): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $@
main.o: main.cpp
$(CC) $(CFLAGS) -c $< -o $@
besselJ.o: besselJ.cpp
$(CC) $(CFLAGS) -c $< -o $@ $(LIBS)
在阅读其他问题之后,我尝试了-L和-l的不同组合,但没有任何效果。抱歉,这是我第一次使用外部图书馆......
我将makefile更改为:
OBJS = main.o besselJ.o
CC = c++
CFLAGS = -std=c++11 -stdlib=libc++
LIBS = -L/usr/lib -lcomplex_bessel
PROGRAM_NAME = test
all: $(PROGRAM_NAME)
$(PROGRAM_NAME): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $@ $(LIBS)
main.o: main.cpp
$(CC) $(CFLAGS) -c $< -o $@
besselJ.o: besselJ.cpp
$(CC) $(CFLAGS) -c $< -o $@
但我仍有问题,我收到此消息:
c++ -std=c++11 -stdlib=libc++ main.o besselJ.o -o test -L/usr/lib -lcomplex_bessel
ld: library not found for -lcomplex_bessel
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test] Error 1
好的,我认为我使用xcode-select --install
解决了这个问题:其他用户在更新后遇到了与库相同的问题。
答案 0 :(得分:1)
您需要将libs传递给链接器,而不是传递给编译器:
onDelete('cascade')