定义引用std::basic_string

时间:2022-09-27 04:55:00

I'm compiling my project and seeing link problem

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

$ 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

The std::basic_string symbol in my gcc library as follows:

在我的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&&)

How can I fix this?

我怎么解决这个问题?

--EDIT--

——编辑

The problem fixed after I removed -std=gnu++11 from the compile command. It appears that the Chromium base library of string16 is having compatibility issue with C++11.

从编译命令中删除-std=gnu++11之后,问题就解决了。看来string16的Chromium库与c++ 11存在兼容性问题。

1 个解决方案

#1


4  

You're trying to use basic_string<unsigned short, base::string16_char_traits> but that does not come from the standard library, the libstdc++.so library only contains basic_string<char> and basic_string<wchar_t>

您尝试使用basic_string ,但它不是来自标准库,libstdc++。所以库只包含basic_string 和basic_string

That specialization must be used in one of the libraries you're using, so you should find out which and ensure you link to it correctly. If you're compiling with -fno-implicit-templates then you may need an explicit instantiation.

这种专门化必须在您使用的其中一个库中使用,因此您应该找到并确保您正确地链接到它。如果使用-fno-implicit模板编译,则可能需要显式实例化。

It might help to look for base::string16_char_traits to find where the instantiation comes from. A quick Google suggests it's from a Chromium library, so maybe you're not linking to that, or maybe you need to put that library later in the link command.

它可能有助于查找base::string16_char_traits,以找到实例化的来源。一个快速的谷歌提示它来自一个Chromium库,所以也许你没有链接到它,或者你需要把那个库放到链接命令后面。

#1


4  

You're trying to use basic_string<unsigned short, base::string16_char_traits> but that does not come from the standard library, the libstdc++.so library only contains basic_string<char> and basic_string<wchar_t>

您尝试使用basic_string ,但它不是来自标准库,libstdc++。所以库只包含basic_string 和basic_string

That specialization must be used in one of the libraries you're using, so you should find out which and ensure you link to it correctly. If you're compiling with -fno-implicit-templates then you may need an explicit instantiation.

这种专门化必须在您使用的其中一个库中使用,因此您应该找到并确保您正确地链接到它。如果使用-fno-implicit模板编译,则可能需要显式实例化。

It might help to look for base::string16_char_traits to find where the instantiation comes from. A quick Google suggests it's from a Chromium library, so maybe you're not linking to that, or maybe you need to put that library later in the link command.

它可能有助于查找base::string16_char_traits,以找到实例化的来源。一个快速的谷歌提示它来自一个Chromium库,所以也许你没有链接到它,或者你需要把那个库放到链接命令后面。