架构x86_64的未定义符号:链接错误?

时间:2016-04-21 14:03:27

标签: c++ opencv linker clang

我是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)

任何善良的人都有关于这个问题的想法?提前致谢

1 个答案:

答案 0 :(得分:1)

正确安装了gsl B)向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不是你应该放在那里的东西,而是用你系统上的实际路径替换它们。