如何使用依赖boost和另一个静态库的静态库编译代码?
我已经尝试了
g++ -lSimpleAmqpClient test_simpleamqpclient.cpp -o test_simpleamqpclient
和
g++ -lrabbitmq -lSimpleAmqpClient test_simpleamqpclient.cpp -o test_simpleamqpclient
test_simpleamqpclient.cpp
#include "SimpleAmqpClient/SimpleAmqpClient.h"
int main(){
AmqpClient::BasicMessage::ptr_t message = AmqpClient::BasicMessage::Create();
return 0;
}
/usr/local/include/SimpleAmqpClient/SimpleAmqpClient.h
:
#include "SimpleAmqpClient/BasicMessage.h"
:
我正在
/tmp/ccMsTz9s.o: In function `boost::detail::sp_if_not_array<AmqpClient::BasicMessage>::type boost::make_shared<AmqpClient::BasicMessage>()':
test_simpleamqpclient.cpp:(.text._ZN5boost11make_sharedIN10AmqpClient12BasicMessageEEENS_6detail15sp_if_not_arrayIT_E4typeEv[_ZN5boost11make_sharedIN10AmqpClient12BasicMessageEEENS_6detail15sp_if_not_arrayIT_E4typeEv]+0x62): undefined reference to `AmqpClient::BasicMessage::BasicMessage()'
collect2: error: ld returned 1 exit status
静态库, libSimpleAmqpClient.a 。
libSimpleAmqpClient.pc
prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include
Name: SimpleAmqpClient
Description: C++ wrapper of rabbitmq-c AMQP client library
Version: 2.5.0
Requires.private: librabbitmq
Libs: -L${libdir} -lSimpleAmqpClient
Libs.private: -L/usr/local/lib -lboost_chrono -lboost_system
CFlags: -I${includedir}
它依赖于 boost 和另一个库 librabbitmq.a
librabbitmq.pc
prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib64
includedir=${prefix}/include
Name: rabbitmq-c
Description: An AMQP 0-9-1 client library
Version: 0.8.1
URL: https://github.com/alanxz/rabbitmq-c
Requires.private:
Libs: -L${libdir} -lrabbitmq
Libs.private: rt;-lpthread
CFlags: -I${includedir}
答案 0 :(得分:1)
事实证明,即使您使用静态库进行链接,仍然需要链接库依赖项。我已经设法用这种语法编译它
g++ test_simpleamqpclient.cpp -o test_simpleamqpclient -lSimpleAmqpClient -lboost_chrono -lboost_system -lrabbitmq -lrt -lssl
希望这会对某人有所帮助。