2015-12-01 39 views
1

我下载了最新的独立版本Boost's Asio Library。现在我想将纯粹的头文件库整合到一个简单的qt creator C++项目中。但是,如果我尝试运行与asio.hpp的“Hello World”的例子包括我收到以下错误信息(参见下面的完整的错误消息):Asio C++ Library:asio/detail/config.hpp:没有这样的文件或目录

asio/detail/config.hpp: No such file or directory 

这是我花了这么远

步骤
  1. Qt Creator中创建了一个新的项目(C++与QMAKE)
  2. 提取的ASIO库
  3. 复制ASIO的包括和src文件夹到 “库” 目录在我的项目
:在C++ 11的pro文件指定应由

CONFIG + = C++ 11

  • 而且我试图添加以下定义在我的主要被用于

    #define ASIO_STANDALONE 
    #define ASIO_HAS_STD_ADDRESSOF 
    #define ASIO_HAS_STD_ARRAY 
    #define ASIO_HAS_CSTDINT 
    #define ASIO_HAS_STD_SHARED_PTR 
    #define ASIO_HAS_STD_TYPE_TRAITS 
    
    #include <iostream> 
    #include "libs/asio/include/asio.hpp" 
    
    using namespace std; 
    
    int main() 
    { 
        cout << "Hello World!" << endl; 
        return 0; 
    } 
    
    1. 看来qmake并不知道所有的包含。我不是很喜欢cmake,qmake和这个东西。因此,作为一个小白我尝试添加一个新的INCLUDEPATH在.pro文件...

      INCLUDEPATH + = ./libs/asio/include

    ...并得到了一个新的错误:

    boost/detail/atomic_count.hpp: No such file or directory 
    

    这是我的第一个错误完整的错误消息:

    make: Entering directory `/home/ubuntu/asiotest-build-desktop-Qt_4_8_1_in_PATH__System__Release' 
    /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ -o Makefile ../asiotest/asiotest.pro 
    make: Leaving directory `/home/ubuntu/asiotest-build-desktop-Qt_4_8_1_in_PATH__System__Release' 
    make: Entering directory `/home/ubuntu/asiotest-build-desktop-Qt_4_8_1_in_PATH__System__Release' 
    g++ -c -pipe -O2 -Wall -W -DQT_WEBKIT -I/usr/share/qt4/mkspecs/linux-g++ -I../asiotest -I../asiotest -I. -o main.o ../asiotest/main.cpp 
    In file included from ../asiotest/libs/asio/include/asio.hpp:18:0, 
           from ../asiotest/main.cpp:9: 
    ../asiotest/libs/asio/include/asio/async_result.hpp:18:34: fatal error: asio/detail/config.hpp: No such file or directory 
    compilation terminated. 
    make: Leaving directory `/home/ubuntu/asiotest-build-desktop-Qt_4_8_1_in_PATH__System__Release' 
    make: *** [main.o] Error 1 
    17:55:01: The process "/usr/bin/make" exited with code 2. 
    Error while building project asiotest (target: Desktop) 
    When executing build step 'Make' 
    

    文件hierarchie:

    asiotest (project folder) 
    -- asiotest.pro 
    -- sources (folder) 
    ---- main.cpp 
    -- libs (folder) 
    ---- asio (folder) 
    ------- include(folder) 
    ---------- asio.hpp 
    ---------- asio (folder) 
    ------------- detail (folder) 
    ------------- more folders 
    ------- src 
    ---------- asio.cpp 
    ---------- asio_ssl.cpp 
    

    如何让qt在正确的目录中搜索包含文件?

    注意:对于源代码的引用抱歉,但我没有设法通过使用源代码“tag”简单地在代码列表中突出显示代码。

  • 回答

    1

    也许这对未来的这个问题的访问者会有帮助。我设法解决了这个问题。我甚至获得了运行asio的http服务器示例。同时也从ubuntu切换到debian,从qmake切换到cmake,但我不认为这是最终的原因。下面的CMakeLists.txt对我的作品:

    project(asiotest) 
    cmake_minimum_required(VERSION 2.8) 
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DASIO_STANDALONE -pthread") 
    aux_source_directory(. SRC_LIST) 
    include_directories(asio/include) 
    add_executable(${PROJECT_NAME} ${SRC_LIST}) 
    

    注意-pthread选项。没有它,我得到了很多链接器错误。另见here。 文件夹结构与之前几乎相同:

    asiotest (project folder) 
    -- [..source files of http server example..] 
    -- libs (folder) 
    ---- asio (folder) 
    ------- include(folder) 
    ---------- asio.hpp 
    ---------- asio (folder) 
    ------------- detail (folder) 
    ------------- more folders 
    ------- src 
    ---------- asio.cpp 
    ---------- asio_ssl.cpp 
    
    相关问题