Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 链接动态库_Xcode_Macos_Makefile_Clang_Dylib - Fatal编程技术网

Xcode 链接动态库

Xcode 链接动态库,xcode,macos,makefile,clang,dylib,Xcode,Macos,Makefile,Clang,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

我试图在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)
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
解决了这个问题:其他用户在更新库后也遇到了同样的问题。

您需要将libs传递给链接器,而不是编译器:

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) $(OBJS) -o $@ $(LIBS)
main.o: main.cpp
    $(CC) $(CFLAGS) -c $< -o $@ 
besselJ.o: besselJ.cpp
    $(CC) $(CFLAGS) -c $< -o $@
OBJS=main.o besselJ.o
cc= C++
CFLAGS=-std=c++11-stdlib=libc++
LIBS=-L/usr/lib-lcomplex\u bessel
程序名称=测试
全部:$(程序名称)
$(程序名称):$(OBJS)
$(CC)$(OBJS)-o$@$(LIBS)
main.o:main.cpp
$(CC)$(CFLAGS)-c$<-o$@
besselJ.o:besselJ.cpp
$(CC)$(CFLAGS)-c$<-o$@

好的,谢谢,我这样做了,但我收到以下消息:ld:library not found for-lcomplex\u bessel clang:error:linker命令失败,退出代码为1(使用-v查看调用)
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
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) $(OBJS) -o $@ $(LIBS)
main.o: main.cpp
    $(CC) $(CFLAGS) -c $< -o $@ 
besselJ.o: besselJ.cpp
    $(CC) $(CFLAGS) -c $< -o $@