构建Wt项目时出错。无法打开包含文件:'boost / any.hpp'

时间:2012-07-31 14:12:50

标签: c++ boost cmake wt

Wt v.3.2.2和boost库v.1.47已成功安装在我的计算机中,并且在安装过程中没有发生错误。在测试过程中编译并正确运行了一些简单的Wt和Boost示例。我使用为MSVC 2008配置的CMake为我自己的Wt项目创建构建文件。

然而,当我尝试构建自己的项目时,我收到此错误(无法打开包含文件:'boost / any.hpp')。正如我所见,boost / any.hpp包含在Wt / WApplication头文件中。

要获得进一步的帮助,我的CMakeLists.txt文件内容是: CMakeLists.txt放在项目目录中:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT(WT_EXAMPLE)

SET (WT_CONNECTOR "wthttp" CACHE STRING "Connector used (wthttp or wtfcgi)")

ADD_SUBDIRECTORY(source)

CMakeLists.txt放在源目录中:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

SET(WT_INSTALL_DIR "C:/Program Files/WT/boost_1_47")
SET(BOOST_INSTALL_DIR "C:/Program Files/boost")

ADD_EXECUTABLE(
 GOP.wt
 Main.C
)

SET(WT_LIBS
 optimized wthttp debug wthttpd
 optimized wt debug wtd)

SET(BOOST_LIBS
 boost_signals boost_regex boost_thread boost_filesystem boost_system
 boost_random boost_date_time boost_program_options)

TARGET_LINK_LIBRARIES (
 GOP.wt
 ${WT_LIBS} ${BOOST_LIBS} ${SYSTEM_LIBS}
)

LINK_DIRECTORIES (
 ${WT_INSTALL_DIR}/lib/
 ${BOOST_INSTALL_DIR}/lib/
)

INCLUDE_DIRECTORIES(${WT_INSTALL_DIR}/include)
INCLUDE_DIRECTORIES(${BOOST_INSTALL_DIR}/include)

正如我在Wt构建目录中的CMakeCache.txt中看到的那样,找到了提升库的路径,但是......这条线怎么样?

//The directory containing a CMake configuration file for Boost.
Boost_DIR:PATH=Boost_DIR-NOTFOUND

我在Wt支持论坛上问了这个问题,但是大约24小时我没有得到答案......

更新:我发现any.hpp位于C:\ Program Files \ boost \ boost_1_47 \ boost \ spirit \ home \ support \ algorithm \ any.hpp。因此,我怀疑搜索any.hpp的路径有一个概念(它不直接包含在boost目录中)。

2 个答案:

答案 0 :(得分:1)

问题解决了。我做了一个新的Wt构建,我在一条新路径中放置并重建了boost,我为这个项目编写了CMakeLists ,更加谨慎

答案 1 :(得分:0)

包含

例如

#include <boost/any.hpp>
#include <iostream>
#include <vector>
#include <string>

int main() {
    std::vector<boost::any> some_values;

    some_values.push_back(10);
    const char* c_str = "Hello there!";
    some_values.push_back(c_str);
    some_values.push_back(std::string("Wow!"));

    std::string& s = boost::any_cast<std::string&>(some_values.back());
    s += " That is great!\n";
    std::cout << s;
}

我们只需要一个简单的cmake文件

# Defines AppBase library target.
project(recipe_01)
cmake_minimum_required(VERSION 3.5)

include(GNUInstallDirs)

set(CMAKE_EXPORT_COMPILE_COMMANDS "ON")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})

if(CMAKE_CXX_STANDARD EQUAL 98 OR CMAKE_CXX_STANDARD LESS 14)
   message(FATAL_ERROR "app requires c++14 or newer")
elseif(NOT CMAKE_CXX_STANDARD)
   set(CMAKE_CXX_STANDARD 14)
   set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()

find_package(Boost 1.60 REQUIRED)

add_executable(main main.cpp)

target_link_libraries(main)