繁体   English   中英

无法与库一起编译

[英]unable to compile with library

我想尝试使用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

谁能指出我在这里做错了什么?

gcc(1)手册页中:

... -l选项的位置很重要。

[...]

在命令中写入此选项的位置会有所不同。 链接器按照指定的顺序搜索和处理库和目标文件。 因此, foo.o -lz bar.o搜索库z文件后, foo.o但在此之前bar.o 如果bar.o引用z中的函数,则可能不会加载这些函数。

$ g++ -Wall test.cpp -lopenalpr -o test

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM