Linking error for client of rabbitmq-c

1.5k Views Asked by At

I want to implement a small c++ client, that connects to my local RabbitMQ-server.

The app is configured with CMakeList as follows:

Boost_STATIC_LIBS: ON
Boost SHARED_LIBS: ON
ENABLE_SSL_SUPPORT: ON
Rabbitmqc_INCLUDE_DIR: C:/rabbitmq-c/include
Rabbitmqc_LIBRARY: C:/rabbitmq-c/lib
Rabbitmqc_SSL_ENABLED: ON
_Rabbitmqc_SSL_HEADER: C:/rabbitmq-c/include/amqp_ssl_socket.h

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(client)

INCLUDE_DIRECTORIES(
    ${CMAKE_CURRENT_BINARY_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/utilities
    )

# Find Boost library
SET(Boost_INCLUDE_DIR C:/local/boost_1_64_0)
SET(Boost_LIBRARY_DIR C:/local/boost_1_64_0/lib64-msvc-14.0)
FIND_PACKAGE(Boost 1.64.0 COMPONENTS chrono system REQUIRED)
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})   

# Find Rabbitmqc library
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Modules)
FIND_PACKAGE(Rabbitmqc REQUIRED)
INCLUDE_DIRECTORIES(SYSTEM ${Rabbitmqc_INCLUDE_DIRS})

OPTION(ENABLE_SSL_SUPPORT "Enable SSL support." ${Rabbitmqc_SSL_ENABLED})
OPTION(BUILD_SHARED_LIBS "Build client as a shared library" ON)
OPTION(BOOST_STATIC_LIBS "Build Boost as a static library" ON)

IF(WIN32)
    SET(PLATFORM_DIR win32)
ELSE(WIN32)
    SET(PLATFORM_DIR unix)
ENDIF(WIN32) 

set(COMMON_SRCS
    utilities/utils.h
    utilities/utils.c
    ${PLATFORM_DIR}/utilities/platform_utils.c
    )

SET(client_SRCS
    testClient.cxx
)
ADD_EXECUTABLE(client ${client_SRCS})
TARGET_LINK_LIBRARIES(client ${Boost_LIBRARIES} ${Rabbitmqc_LIBRARY} ${OPENSSL_LIBRARIES} ${SOCKET_LIBRARY})

The output of CMake-Gui after generating:

Boost version: 1.64.0
Found the following Boost libraries:
chrono
system
Found Rabbitmqc 
Configuring done
WARNING: Target "client" requests linking to directory "C:/rabbitmq-c/lib".  Targets may link only to libraries.  CMake is dropping the item.
Generating done

I don't understand why the Rabbitmqc library is not linked properly. is the entry ${Rabbitmqc_LIBRARY} in TARGET_LINK_LIBRARIES not enough?

If I compile my client, then I get following errors:

testClient.cxx

#include <iostream>
#include <amqp.h>
#include <amqp_tcp_socket.h>

#include <assert.h>

#include "utilities\utils.h"

int main(int argc, char const *const *argv) 
{
  char const *hostname;
  int port, status;
  char const *exchange;
  char const *bindingkey;
  amqp_socket_t *socket = NULL;
  amqp_connection_state_t conn;
  amqp_bytes_t queuename;

  if (argc < 5) 
  {
    fprintf(stderr, "Usage: amqp_listen host port exchange bindingkey\n");
    return 1;
  }

  hostname = "localhost";
  port = atoi("15672");
  exchange = "testExchange";
  bindingkey = "testMessage";

  conn = amqp_new_connection();

  socket = amqp_tcp_socket_new(conn);
  if(!socket) 
  {
    std::cout<<"Error creating SSL/TLS socket"<<std::endl;
  }

  status = amqp_socket_open(socket, hostname, port);
  if(status) 
  {
    std::cout<<"opening TCP socket"<<std::endl;
  }
}


LINK : warning LNK4044: unrecognized option '/lrabbitmq'; ignored
2>testClient.obj : error LNK2019: unresolved external symbol _amqp_new_connection referenced in function _main
2>testClient.obj : error LNK2019: unresolved external symbol _amqp_socket_open referenced in function _main
2>testClient.obj : error LNK2019: unresolved external symbol _amqp_tcp_socket_new referenced in function _main
2>C:\local\boost_1_64_0\lib64-msvc-14.0\boost_chrono-vc140-mt-1_64.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86'
2>C:\local\boost_1_64_0\lib64-msvc-14.0\boost_system-vc140-mt-1_64.lib : warning LNK4272: library machine type 'x64' conflicts with target machine type 'X86'

Thank you for any suggestion!

OS: Win10 64x
Boost: boost_1_64_0 (in path)
rabbitmq-c (in path)
RabbitMQ Server: rabbitmq_server-3.7.6 (in path)
CMake: 3.9.6
OpenSSL: Win32OpenSSL-1_1_0h
IDE: Visual Studio 14(2015)
0

There are 0 best solutions below