首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法用库进行编译

无法用库进行编译
EN

Stack Overflow用户
提问于 2018-07-22 03:53:03
回答 1查看 254关注 0票数 0

我想实验一下OpenALPR SDK,并编写了一个小小的测试程序。问题是,我无法让它正确地编译,我也不知道为什么。这是SDK文档

我的源文件看起来如下:

代码语言:javascript
复制
$ 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;
}

我使用以下命令编译并获取输出:

代码语言:javascript
复制
$ 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.solibopenalpr.so.2的一个符号链接。

代码语言:javascript
复制
$ locate libopenalpr.so
/usr/lib/libopenalpr.so
/usr/lib/libopenalpr.so.2

有人能指出我在这里做错了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-22 04:31:34

来自gcc(1)手册页:

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

代码语言:javascript
复制
$ g++ -Wall test.cpp -lopenalpr -o test
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51462047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档