Reputation: 15658
I would like to experiment with the OpenALPR SDK and have written a little test program. The problem is, I can't get it to compile properly and I'm not sure why. Here's the SDK documentation.
My source file looks like:
$ cat test.cpp
#include <alpr.h>
#include <iostream>
std::string key =
"MyKey";
int main (void)
{
alpr::Alpr openalpr("us", "/etc/openalpr/openalpr.conf", "/usr/share/openalpr/runtime_data/", key);
// Make sure the library loaded before continuing.
// For example, it could fail if the config/runtime_data is not found
if (openalpr.isLoaded() == false)
{
std::cerr << "Error loading OpenALPR" << std::endl;
return 1;
}
std::cout << "Hello World!" << std::endl;
return 0;
}
I use the following command to compile and get the output:
$ g++ -Wall -lopenalpr test.cpp -o test
/tmp/ccGjLkrk.o: In function `main':
test.cpp:(.text+0xc5): undefined reference to `alpr::Alpr::Alpr(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
test.cpp:(.text+0x134): undefined reference to `alpr::Alpr::isLoaded()'
test.cpp:(.text+0x18e): undefined reference to `alpr::Alpr::~Alpr()'
test.cpp:(.text+0x1ce): undefined reference to `alpr::Alpr::~Alpr()'
test.cpp:(.text+0x202): undefined reference to `alpr::Alpr::~Alpr()'
test.cpp:(.text+0x236): undefined reference to `alpr::Alpr::~Alpr()'
test.cpp:(.text+0x273): undefined reference to `alpr::Alpr::~Alpr()'
/tmp/ccGjLkrk.o:test.cpp:(.text+0x290): more undefined references to `alpr::Alpr::~Alpr()' follow
collect2: error: ld returned 1 exit status
Just confirming my library is where it should be: libopenalpr.so
is a symlink to libopenalpr.so.2
.
$ locate libopenalpr.so
/usr/lib/libopenalpr.so
/usr/lib/libopenalpr.so.2
Can anyone point out what I'm doing wrong here?
Upvotes: 0
Views: 275
Reputation: 799230
From the gcc(1)
man page:
... the placement of the -l option is significant.
[...]
It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus,
foo.o -lz bar.o
searches libraryz
after filefoo.o
but beforebar.o
. Ifbar.o
refers to functions inz
, those functions may not be loaded.
$ g++ -Wall test.cpp -lopenalpr -o test
Upvotes: 4