Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nothing happens when using shared library from cmake build #434

Open
akay25 opened this issue Oct 12, 2021 · 2 comments
Open

Nothing happens when using shared library from cmake build #434

akay25 opened this issue Oct 12, 2021 · 2 comments

Comments

@akay25
Copy link

akay25 commented Oct 12, 2021

Describe the bug
When using the build generated with cmake instructions, the program exits with code 0. On using make instructions to build the library, the same code listens for incoming messages from rabbitmq server as expected.

I used the following cmake instructions to build the library:

git clone [email protected]:CopernicaMarketingSoftware/AMQP-CPP.git
cd AMQP-CPP
mkdir build && cd build
cmake .. -DAMQP-CPP_BUILD_SHARED=ON -DAMQP-CPP_LINUX_TCP=ON
sudo cmake --build . --target install

Also, I used the following make instructions to build the library:

git clone [email protected]:CopernicaMarketingSoftware/AMQP-CPP.git
cd AMQP-CPP
make
sudo make install

Expected behavior and actual behavior
Expected behaviour: Program should listen for incoming messages from rabbitmq.
Actual behaviour: Program exits with code 0. I tried adding break points in the lambda functions but same result. No error message on passing invalid credentials or host either.

Main file

int main() {

    // access to the boost asio handler
    // note: we suggest use of 2 threads - normally one is fin (we are simply
    // demonstrating thread safety).
    boost::asio::io_service service(4);

    // handler for libev
    AMQP::LibBoostAsioHandler handler(service);

    // make a connection
    AMQP::TcpConnection connection(&handler,
                                   AMQP::Address("amqp://localhost/"));

    // we need a channel too
    AMQP::TcpChannel channel(&connection);

    // On error
    channel.declareQueue(config::RABBITMQ_QUEUE_NAME)
        .onError([&handler](const char *message) {
            std::cout << "Channel error: " << message << std::endl;
            // handler.st
        });

    // Consume handler
    channel.consume(config::RABBITMQ_QUEUE_NAME, AMQP::noack)
        .onReceived(
            [](const AMQP ::Message &msg, uint64_t tag, bool redelivered) {
                std::cout << "Received: " << msg.body() << std::endl;
            });

    // run the handler
    // at the moment, one will need SIGINT to stop.  In time, should add signal
    // handling through boost API.
    return service.run();
}

CmakeLists.txt

cmake_minimum_required(VERSION 3.20)
project(project_name)

# Setting up logger here
if(NOT TARGET spdlog)
    # Stand-alone build
    find_package(spdlog REQUIRED)
endif()

set(CMAKE_CXX_STANDARD 17)
set(SOURCE_FILES src/main.cpp )

add_executable(image_compressor ${SOURCE_FILES})

# Setting up magick locations
add_definitions( -DMAGICKCORE_QUANTUM_DEPTH=16 )
add_definitions( -DMAGICKCORE_HDRI_ENABLE=0 )
find_package(ImageMagick COMPONENTS Magick++)
include_directories(${ImageMagick_INCLUDE_DIRS})

target_link_libraries(image_compressor pthread spdlog::spdlog uuid amqpcpp ev dl ${ImageMagick_LIBRARIES})
@EmielBruijntjes
Copy link
Member

EmielBruijntjes commented Oct 13, 2021

I see you're using boost asio. I have no experience with that. Can you send an example that uses an event loop that I am familiar with, like libev?

Plus: can you extend the connection-handler and add a custom implementation for the onError() method? Maybe there is some error that is not reported.

@akay25
Copy link
Author

akay25 commented Oct 13, 2021

I tried example code for libev as well and had the same result with cmake build. I have compiled the new library using make for now, but I can check and post results later along with onError method for connection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants