如何将项目(比如zeromq)构建为静态库并将其链接到我的项目中

时间:2012-04-23 01:00:43

标签: linux build hyperlink zeromq

我想在我的项目中使用zeroMQ 我运行如下配置将libaray构建到我的主文件夹

./configure --enable-static --disable-shared --prefix=/home/xx/out

然后我通过

链接我的项目
gcc -o myproject x.c y.c /home/xx/out/libzmq.a

但仍有很多链接错误,如下所示:

../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 个答案:

答案 0 :(得分:4)

  

gcc -o myproject x.c y.c /home/xx/out/libzmq.a

由于ZeroMQ(显然)使用C ++,因此需要使用适当的编译器驱动程序(在本例中为g++)来链接它。

试试这个:

 gcc -c x.c y.c
 g++ -o myproject x.o y.o /home/xx/out/libzmq.a
相关问题