我想实验一下OpenALPR SDK,并编写了一个小小的测试程序。问题是,我无法让它正确地编译,我也不知道为什么。这是SDK文档。
我的源文件看起来如下:
$ 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;
}我使用以下命令编译并获取输出:
$ 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只需确认我的库就可以了:libopenalpr.so是libopenalpr.so.2的一个符号链接。
$ locate libopenalpr.so
/usr/lib/libopenalpr.so
/usr/lib/libopenalpr.so.2有人能指出我在这里做错了什么吗?
发布于 2018-07-22 04:31:34
来自gcc(1)手册页:
..。-l选项的位置非常重要。 ..。 在命令中写入此选项的位置有所不同;链接器按照指定的顺序搜索和处理库和对象文件。因此,
foo.o -lz bar.o在文件foo.o之后而在bar.o之前搜索库z。如果bar.o引用z中的函数,则可能不会加载这些函数。
$ g++ -Wall test.cpp -lopenalpr -o testhttps://stackoverflow.com/questions/51462047
复制相似问题