开发者

Undefined symbol with g++

I have implemented the tutorial example of boost for the asio library, but with seperation through a header file:

server.cpp

server.h

I build both files with another .cpp file in the 开发者_StackOverflow中文版following way:

g++ -I/usr/lib/jvm/java-6-openjdk/include -L/usr/local/lib -fPIC  -lboost_system -shared -o libagent.so agent.cpp server.cpp 

When using the shared library I have compiled, I get:

java: symbol lookup error: ./libagent.so: undefined symbol: _ZN14tcp_connection6socketEv

What seems to be the cause for this error? ldd -d gives me no dependency misses.


You're not actually linking to the boost::asio library, therefore the shared object doesn't know where to find the symbol that is being used in your class.

assuming the library is called boost_asio, you need to add:

-lboost_asio

to the link line.

... scratch that, completely wrong.

You're missing the implementation of the tcp_connection::socket - that's where the error comes from.

perhaps the line:

tcp::socket& socket();

in the .h file needs to read:

tcp::socket& socket() { return socket_; }


The most likely guess is that ./libagent.so was compiled with a different compiler/settings/environment and the name mangling doesn't exactly match.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜