mercredi 29 juin 2016

error when runing .cpp file in terminal using g++

I trying RabbitMQ + C++. Working on linux ubuntu 16.04. Have working code and when I compile using CLion all works fine. I have peace of code what I need to run with root, so I need to run it using g++.

ERROR FROM TERMINAL

In function `main':
receiveUNPW.cpp:(.text+0x8e8): undefined reference to `SimplePocoHandler::SimplePocoHandler(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned short)'
receiveUNPW.cpp:(.text+0xc9c): undefined reference to `SimplePocoHandler::loop()'
receiveUNPW.cpp:(.text+0xcce): undefined reference to `SimplePocoHandler::~SimplePocoHandler()'
receiveUNPW.cpp:(.text+0xea7): undefined reference to `SimplePocoHandler::~SimplePocoHandler()'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../../lib/libamqpcpp.so: undefined reference to `pthread_create'

I write :

g++ -std=c++11 receiveUNPW.cpp -o receiveUNPW -lcrypt -lPocoNet -lPocoFoundation -lamqpcpp 

CMakeList.txt

cmake_minimum_required(VERSION 3.5)
project(test)

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

add_library(poco_simple_handler SimplePocoHandler.cpp SimplePocoHandler.h)
target_link_libraries(poco_simple_handler PocoNet PocoFoundation crypt )

set(PROGS
        sendUNPW
        receiveUNPW
        )

foreach(item ${PROGS})
    add_executable(${item} "${item}.cpp")
    target_link_libraries(${item} amqpcpp poco_simple_handler PocoNet PocoFoundation crypt)
endforeach(item)

MY IDEA

As can see when I use g++ it can't find reference to SimplePocoHandler. In CmakeList.txt i have

add_library(poco_simple_handler SimplePocoHandler.cpp SimplePocoHandler.h)
target_link_libraries(poco_simple_handler PocoNet PocoFoundation crypt )

so when I compile in CLion all works fine. So seems I need to do the same when I using g++. But I don't know how to do it, any suggestions or explanations would be great.

I don't share my receiveUNPW.cpp code, but it's almost similar to that receiver.cpp what you can see there and also I don't have any error there, in CLion all works fine, I just need to run my program using terminal with root permissions.

Aucun commentaire:

Enregistrer un commentaire