2012-04-23 53 views
4

我想用zeroMQ在我的项目 我运行如下的配置来构建libaray到我的主文件夹如何建立一个项目(比如zeromq)的静态库,并将其链接到我的项目

./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

你会意识到,ØMQ是LGPL,对不对? – 2012-04-23 01:02:00

+3

LGPL与静态链接异常http://www.zeromq.org/area:licensing – g19fanatic 2012-09-07 13:50:51

回答

4

GCC -o myproject的XC YC /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 
+1

我已经解决了这个问题,应该把所有的对象文件和libzmq.a之前的-lstdC++放在它们之前。 – sureone 2012-04-23 05:20:21

+1

@sureone“应该在所有对象之后放置-lstdC++” - 虽然此解决方案似乎可行,但它不一定是正确的,并且明天可能无法工作。链接C++代码时,你*应该使用'g ++'。 – 2012-04-23 05:36:10

+0

感谢您的建议,我尝试了你的方式,它确实解决了我的问题。 – sureone 2012-04-23 08:31:15

相关问题