如何建立一个项目(比如zeromq)为静态库,并将其链接到我的项目 [英] How to build a project (say zeromq) as static library and linked it into my project

查看:1907
本文介绍了如何建立一个项目(比如zeromq)为静态库,并将其链接到我的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用的zeroMQ在我的项目
我跑的配置如下打造libaray到我的主文件夹

  ./配置--enable-静态--disable共享 -  preFIX = /家庭/ XX /出

然后我通过

链接我的项目

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

但仍有很多链接错误象下面这样:

  ../ ZMQ / lib中/ libzmq.a(libzmq_la-ip.o):在功能ZMQ :: resolve_ip_interface(sockaddr_storage *,无符号整型*,字符常量*):
/home/sureone/share/zeromq-2.2.0/src/ip.cpp:221:未定义的引用到std :: basic_string的<焦炭,的std :: char_traits<焦炭>中的std ::分配器<焦炭> > :: basic_string的〜()
/home/sureone/share/zeromq-2.2.0/src/ip.cpp:222:未定义的引用到std :: basic_string的<焦炭,的std :: char_traits<焦炭>中的std ::分配器<焦炭> > :: basic_string的〜()
../zmq/lib/libzmq.a(libzmq_la-ip.o):在功能ZMQ :: resolve_ip_hostname(sockaddr_storage *,无符号整型*,字符常量*):
/home/sureone/share/zeromq-2.2.0/src/ip.cpp:314:未定义的引用到std :: basic_string的<焦炭,的std :: char_traits<焦炭>中的std ::分配器<焦炭> > :: basic_string的(字符常量*,UNS

...........


解决方案

  

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


由于使用C ++ ZeroMQ是(显然),则需要使用相应的编译器驱动程序( G ++ 在这种情况下)链接​​它。

试试这个:

  GCC -c x.c y.c
 G ++ -o myproject的X.O y.o /home/xx/out/libzmq.a

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

...........

解决方案

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

这篇关于如何建立一个项目(比如zeromq)为静态库,并将其链接到我的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆