gpt4 book ai didi

c++ - 静态库的链接器错误

转载 作者:行者123 更新时间:2023-11-28 03:24:46 25 4
gpt4 key购买 nike

我已经成功地编译了我的拼写检查程序和 libspellcheck 库。现在我的问题是允许其他开发人员使用我的 libspellcheck。我创建了一个简单的测试程序:

#include <spellcheck.h>
#include <iostream>

using namespace std;

int main(void)
{

bool spell_result = check_spelling("english.dict", "abed");

if(spell_result == true)
{
cout << "your dictionary / libspellcheck works!" << endl;
}
else
{
cout << "problem with your dictionary / libspellcheck" << endl;
}

return 0;
}

如果一切正常,程序将输出:

你的字典/libspellcheck 工作

但是,该程序甚至无法编译。我用过:

g++ -lspellcheck -o 测试测试.cpp

但它没有用。我相信这是头文件的问题,因为编译器给我这个:

test.cpp: In function ‘int main()’:
test.cpp:9:59: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
test.cpp:9:59: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
/tmp/ccIz3ivT.o: In function `main':
test.cpp:(.text+0x19): undefined reference to `check_spelling(char*, char*)'
collect2: ld returned 1 exit status

唯一的问题是,spellcheck.h 位于/usr/include,我认为它应该位于该位置。我的问题是,我该如何修复这个错误,是我的头文件有问题还是我的 libspellcheck 有问题。如果您需要查看其他代码,我很乐意提供,因为拼写检查和 libspellcheck 已获得 GPL 许可。

最佳答案

假设您在 header 中的check_spelling 声明是正确的,试试这个:

g++ -o test test.cpp -lspellcheck

(-l 应该在对象之后,具体取决于命令行中的库)。从 header 开始,它确实被发现并使用了,否则你会从编译器而不是链接器中得到一个错误。

关于c++ - 静态库的链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14443924/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com