在C ++项目中包含Pistache

wma*_*ash 6 c++ cmake

很抱歉,这是一个非常菜鸟的问题,但是我对C ++还是很陌生。

我正在使用pistache构建RESTful服务。我已经检查了一下,并在项目本身中运行了示例,但现在尝试导入/包括要在我自己的项目中使用的框架。

我的文件夹结构如下:

rest_api
   |
   +--- build
   +--- include
          |
          +--- pistache
   +--- src
          |
          +--- main.cpp
   +--- tests
Run Code Online (Sandbox Code Playgroud)

pistache目录包含所有已编译的pistache源代码。 (我不确定这里是否需要整个项目或仅需要头文件)

我试图按照示例快速入门指南进行操作,但是没有看。

我的CMakeLists.txt是准系统,目前看起来像这样:

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)
Run Code Online (Sandbox Code Playgroud)

我的main.cpp是他们的示例hello_server.cc的直接副本。

当我尝试和make我的项目时,返回的是异常(快照)

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&)'
Run Code Online (Sandbox Code Playgroud)

我已经看过了问题,比如这个,但并不能帮助我。

我的问题是:

  1. 我是否需要整个Pistache源代码或仅标头?
  2. 我的CMakeLists.txt中出了什么问题导致这些错误?

抱歉,如果这被视为重复但未能找到我需要的正确答案。

谢谢!

tio*_*rez 5

这是我的CMakeLists.txt文件。工作正常: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})
Run Code Online (Sandbox Code Playgroud)


归档时间:

查看次数:

1482 次

最近记录:

6 年,11 月 前