【发布时间】:2018-07-22 03:53:03
【问题描述】:
我想试用 OpenALPR SDK 并编写了一个小测试程序。问题是,我无法正确编译它,我不知道为什么。这是SDK documentation。
我的源文件如下所示:
$ 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
谁能指出我在这里做错了什么?
【问题讨论】:
标签: compilation shared-libraries linker g++