2

我已经从源代码(https://github.com/downloads/chokkan/crfsuite/crfsuite-0.12.tar.gz)正确安装了crfsuite。但是当我尝试编译一个非常简单的代码时,似乎我错过了一些东西。

这是代码:

#include "crfsuite.hpp"

using namespace CRFSuite;

int main(int argc, char *argv[]) 
{ 
    Tagger tagger;
}

这是要编译的命令行:

g++ -L/usr/local/lib -I/usr/local/include -lcrfsuite tagging.cpp

和错误:

/tmp/ccIkvCFv.o: In function `CRFSuite::Trainer::Trainer()':
tagging.cpp:(.text+0x48): undefined reference to `crfsuite_data_init'
/tmp/ccIkvCFv.o: In function `CRFSuite::Trainer::init()':
tagging.cpp:(.text+0x149): undefined reference to `crfsuite_create_instance'
tagging.cpp:(.text+0x1b7): undefined reference to `crfsuite_create_instance'
/tmp/ccIkvCFv.o: In function `CRFSuite::Trainer::clear()':
tagging.cpp:(.text+0x2dd): undefined reference to `crfsuite_data_finish'
tagging.cpp:(.text+0x2ed): undefined reference to `crfsuite_data_init'
/tmp/ccIkvCFv.o: In function `CRFSuite::Trainer::append(std::vector<std::vector<CRFSuite::Attribute, std::allocator<CRFSuite::Attribute> >, std::allocator<std::vector<CRFSuite::Attribute, std::allocator<CRFSuite::Attribute> > > > const&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, int)':
tagging.cpp:(.text+0x495): undefined reference to `crfsuite_instance_init_n'
tagging.cpp:(.text+0x51f): undefined reference to `crfsuite_item_init_n'
tagging.cpp:(.text+0x69b): undefined reference to `crfsuite_data_append'
tagging.cpp:(.text+0x6aa): undefined reference to `crfsuite_instance_finish'
/tmp/ccIkvCFv.o: In function `CRFSuite::Trainer::select(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
tagging.cpp:(.text+0x7e9): undefined reference to `crfsuite_create_instance'
/tmp/ccIkvCFv.o: In function `CRFSuite::Tagger::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
tagging.cpp:(.text+0x11a0): undefined reference to `crfsuite_create_instance_from_file'
/tmp/ccIkvCFv.o: In function `CRFSuite::Tagger::set(std::vector<std::vector<CRFSuite::Attribute, std::allocator<CRFSuite::Attribute> >, std::allocator<std::vector<CRFSuite::Attribute, std::allocator<CRFSuite::Attribute> > > > const&)':
tagging.cpp:(.text+0x16c6): undefined reference to `crfsuite_instance_init_n'
tagging.cpp:(.text+0x1731): undefined reference to `crfsuite_item_init'
tagging.cpp:(.text+0x17e1): undefined reference to `crfsuite_attribute_set'
tagging.cpp:(.text+0x17f4): undefined reference to `crfsuite_item_append_attribute'
tagging.cpp:(.text+0x1854): undefined reference to `crfsuite_instance_finish'
tagging.cpp:(.text+0x18ac): undefined reference to `crfsuite_instance_finish'
collect2: error: ld returned 1 exit status

路径正确 ( /usr/local/lib, /usr/local/include)

4

1 回答 1

0

论点的顺序很重要。该库应该在您的 cpp 文件之后:

g++ -L/usr/local/lib -I/usr/local/include tagging.cpp -lcrfsuite

查看答案为什么链接库的顺序有时会导致 GCC 出错?了解更多信息。

于 2019-09-06T15:28:13.130 回答