问题
I want to use the zeroMQ in my project and I run the configure as below to build the libaray into my home folder
./configure --enable-static --disable-shared --prefix=/home/xx/out
then I link my project by
gcc -o myproject x.c y.c /home/xx/out/libzmq.a
but there still a lot of link error like below:
../zmq/lib/libzmq.a(libzmq_la-ip.o): In function zmq::resolve_ip_interface(sockaddr_storage*, unsigned int*, char const*)':
/home/sureone/share/zeromq-2.2.0/src/ip.cpp:221: undefined reference to std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/home/sureone/share/zeromq-2.2.0/src/ip.cpp:222: undefined reference to std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
../zmq/lib/libzmq.a(libzmq_la-ip.o): In function zmq::resolve_ip_hostname(sockaddr_storage*, unsigned int*, char const*)':
/home/sureone/share/zeromq-2.2.0/src/ip.cpp:314: undefined reference to std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, uns
...........
回答1:
gcc -o myproject x.c y.c /home/xx/out/libzmq.a
Since ZeroMQ is (apparently) using C++, you need to use appropriate compiler driver (g++
in this case) to link it.
Try this:
gcc -c x.c y.c
g++ -o myproject x.o y.o /home/xx/out/libzmq.a
来源:https://stackoverflow.com/questions/10273608/how-to-build-a-project-say-zeromq-as-static-library-and-linked-it-into-my-proj