4

I have downloaded the latest Poco library poco-1.7.3.tar. Configured with few properties and did make install. Tried the following sample helloworld program.

#include <iostream>
#include <Poco/Util/Application.h>

class HelloPocoApplication : public Poco::Util::Application
{
protected:
    virtual int main(const std::vector<std::string> &args)
    {
            std::cout << "Hello, POCO C++ Libraries!" << std::endl;

            return EXIT_OK;
    }
};
POCO_APP_MAIN(HelloPocoApplication);

Compiled it using

g++ -I poco-1.7.3/Util/include -I poco-1.7.3/XML/include -I poco-1.7.3/JSON/include -I poco-1.7.3/Foundation/include -L poco-1.7.3/lib/Linux/x86_64 -lPocoUtil -lPocoFoundation -lPocoXML -lPocoJSON helloworld.cpp -o prog

But it is throwing following errors

 /tmp/ccFvl4ll.o: In function `main':
 helloworld.cpp:(.text+0x4f): undefined reference to     `Poco::Util::Application::init(int, char**)'
      helloworld.cpp:(.text+0xd9): undefined reference to    `Poco::Logger::log(Poco::Exception const&)'
    /tmp/ccFvl4ll.o: In function `Poco::RefCountedObject::release() const':
    helloworld.cpp:(.text._ZNK4Poco16RefCountedObject7releaseEv[_ZNK4Poco16RefCountedObject7releaseEv]+0x6e): undefined reference to `Poco::Bugcheck::unexpected(char const*, int)'
    /tmp/ccFvl4ll.o: In function `Poco::Util::Application::logger() const':
    helloworld.cpp:(.text._ZNK4Poco4Util11Application6loggerEv[_ZNK4Poco4Util11Application6loggerEv]+0x2c): undefined reference to `Poco::Bugcheck::nullPointer(char const*, char const*, int)'
    /tmp/ccFvl4ll.o: In function `HelloPocoApplication::HelloPocoApplication()':
    helloworld.cpp:(.text._ZN20HelloPocoApplicationC2Ev[_ZN20HelloPocoApplicationC5Ev]+0x14): undefined reference to `Poco::Util::Application::Application()'
    /tmp/ccFvl4ll.o:(.gcc_except_table+0x2c): undefined reference to `typeinfo for Poco::Exception'
    /tmp/ccFvl4ll.o: In function `Poco::AutoPtr<HelloPocoApplication>::operator->()':
    helloworld.cpp:(.text._ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv[_ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv]+0x3a): undefined reference to `Poco::NullPointerException::NullPointerException(int)'
    helloworld.cpp:(.text._ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv[_ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv]+0x3f): undefined reference to `Poco::NullPointerException::~NullPointerException()'
    helloworld.cpp:(.text._ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv[_ZN4Poco7AutoPtrI20HelloPocoApplicationEptEv]+0x44): undefined reference to `typeinfo for Poco::NullPointerException'
    /tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x20): undefined reference to `Poco::Util::Application::name() const'
    /tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x28): undefined reference to `Poco::Util::Application::initialize(Poco::Util::Application&)'
    /tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x30): undefined reference to `Poco::Util::Application::uninitialize()'
    /tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x38): undefined reference to `Poco::Util::Application::reinitialize(Poco::Util::Application&)'
    /tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x40): undefined reference to `Poco::Util::Application::defineOptions(Poco::Util::OptionSet&)'
    /tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x48): undefined reference to `Poco::Util::Application::run()'
    /tmp/ccFvl4ll.o:(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x50): undefined reference to `Poco::Util::Application::handleOption(std::string const&, std::string const&)'
    /tmp/ccFvl4ll.o: In function `HelloPocoApplication::~HelloPocoApplication()':
    helloworld.cpp:(.text._ZN20HelloPocoApplicationD2Ev[_ZN20HelloPocoApplicationD5Ev]+0x1f): undefined reference to `Poco::Util::Application::~Application()'
    /tmp/ccFvl4ll.o:(.rodata._ZTI20HelloPocoApplication[_ZTI20HelloPocoApplication]+0x10): undefined reference to `typeinfo for Poco::Util::Application'
    collect2: error: ld returned 1 exit status

Can you please help me?

Kranthi
  • 195
  • 3
  • 13

4 Answers4

3

I managed to run exactly that code but using CMake rather than Makefile and it worked. you have just to change the paths according to your machine.

Here's my CMakeLists.txt :

cmake_minimum_required(VERSION 2.8.3)
project(tutocpp14)

set(Poco_DIR "/usr/local/lib/cmake/Poco/") 
set(Poco_INCLUDE_DIRS "/usr/include/Poco/")

find_package(Poco REQUIRED COMPONENTS Foundation Net XML Util) # add other components here

# check c++11 / c++0x
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11 " COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
    set(CMAKE_CXX_FLAGS "-std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
    set(CMAKE_CXX_FLAGS "-std=c++0x")
else()
    message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()

include_directories( ${Poco_INCLUDE_DIRS}) 

add_executable(publisher src/publisher.cpp)
target_link_libraries(publisher ${Poco_LIBRARIES}) 

Cheers,

Vtik
  • 3,073
  • 2
  • 23
  • 38
0

Checking with Poco documents it seems it should work. Looking at an example here, and its makefile, I suspect the order of your library is reversed. Assuming that paths are correct (since ld didn't report on that) I would say that linking order is incorrect. See here Why. So I suggest you change your command to

g++ -I poco-1.7.3/Util/include -I poco-1.7.3/Foundation/include -L poco-1.7.3/lib/Linux/x86_64 -lPocoFoundation -lPocoUtil helloworld.cpp -o prog

in case those examples goes out of scope somehow in future, here is the code and makefile copied.

#include <iostream>
#include <Poco/Util/Application.h>

class HelloPocoApplication : public Poco::Util::Application
{
protected:
    virtual int main(const std::vector<std::string> &args)
    {
        std::cout << "Hello, POCO C++ Libraries!" << std::endl;

        return EXIT_OK;
    }
};

POCO_APP_MAIN(HelloPocoApplication);

Note: Remember to restore the tabs instead of spaces in makefile code!

POCO_LIBS=-lPocoFoundation -lPocoUtil

all: hello-poco

clean:
    rm -f hello-poco

hello-poco: hello-poco.cpp
    $(CXX) $(POCO_LIBS) -o hello-poco hello-poco.cpp

Update:

With all above said, I have to put a note on strangeness of your error especially Poco::Logger which is found in foundation library. So it seems that library does not get linked. I would suggest two things: 1. Check if its not corrupted. You can do that by cleaning and recompiling 2. Try to install in standard path so that you avoid linking paths

I know all these are not definitive (guess works at best) but will be useful to provide you hints of where the issue lies.

Community
  • 1
  • 1
Stefano Mtangoo
  • 6,017
  • 6
  • 47
  • 93
  • Thanks for the reply. First method of changing order of linking reported the same issue. – Kranthi May 20 '16 at 11:36
  • Second method: From where the program can pick the included files like Application.h. It is reporting the obvious error as follows. **'$ make' g++ -lPocoFoundation -lPocoUtil -o hello-poco hello-poco.cpp hello-poco.cpp:2:35: fatal error: Poco/Util/Application.h: No such file or directory #include ^ compilation terminated. make: *** [hello-poco] Error 1** – Kranthi May 20 '16 at 11:37
  • looking at samples make I don't see anything peculiar than two additional libraries. See it here. https://github.com/pocoproject/poco/blob/develop/Util/samples/SampleApp/Makefile Can you compile samples and see if they run correct? – Stefano Mtangoo May 20 '16 at 11:48
0

Your original library linking order was fine, but you are missing XML and JSON (Util depends on these libraries). Although, the link errors you've got indicate that you may be either missing Foundation library or mixing library versions.

$ echo $POCO_BASE
/tmp/poco
$ pwd
/tmp/poco/test
$ g++ -I $POCO_BASE/Util/include -I $POCO_BASE/Foundation/include -L $POCO_BASE/lib/Linux/x86_64 -lPocoUtil -lPocoXML -lPocoJSON -lPocoFoundation helloworld.cpp -o prog
Alex
  • 5,159
  • 4
  • 25
  • 33
  • It reduced the errors. But still reporting following issues. **/tmp/ccjBEy6m.o: In function `main': helloworld.cpp:(.text+0x4f): undefined reference to `Poco::Util::Application::init(int, char**)' helloworld.cpp:(.text+0xd9): undefined reference to `Poco::Logger::log(Poco::Exception const&)' /tmp/ccjBEy6m.o: In function `Poco::RefCountedObject::release() const': helloworld.cpp:(.text._ZNK4Poco16RefCountedObject7releaseEv[_ZNK4Poco16RefCou(.rodata._ZTV20HelloPocoApplication[_ZTV20HelloPocoApplication]+0x collect2: error: ld returned 1 exit status** – Kranthi May 23 '16 at 05:07
  • You are either (a) missing poco libraries, or (b) linking your application with different standard library than the one with which poco libraries are linked – Alex May 24 '16 at 00:33
0

try this command to compile.

g++ <src_file>.cpp -lPocoFoundation -lPocoJSON -lPocoUtil -lPocoJWT -o <binary_name>

Rajeev
  • 147
  • 1
  • 1
  • 17