我下载了Boost's Asio Library的最新独立版本。现在我想在一个简单的qt creator c ++项目中集成只有头文件库。但是,如果我试图运行"你好世界"包含asio.hpp的示例我收到以下错误消息(请参阅下面的完整错误消息):
asio/detail/config.hpp: No such file or directory
这是我到目前为止采取的步骤
应该使用c ++ 11
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; }
似乎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'
文件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在正确的目录中搜索包含文件?
注意:对于源代码周围的引用感到抱歉,但我没有通过简单的源代码&#34;标记&#34;设法使编号列表中的代码突出显示。
答案 0 :(得分: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