2012-04-23 90 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

相關問題