Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

...........

like image 736
sureone Avatar asked Apr 23 '12 01:04

sureone


People also ask

Why use ZeroMQ?

ZeroMQ provides a whole slew of language APIs which run on most operating systems and allows you to communicate seamlessly between all sorts of programs. It also provides a collection of patterns, such as request-reply and publish-subscribe which assist you in creating and structuring your network.

Is ZeroMQ a message broker?

ZeroMQ (also spelled ØMQ, 0MQ or ZMQ) is an asynchronous messaging library, aimed at use in distributed or concurrent applications. It provides a message queue, but unlike message-oriented middleware, a ZeroMQ system can run without a dedicated message broker; the zero in the name is for zero broker.

Is ZeroMQ open source?

Backed by a large and active open source community.


1 Answers

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
like image 167
Employed Russian Avatar answered Sep 30 '22 16:09

Employed Russian