问题描述
将clang与libc ++一起使用时,为什么会出现以下链接器错误:
Why am I getting the following linker error when using clang with libc++:
$ clang++ -stdlib=libc++ po.cxx -lpoppler
/tmp/po-QqlXGY.o: In function `main':
po.cxx:(.text+0x33): undefined reference to `Dict::lookup(char*, Object*, std::__1::set<int, std::__1::less<int>, std::__1::allocator<int> >*)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
位置:
$ nm -D /usr/lib/x86_64-linux-gnu/libpoppler.so | grep lookup | c++filt| grep \ Dict::lookup\(
00000000000c1870 T Dict::lookup(char*, Object*, std::set<int, std::less<int>, std::allocator<int> >*)
代码很简单:
#include <poppler/PDFDoc.h>
int main()
{
Dict *infoDict;
Object obj;
infoDict->lookup((char*)"key", &obj);
return 0;
}
推荐答案
根据您的错误,应该就像您正在尝试将libc ++与stdlibc ++链接在一起一样,libc ++和stdlibc ++是不同的,stdlibc ++是gcc的c ++标准库,它将彼此不兼容.
According you error, it should be like you're trying to link a libc++ with stdlibc++,the libc++ and stdlibc++ is different, stdlibc++ is gcc's c++ standard library, it will not compatible with each other.
对于您的问题,就像您的libpoppler.so正在使用stdlibc ++,但是在您的clang命令行中,您尝试将libc ++用作标准lib,它们在链接阶段具有不同的名称,有关详细原因,请参见此答案末尾的链接.
For your issue, it's like your libpoppler.so is using stdlibc++,but in your clang command line, you're trying use libc++ as standard lib, they have different name in linking stage, see link at the end of this answer for detail why.
所以,也许您的解决方案就是将compile命令更改为
So, maybe your solution is just change the compile command to
clang++ -stdlib=libstdc++ po.cxx -lpoppler
请查看此问题以了解为什么使用std:__ 1 :: set和std :: set的详细信息.
Please see this question for detail why std:__1::set and std::set.
为什么可以?在c ++ 0x模式下使用libc ++敲响c链接此boost :: program_options示例吗?
这篇关于clang ++ -stdlib = libc ++导致未定义的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!