Reputation: 1313
I am actually imroving my c++ skills with a project that uses PocoProject as a framework for supplying a simple rest webserver and json parsing as well as a mongodb driver.
I am compiling my project with cmake/make
my directory structure is:
root
- pocoproject
- helloworld.cpp
- CMakeLists.txt
To test cmake, I have a simple cpp file (taken from the poco examples) that starts a http-server. the includes are the following:
#include "Poco/Net/HTTPServer.h"
#include "Poco/Net/HTTPRequestHandler.h"
...
#include "Poco/Util/HelpFormatter.h"
#include <iostream>
My CMakeLists.txt look like:
cmake_minimum_required (VERSION 2.6)
project (Hello)
add_executable(Hello helloworld.cpp)
How do I add the needed libraries from pocoproject to to my executable? How do I reference the headers correctly?
Upvotes: 2
Views: 2447
Reputation: 7799
You need let your CMake project know where to look for the dependencies, such as Poco. You need to set the variable CMAKE_PREFIX_PATH
. It can be done with cmake-gui
or on the command line:
cmake ... -DCMAKE_PREFIX_PATH=<path> ...
The <path>
is where you copied or installed the Poco library, so the Poco headers will have paths like <path>/include/Poco/AbstractCache.h
, etc..., libraries like <path>/lib/libPocoFoundation.*
and most importantly, the config-module must be found at <path>/lib/cmake/Poco/PocoConfig.cmake
.
In your CMakeLists.txt
you need to find the Poco package with
find_package(Poco REQUIRED Foundation Util Net)
and link to it with
target_link_libraries(Hello Poco::Foundation Poco::Util Poco::Net)
Upvotes: 3