Apologies for the fact this is a very noob question but I am fairly new to C++.
I'm building a RESTful service with pistache. I have checked it out and got the examples running within the project itself but am now trying to import/include the framework to use in my own project.
My folder structure is as follows:
rest_api
|
+--- build
+--- include
|
+--- pistache
+--- src
|
+--- main.cpp
+--- tests
The pistache
directory holds all of the pistache source code compiled.
(I am unsure here if I need the entirety of the project or just the header files)
I have attempted to follow the example and the quickstart guide but have had no look.
My CMakeLists.txt is barebones currently looking like this:
cmake_minimum_required(VERSION 3.5.1)
project(rest_api)
set(CMAKE_CXX_STANDARD 14)
set(PISTACHE_DIR "./include/pistache")
include_directories (${PISTACHE_DIR}/include)
add_executable(${PROJECT_NAME} src/main.cpp)
My main.cpp is a direct copy of their example hello_server.cc.
When I try and make
my project, I am returned with the exceptions (a snapshot of):
main.cpp:(.text+0x143): undefined reference to `Pistache::Port::Port(unsigned short)'
main.cpp:(.text+0x148): undefined reference to `Pistache::Ipv4::any()'
main.cpp:(.text+0x162): undefined reference to `Pistache::Address::Address(Pistache::Ipv4, Pistache::Port)'
main.cpp:(.text+0x171): undefined reference to `Pistache::Http::Endpoint::options()'
main.cpp:(.text+0x185): undefined reference to `Pistache::Http::Endpoint::Options::threads(int)'
main.cpp:(.text+0x1c9): undefined reference to `Pistache::Http::Endpoint::Endpoint(Pistache::Address const&)'
main.cpp:(.text+0x1e2): undefined reference to `Pistache::Http::Endpoint::init(Pistache::Http::Endpoint::Options const&)'
main.cpp:(.text+0x223): undefined reference to `Pistache::Http::Endpoint::setHandler(std::shared_ptr<Pistache::Http::Handler> const&)'
I have looked at questions such as this but does not help me.
My questions are:
Apologies if this is seen as a duplicate but have not been able to find the right answers I need.
Thank you!
This my CMakeLists.txt file. Works fine :D
cmake_minimum_required(VERSION 3.12)
project(PistacheExample)
set(CMAKE_CXX_STANDARD 11)
############################
## SOURCE FILES ##
############################
add_executable(${PROJECT_NAME} src/main.cpp)
#####################################
## HEADERS SEARCH PATHS ##
#####################################
set(PROJECT_INCLUDE_DIR "src/include")
set(PISTACHE_INCLUDE_DIR "libs/pistache/include")
set(HEADER_SEARCH_PATHS ${PROJECT_INCLUDE_DIR} ${PISTACHE_INCLUDE_DIR})
#####################################
## LIBRARY SEARCH PATHS ##
#####################################
set(PISTACHE_LIBRARY "${PROJECT_SOURCE_DIR}/libs/pistache/lib/libpistache.a")
set(EXTRA_LIBRARY "-pthread -lssl")
set(LIBRARIES_SEARCH_PATHS ${PISTACHE_LIBRARY} ${EXTRA_LIBRARY})
#######################################
## ADDING HEADERS LIBRARY ##
#######################################
include_directories(${HEADER_SEARCH_PATHS})
target_link_libraries(${PROJECT_NAME} ${LIBRARIES_SEARCH_PATHS})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With