c++ - 无法使用 crfsuite 的 C++ API 编译一个非常简单的 Tagger 示例

标签 c++ crfsuite

我已经从源代码(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)

最佳答案

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

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

查看答案 Why does the order in which libraries are linked sometimes cause errors in GCC?获取更多信息。

关于c++ - 无法使用 crfsuite 的 C++ API 编译一个非常简单的 Tagger 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57823691/

相关文章:

c++ - 如何链接未知库

machine-learning - 如何在 python crfsuite 中使用 Conll 2003 语料库

java - jcrfsuite 训练文件格式

python - 在 crfsuite 中使用标签作为属性

c++ 解决方案在 leetcode 上失败,地址未对齐错误,但在 Visual Studio 中运行

c++ - C++ 对齐的 future : passing by value?

android - Opencv Android 的代码优化

c# - 可移植独立C#编译器

python - 如何使用词嵌入作为 CRF (sklearn-crfsuite) 模型训练的特征

image-processing - CRF++ 或 CRFSuite