建筑x86_64的未定义符号:链接错误



我是cpp的新手,想要一个粒子过滤器的实现,我尝试在这里运行代码 https://github.com/NewProggie/Particle-Filter,这是一个结构化且易于理解的项目。但是当我尝试编译和链接时:

g++ $(pkg-config --cflags --libs opencv)  -I/usr/local/Cellar/opencv3/3.1.0_1/include -I /usr/local/Cellar/gsl/1.16/include  -stdlib=libc++   main.cpp -o main

我有以下链接问题:

Undefined symbols for architecture x86_64:
"colorFeatures::colorFeatures()", referenced from:
  _main in main-2b4c23.o
"colorFeatures::~colorFeatures()", referenced from:
  _main in main-2b4c23.o
"adaboostDetect::detectObject(_IplImage*, CvRect**)", referenced from:
  _main in main-2b4c23.o
"adaboostDetect::adaboostDetect()", referenced from:
  _main in main-2b4c23.o
"tracker::addObjects(_IplImage*, CvRect*, int)", referenced from:
  _main in main-2b4c23.o
"tracker::initTracker(_IplImage*, CvRect*, int, int)", referenced from:
  _main in main-2b4c23.o
"tracker::showResults(_IplImage*)", referenced from:
  _main in main-2b4c23.o
"tracker::next(_IplImage*)", referenced from:
  _main in main-2b4c23.o
"tracker::tracker()", referenced from:
  _main in main-2b4c23.o
"tracker::~tracker()", referenced from:
  _main in main-2b4c23.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

任何善良的人对这个问题有想法吗?提前致谢

已正确安装 GSLB) 向 g++ 传递对 gsl 库所在的 lib 目录的引用(可能类似于/usr/lib 或/usr/local/lib,它们都应该是链接器搜索的默认位置),以及头文件所在的位置,并告诉链接器进行链接。

g++ -o <name of executable> -L/path/to/gsl/libs -I/path/to/headers -lgsl <name of source file>
-L 告诉它在哪里可以找到库(Linux 上的 .

so 文件,OS X 上的 .dylib),-I 告诉它在哪里可以找到标头,-l(这是小写的 L)告诉它链接到库,该库将被命名为 libgsl.so 或 libgsl.dylib。

首先尝试添加 -lgsl 标志,如果找不到 libgsl.so(或 .dylib),请添加 -L 标志。注意:/path/to/gsl/libs 和/path/to/headers 不是你应该放在那里的东西,而是用系统上的实际路径替换它们。

最新更新