How to build a project (say zeromq) as static library and linked it into my project

社会主义新天地 提交于 2019-12-10 14:54:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!