今天写了一个小程序,结果碰见来一大堆的问题。代码的问题就先不说了。
1.[root@localhost jni]# g++ Bodies.cpp -o z
/tmp/cc5Cismh.o: In function `gloox::JID::JID(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
Bodies.cpp:(.text._ZN5gloox3JIDC2ERKSs[_ZN5gloox3JIDC5ERKSs]+0x6d): undefined reference to `gloox::JID::setJID(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/tmp/cc5Cismh.o: In function `Bodies::start()':
Bodies.cpp:(.text._ZN6Bodies5startEv[Bodies::start()]+0xfe): undefined reference to `gloox::Client::Client(gloox::JID const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
Bodies.cpp:(.text._ZN6Bodies5startEv[Bodies::start()]+0x11b): undefined reference to `gloox::ClientBase::registerConnectionListener(gloox::ConnectionListener*)'
Bodies.cpp:(.text._ZN6Bodies5startEv[Bodies::start()]+0x18c): undefined reference to `gloox::GLOOX_VERSION'
Bodies.cpp:(.text._ZN6Bodies5startEv[Bodies::start()]+0x19b): undefined reference to `gloox::Disco::setVersion(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
Bodies.cpp:(.text._ZN6Bodies5startEv[Bodies::start()]+0x231): undefined reference to `gloox::EmptyString'
Bodies.cpp:(.text._ZN6Bodies5startEv[Bodies::start()]+0x247): undefined reference to `gloox::Disco::setIdentity(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
Bodies.cpp:(.text._ZN6Bodies5startEv[Bodies::start()]+0x2f6): undefined reference to `gloox::ClientBase::connect(bool)'
collect2: ld 返回 1
这是我碰到编译的第一个大问题,是没有链接共享库(.so)
解决如下,结果碰见来下一个问题:
[root@localhost jni]# g++ Bodies.cpp -o z /usr/local/lib/libgloox.so
/usr/local/lib/libgloox.so: undefined reference to `pthread_mutex_trylock'
collect2: ld 返回 1
说的是没有定义相关线程库,在我大牛同学的指导之下解决了:
[root@localhost jni]# g++ Bodies.cpp -o z /usr/local/lib/libgloox.so -lpthread
[root@localhost jni]# ./z
./z: error while loading shared libraries: libgloox.so.8: cannot open shared object file: No such file or directory
但是很不幸,运行的时候还是出现来问题,后来还是在我大牛同学的帮助下找到来解决方案:
[root@localhost jni]# export LD_LIBRARY_PATH=/usr/local/lib
[root@localhost jni]# ./z
please enter your username and password!
成功了,悲剧啊!