【问题标题】:Asio C++ Library: asio/detail/config.hpp: No such file or directoryAsio C++ 库:asio/detail/config.hpp:没有这样的文件或目录
【发布时间】:2016-03-05 18:11:00
【问题描述】:

我下载了最新的独立版Boost's Asio Library。现在我想将仅包含标头的库集成到一个简单的 qt creator c++ 项目中。但是,如果我尝试运行包含 asio.hpp 的“hello world”示例,我会收到以下错误消息(完整错误消息见下文):

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

这些是我到目前为止采取的步骤

  1. 在 qt creator 中创建了一个新项目(c++ with qmake)
  2. 提取了 asio 库
  3. 将asio的include和src文件夹复制到我项目中的“libs”目录中
  4. 在.pro文件中指定c++11应该被使用

    配置 += c++11

  5. 此外,我尝试在我的 main 中添加以下定义:

 #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 和这些东西不是很熟悉。所以作为一个菜鸟,我尝试在 .pro 文件中添加一个新的 INCLUDEPATH ...

    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'

文件层次结构:

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 在正确的目录中搜索包含文件?

注意:很抱歉引用源代码,但我没有设法通过简单地使用源代码“标签”在编号列表中突出显示代码。

【问题讨论】:

    标签: c++ qt boost-asio qmake


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-22
      • 1970-01-01
      • 2021-06-24
      • 2016-03-29
      相关资源
      最近更新 更多