Статическое связывание ActiveMQ-cpp

Я создаю проект C ++, в котором я хочу, чтобы он работал в автономном режиме без каких-либо зависимостей, так как он будет развернут на нескольких серверах.

Это мое CMakeLists файл :

project(CMS-test)
cmake_minimum_required(VERSION 2.6)

add_executable(main main.cpp)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

INCLUDE_DIRECTORIES(/usr/local/apr/include/apr-1)
INCLUDE_DIRECTORIES(/usr/local/include/activemq-cpp-3.9.4)

target_link_libraries(main ${CMAKE_SOURCE_DIR}/libapr-1.a)
target_link_libraries(main ${CMAKE_SOURCE_DIR}/libactivemq-cpp.a)

libactivemq-cpp.a и libapr-1.a находятся в моей директории проекта

но ошибка я получаю после make main во время связывания

/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/DecafRuntime.cpp:72: undefined reference to `apr_initialize'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/DecafRuntime.cpp:73: undefined reference to `apr_pool_create_ex'
libactivemq-cpp.a(libactivemq_cpp_la-DecafRuntime.o): In function `decaf::lang::Runtime::shutdownRuntime()':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/DecafRuntime.cpp:109: undefined reference to `apr_pool_destroy'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/DecafRuntime.cpp:110: undefined reference to `apr_terminate'
libactivemq-cpp.a(libactivemq_cpp_la-Network.o): In function `decaf::internal::net::Network::initializeNetworking()':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/Network.cpp:116: undefined reference to `apr_signal_block'
libactivemq-cpp.a(libactivemq_cpp_la-SecureRandomImpl.o): In function `decaf::internal::security::SecureRandomImpl::providerNextBytes(unsigned char*, int)':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/security/unix/SecureRandomImpl.cpp:128: undefined reference to `apr_file_read_full'
libactivemq-cpp.a(libactivemq_cpp_la-SecureRandomImpl.o): In function `decaf::internal::security::SecureRandomImpl::SecureRandomImpl()':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/security/unix/SecureRandomImpl.cpp:76: undefined reference to `apr_file_open'
libactivemq-cpp.a(libactivemq_cpp_la-Exception.o): In function `decaf::lang::Exception::buildMessage(char const*, __va_list_tag (&) [1])':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/lang/Exception.cpp:124: undefined reference to `apr_pvsprintf'
libactivemq-cpp.a(libactivemq_cpp_la-System.o): In function `decaf::lang::System::unsetenv(std::string const&)':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/lang/System.cpp:276: undefined reference to `apr_env_delete'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/lang/System.cpp:286: undefined reference to `apr_strerror'
libactivemq-cpp.a(libactivemq_cpp_la-System.o): In function `decaf::lang::System::getenv(std::string const&)':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/lang/System.cpp:297: undefined reference to `apr_env_get'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/lang/System.cpp:306: undefined reference to `apr_strerror'
libactivemq-cpp.a(libactivemq_cpp_la-System.o): In function `decaf::lang::System::setenv(std::string const&, std::string const&)':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/lang/System.cpp:326: undefined reference to `apr_env_set'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/lang/System.cpp:336: undefined reference to `apr_strerror'
libactivemq-cpp.a(libactivemq_cpp_la-InetAddress.o): In function `decaf::net::InetAddress::getLocalHost()':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/net/InetAddress.cpp:158: undefined reference to `apr_gethostname'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/net/InetAddress.cpp:168: undefined reference to `apr_sockaddr_info_get'
libactivemq-cpp.a(libactivemq_cpp_la-AprPool.o): In function `decaf::internal::AprPool::destroyPool()':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/AprPool.cpp:50: undefined reference to `apr_pool_destroy'
libactivemq-cpp.a(libactivemq_cpp_la-AprPool.o): In function `decaf::internal::AprPool::allocatePool() const':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/AprPool.cpp:42: undefined reference to `apr_pool_create_unmanaged_ex'
libactivemq-cpp.a(libactivemq_cpp_la-AprPool.o): In function `decaf::internal::AprPool::cleanup()':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/AprPool.cpp:60: undefined reference to `apr_pool_clear'
libactivemq-cpp.a(libactivemq_cpp_la-TcpSocket.o): In function `decaf::internal::net::tcp::TcpSocket::connect(std::string const&, int, int)':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:312: undefined reference to `apr_sockaddr_info_get'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:318: undefined reference to `apr_socket_opt_get'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:319: undefined reference to `apr_socket_timeout_get'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:322: undefined reference to `apr_socket_opt_set'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:328: undefined reference to `apr_socket_timeout_set'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:332: undefined reference to `apr_socket_connect'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:335: undefined reference to `apr_socket_opt_set'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:336: undefined reference to `apr_socket_timeout_set'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:326: undefined reference to `apr_socket_timeout_set'
libactivemq-cpp.a(libactivemq_cpp_la-TcpSocket.o): In function `decaf::internal::net::tcp::TcpSocket::available()':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:417: undefined reference to `apr_os_sock_get'
libactivemq-cpp.a(libactivemq_cpp_la-TcpSocket.o): In function `decaf::internal::net::tcp::TcpSocket::getLocalAddress() const':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:376: undefined reference to `apr_socket_addr_get'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:378: undefined reference to `apr_sockaddr_ip_getbuf'
libactivemq-cpp.a(libactivemq_cpp_la-TcpSocket.o): In function `decaf::internal::net::tcp::TcpSocket::getOption(int) const':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:571: undefined reference to `apr_socket_opt_get'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:541: undefined reference to `apr_socket_timeout_get'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:545: undefined reference to `apr_socket_opt_get'
libactivemq-cpp.a(libactivemq_cpp_la-TcpSocket.o): In function `decaf::internal::net::tcp::TcpSocket::setOption(int, int)':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:621: undefined reference to `apr_socket_opt_set'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:591: undefined reference to `apr_socket_opt_set'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:593: undefined reference to `apr_socket_timeout_set'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:603: undefined reference to `apr_socket_opt_set'
libactivemq-cpp.a(libactivemq_cpp_la-TcpSocket.o): In function `decaf::internal::net::tcp::TcpSocket::read(unsigned char*, int, int, int)':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:675: undefined reference to `apr_socket_recv'
libactivemq-cpp.a(libactivemq_cpp_la-TcpSocket.o): In function `decaf::internal::net::tcp::TcpSocket::write(unsigned char const*, int, int, int)':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:745: undefined reference to `apr_socket_send'
libactivemq-cpp.a(libactivemq_cpp_la-TcpSocket.o): In function `decaf::internal::net::tcp::TcpSocket::create()':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:157: undefined reference to `apr_socket_create'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/tcp/TcpSocket.cpp:161: undefined reference to `apr_os_sock_get'
libactivemq-cpp.a(libactivemq_cpp_la-TcpSocket.o): In function `decaf::internal::net::tcp::TcpSocket::accept(decaf::net::SocketImpl*)':

/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/net/SocketError.cpp:42: undefined reference to `apr_strerror'
libactivemq-cpp.a(libactivemq_cpp_la-Date.o): In function `decaf::util::Date::toString() const':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/util/Date.cpp:112: undefined reference to `apr_time_exp_lt'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/util/Date.cpp:117: undefined reference to `apr_strftime'
libactivemq-cpp.a(libactivemq_cpp_la-OpenSSLContextSpi.o): In function `decaf::internal::net::ssl::openssl::OpenSSLContextSpi::providerInit(decaf::security::SecureRandom*)':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp:188: undefined reference to `SSL_load_error_strings'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp:189: undefined reference to `SSL_library_init'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp:190: undefined reference to `OPENSSL_add_all_algorithms_noconf'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp:226: undefined reference to `SSL_CTX_use_PrivateKey_file'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp:245: undefined reference to `SSL_CTX_load_verify_locations'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp:253: undefined reference to `RAND_seed'
libactivemq-cpp.a(libactivemq_cpp_la-OpenSSLContextSpi.o): In function `decaf::internal::net::ssl::openssl::OpenSSLContextSpi::~OpenSSLContextSpi()':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp:162: undefined reference to `CRYPTO_set_locking_callback'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp:163: undefined reference to `EVP_cleanup'
libactivemq-cpp.a(libactivemq_cpp_la-OpenSSLContextSpi.o): In function `~ContextData':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLContextSpi.cpp:110: undefined reference to `SSL_CTX_free'
libactivemq-cpp.a(libactivemq_cpp_la-OpenSSLSocketException.o): In function `decaf::internal::net::ssl::openssl::OpenSSLSocketException::getErrorString() const':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.cpp:102: undefined reference to `ERR_get_error'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.cpp:104: undefined reference to `ERR_error_string_n'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocketException.cpp:102: undefined reference to `ERR_get_error'
libactivemq-cpp.a(libactivemq_cpp_la-OpenSSLParameters.o): In function `decaf::internal::net::ssl::openssl::OpenSSLParameters::OpenSSLParameters(ssl_ctx_st*)':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp:573: undefined reference to `SSL_write'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp:575: undefined reference to `SSL_get_error'
libactivemq-cpp.a(libactivemq_cpp_la-OpenSSLSocket.o): In function `decaf::internal::net::ssl::openssl::OpenSSLSocket::available()':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp:641: undefined reference to `X509_free'
libactivemq-cpp.a(libactivemq_cpp_la-OpenSSLSocket.o): In function `decaf::internal::net::ssl::openssl::OpenSSLSocket::verifyServerCert(std::string const&)':
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp:686: undefined reference to `X509_get_subject_name'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp:692: undefined reference to `X509_NAME_get_index_by_NID'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp:367: undefined reference to `SSL_ctrl'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp:370: undefined reference to `SSL_connect'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp:376: undefined reference to `SSL_get_error'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp:406: undefined reference to `SSL_set_verify'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp:408: undefined reference to `SSL_accept'
/home/isammour/Desktop/smart/activemq-cpp-library-3.9.4/src/main/decaf/internal/net/ssl/openssl/OpenSSLSocket.cpp:361: undefined reference to `SSL_set_verify'

и больше..

Я не знаю, что делать, чтобы исправить эти ошибки

Любой совет ?

1

Решение

Я предполагаю, что апрель является зависимостью от activemq. Если это так, вам нужно переключить порядок ссылок apr и activemq.

Компоновщик будет использовать каждую библиотеку только один раз. И когда он обрабатывает libactivemq-cpp.a, он видит, что это зависит от apr, но libapr-1.a уже обработан.

1

Другие решения

Выяснил, что я делаю target_link_libraries в неправильном порядке и как указано финн Я изменил порядок библиотек

Полный рабочий CMakeLists файл сейчас

project(CMS-test C CXX)
cmake_minimum_required(VERSION 2.6)

add_executable(main main.cpp)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

INCLUDE_DIRECTORIES(/usr/local/apr/include/apr-1)
INCLUDE_DIRECTORIES(/usr/local/include/activemq-cpp-3.9.4)
INCLUDE_DIRECTORIES(/usr/lib/x86_64-linux-gnu/)
find_package (Threads)
target_link_libraries(main ${CMAKE_THREAD_LIBS_INIT})target_link_libraries(main ${CMAKE_SOURCE_DIR}/libactivemq-cpp.a)
target_link_libraries(main ${CMAKE_SOURCE_DIR}/libapr-1.a)
target_link_libraries(main ssl)
target_link_libraries(main crypto)
target_link_libraries(main dl)
0

По вопросам рекламы [email protected]