gpt4 book ai didi

c++ - 如何使用依赖于另一个静态库的静态库进行编译

转载 作者:行者123 更新时间:2023-11-28 05:15:49 33 4
gpt4 key购买 nike

如何使用依赖于 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}

最佳答案

事实证明,即使您正在链接静态库,您仍然需要链接库依赖项。我已经设法用这种语法编译它

g++ test_simpleamqpclient.cpp -o test_simpleamqpclient -lSimpleAmqpClient -lboost_chrono -lboost_system -lrabbitmq -lrt -lssl

希望这会对某人有所帮助。

关于c++ - 如何使用依赖于另一个静态库的静态库进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42686810/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com