printemp
printemp

Reputation: 879

Undefined symbols for architecture x86_64: linking mistake?

I am new to cpp, want to have a implementation of particle filter, I try to run the code here https://github.com/NewProggie/Particle-Filter, which is a structured and easy understanding project. But when I try to compile and link:

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

I have following linking problem:

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)

Any kind person has ideas about this problem? Thanks in advance

Upvotes: 2

Views: 999

Answers (1)

printemp
printemp

Reputation: 879

have gsl installed properly B) pass to g++ a reference to the lib directory where the gsl libraries are located (probably something like /usr/lib or /usr/local/lib, these should both be default locations for the linker to search), and also to where the header files are, and also tell the linker to do the linking.

g++ -o <name of executable> -L/path/to/gsl/libs -I/path/to/headers -lgsl <name of source file>

the -L tells it where to find the libraries (.so files on linux, .dylib on OS X), -I tells it where to find the headers, -l (that's a lower case L) tells it to link to the library, which would be named libgsl.so or libgsl.dylib.

First just try adding the -lgsl flag, then if it can't find libgsl.so (or .dylib), add the -L flag. NOTE: /path/to/gsl/libs and /path/to/headers are not what you should literally put in there, but replace them with the actual paths on your system.

Upvotes: 1

Related Questions