Linker错误:未定义的“std::ctype::_M_widen_init()来自静态的lib,即使是相同的gcc版本。

时间:2023-01-11 02:09:14

I am getting error which can be seen below, error is coming from a static library which I created(libredis.a) :

我的错误可以在下面看到,错误来自于我创建的一个静态库(libredisa):

/root/projects/lib/libredis.a(redisHandler.o): In function redisHandler.cpp:(.text+0x1394): undefined reference to `std::ctype<char>::_M_widen_init() const'
collect2: ld returned 1 exit status

I am 100% positive this static lib and my project are being built with same g++ version(g++46) and I used -std=c++0x -static-libstdc++ -static-libgcc options for both them in my makefile.

我100%肯定这个静态库,我的项目是用相同的g++版本(g++46)构建的,我使用了-std=c++0x -static-libstdc+ -静态-libgcc选项,它们都在我的makefile中。

Here is the gcc output of the problem from project sorry for details :

下面是来自项目的gcc输出的问题。

g++46 common/config.o common/hash.o sighandler.o globals.o itap.o itapworker.o itapdb.o itapmsgs.o itapflow.o itapintercept.o itapstore.o itapipdr.o itaputil.o itapprotoutil.o itapmail.o itapdns.o itapdhcp.o itapradius.o itapdhcpv6.o itapsyslog.o itaprbli.o itapl2tp.o itapsip.o itapisup.o itaprudp.o itapmgcp.o itapmegaco.o itapm3ua.o itapq850codes.o itaph323.o itaprtp.o itapsdp.o itaprtpstatictypes.o itapmsn.o itapymsg.o itapftp.o itapsmtp.o itapimap.o itappop3.o itapsmpp.o itaphttp.o itaphttpproto.o itaphotmail.o itapyahoomail.o itapgmail.o itapfacebook.o itaplinkedin.o itaptwitter.o itaptac.o -o inseptrad  -L/root/projects/lib -L/usr/local/lib -L/usr/lib -lecrypt -lipcutil -lsurlicense -lsysctl -ltcpip -ldpi -lconf -ltimerq -lsqlite -lasn -lmiscutil -lredis -lpcap -lssl -lcrypto -lglib-2.0 -lxml2 -lopal -lm -lrt -lsqlite3 -lpthread -licc -lpgm-5-1-117-pic -lwiro -lwireshark -lwsutil -lpt_r -lboost_system -lhiredis `pkg-config --libs glib-2.0` -O3  -Wall -Wno-unused-function -std=c++0x -DFREEBSD -DINTEL -D__USE_BSD=1 -D__FAVOR_BSD=1 -D__USE_GNU -static-libstdc++ -static-libgcc   -I./include -I./common/include -I/root/projects/include -I/root/projects/include/wiro -I/usr/local/include/libxml2 -I/usr/include/libxml2 -I/usr/local/include/pgm-5.1 -I/usr/include/pgm-5.1 -I/usr/local/include/opal -I/usr/include/opal/ -I/usr/local/lib/gcc46/include/ -I/usr/include/hiredis -I/usr/local/include -I/usr/include `pkg-config --cflags glib-2.0`
/root/projects/lib/libredis.a(redisHandler.o): In function `redisHandler::alarmCreater(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::any>, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::any> > >*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
redisHandler.cpp:(.text+0x1394): undefined reference to `std::ctype<char>::_M_widen_init() const'
collect2: ld returned 1 exit status
gmake: *** [inseptrad] Error 1

And also gcc output when I built static library

当我构建静态库时,gcc也会输出。

[root@ ~/projects/test]# gmake clean all install
mkdir -p /root/projects/lib     && cd /root/projects/lib;     rm -f libredis.a;                   cd -
mkdir -p /root/projects/include && cd /root/projects/include; rm -f redisHandler.hpp; cd -
rm -f libredis.a *.o *~ *core*
g++46 -O3 -pipe -fno-strict-aliasing -Winline -Wall -Wno-unused-function -std=c++0x -DFREEBSD -DINTEL -D__USE_GNU -D__USE_BSD=1 -D__FAVOR_BSD=1 -static-libstdc++ -static-libgcc   -I/usr/local/include/glib-2.0 -I/usr/local/include -I/usr/include/hiredis -I/usr/local/lib/gcc46/include/ -I./include/ -I. -I/root/projects/include -I/usr/local/include -I/usr/include `pkg-config --cflags glib-2.0`   -c -o redisHandler.o redisHandler.cpp
ar scru libredis.a redisHandler.o
mkdir -p /root/projects/lib     && cp -pf libredis.a /root/projects/lib
mkdir -p /root/projects/include && cp -pf include/redisHandler.hpp  /root/projects/include

I can't find any reason why this error might occur , if you guys have some ideas I will be very thankful.

我找不出这个错误发生的原因,如果你们有一些想法,我会非常感激的。

Ps: Please guys don't close the question the other topic is not helpful for this problem .

请大家不要关闭这个问题,其他的话题对这个问题没有帮助。

1 个解决方案

#1


0  

Even I were careful the static library and project were using different libs as commenters advised me . At least I can show how I solved it:

即使我很小心,静态库和项目也使用不同的libs作为评论者建议我。至少我可以展示我是如何解决的:

[root@ ~/projects/INSEPTRA_RELENG_12_8_chunk]#  find / -name "libstdc++.a"
/usr/lib/libstdc++.a
/usr/local/lib/gcc46/libstdc++.a
/usr/local/lib/gcc47/libstdc++.a
/usr/lib32/libstdc++.a
/root/projects/lib/libstdc++.a
[root@ ~/projects/INSEPTRA_RELENG_12_8_chunk]# cp /usr/lib/libstdc++.a /usr/lib/libstdc++.a_bak
[root@ ~/projects/INSEPTRA_RELENG_12_8_chunk]# cp /usr/local/lib/gcc46/libstdc++.a /usr/lib/libstdc++.a
[root@ ~/projects/INSEPTRA_RELENG_12_8_chunk]# cp /usr/local/lib/gcc46/libstdc++.a /usr/lib32/libstdc++.a
[root@ ~/projects/INSEPTRA_RELENG_12_8_chunk]# cp /usr/local/lib/gcc46/libstdc++.a /root/projects/lib/libstdc++.a
[root@ ~/projects/INSEPTRA_RELENG_12_8_chunk]# gmake

#1


0  

Even I were careful the static library and project were using different libs as commenters advised me . At least I can show how I solved it:

即使我很小心,静态库和项目也使用不同的libs作为评论者建议我。至少我可以展示我是如何解决的:

[root@ ~/projects/INSEPTRA_RELENG_12_8_chunk]#  find / -name "libstdc++.a"
/usr/lib/libstdc++.a
/usr/local/lib/gcc46/libstdc++.a
/usr/local/lib/gcc47/libstdc++.a
/usr/lib32/libstdc++.a
/root/projects/lib/libstdc++.a
[root@ ~/projects/INSEPTRA_RELENG_12_8_chunk]# cp /usr/lib/libstdc++.a /usr/lib/libstdc++.a_bak
[root@ ~/projects/INSEPTRA_RELENG_12_8_chunk]# cp /usr/local/lib/gcc46/libstdc++.a /usr/lib/libstdc++.a
[root@ ~/projects/INSEPTRA_RELENG_12_8_chunk]# cp /usr/local/lib/gcc46/libstdc++.a /usr/lib32/libstdc++.a
[root@ ~/projects/INSEPTRA_RELENG_12_8_chunk]# cp /usr/local/lib/gcc46/libstdc++.a /root/projects/lib/libstdc++.a
[root@ ~/projects/INSEPTRA_RELENG_12_8_chunk]# gmake