对std :: basic_string的未定义引用

时间:2013-07-05 06:39:10

标签: c++ gcc c++11 linker g++

我正在编译我的项目并看到链接问题

$ g++ -Wl,-z,now -Wl,-z,relro -pthread -Wl,-z,noexecstack -fPIC -Wl,--threads -Wl,--thread-count=4 -B../../third_party/gold -L. -Wl,-uIsHeapProfilerRunning,-uProfilerStart -Wl,-u_Z21InitialMallocHook_NewPKvj,-u_Z22InitialMallocHook_MMapPKvS0_jiiix,-u_Z22InitialMallocHook_SbrkPKvi -Wl,-u_Z21InitialMallocHook_NewPKvm,-u_Z22InitialMallocHook_MMapPKvS0_miiil,-u_Z22InitialMallocHook_SbrkPKvl -Wl,-u_ZN15HeapLeakChecker12IgnoreObjectEPKv,-u_ZN15HeapLeakChecker14UnIgnoreObjectEPKv -Wl,--icf=none -Wl,-rpath=\$ORIGIN/lib/ -Wl,-rpath-link=lib/ -o cameo -Wl,--start-group obj/cameo/src/runtime/app/cameo.cameo_main.o obj/media/libmedia_sse.a ...(omitted many *.a here) -Wl,--end-group -lX11 -lXcursor -lXrandr -lXrender -lrt -ldl -lgmodule-2.0 -lgobject-2.0 -lgthread-2.0 -lglib-2.0 -lXtst -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lXi -lXcomposite -lasound -lXdamage -lXext -lXfixes -lnss3 -lnssutil3 -lsmime3 -lplds4 -lplc4 -lnspr4 -lgconf-2 -lresolv -ldbus-1 -lcups -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err -lgnutls -lgcrypt -lz -lpthread -lm -lcrypt -L/lib/x86_64-linux-gnu -lexpat -ludev
/usr/include/c++/4.7/ext/new_allocator.h:110: error: undefined reference to 'std::basic_string<unsigned short, base::string16_char_traits, std::allocator<unsigned short> >::basic_string(std::basic_string<unsigned short, base::string16_char_traits, std::allocator<unsigned short> >&&)'
/usr/include/c++/4.7/bits/stl_construct.h:77: error: undefined reference to 'std::basic_string<unsigned short, base::string16_char_traits, std::allocator<unsigned short> >::basic_string(std::basic_string<unsigned short, base::string16_char_traits, std::allocator<unsigned short> >&&)'
error: ld returned 1 exit status

我的gcc库中的std::basic_string符号如下:

$ find /usr -name libstdc++.a
/usr/lib/gcc/x86_64-linux-gnu/4.6/32/libstdc++.a
/usr/lib/gcc/x86_64-linux-gnu/4.6/libstdc++.a
/usr/lib/gcc/x86_64-linux-gnu/4.7/32/libstdc++.a
/usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.a

$ nm -C /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.a| grep basic_string | grep '&&'
nm: compatibility-debug_list-2.o: no symbols
nm: compatibility-list-2.o: no symbols
nm: compatibility-parallel_list-2.o: no symbols
0000000000000000 W std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::assign(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&&)
0000000000000000 W std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::operator=(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&&)
0000000000000000 W std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::basic_string(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&&)
0000000000000000 W std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::basic_string(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&&)
0000000000000000 n std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::basic_string(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&&)
0000000000000000 W std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string&&)
0000000000000000 W std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string&&)
0000000000000000 n std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string&&)

我该如何解决这个问题?

- 编辑 -

我从编译命令中删除-std=gnu++11后修复了问题。似乎string16的Chromium基本库与C ++ 11存在兼容性问题。

1 个答案:

答案 0 :(得分:5)

您尝试使用basic_string<unsigned short, base::string16_char_traits>,但这并非来自标准库,libstdc++.so库仅包含basic_string<char>basic_string<wchar_t>

必须在您正在使用的某个库中使用该专业化,因此您应该找出哪些并确保正确链接到它。如果您使用-fno-implicit-templates进行编译,则可能需要显式实例化。

查找base::string16_char_traits以查找实例化的来源可能会有所帮助。一个快速的谷歌建议它来自一个Chromium库,所以也许你没有链接到那个,或者你可能需要稍后在链接命令中放置该库。