我下载了最新的独立版Boost's Asio Library . 现在我想在一个简单的qt creator c项目中集成只有头文件库 . 但是,如果我尝试运行包含asio.hpp的"hello world"示例,我会收到以下错误消息(请参阅下面的完整错误消息):
asio/detail/config.hpp: No such file or directory
这是我到目前为止采取的步骤
-
在qt creator中创建了一个新项目(c with qmake)
-
提取了asio库
-
将asio的include和src文件夹复制到项目的"libs"目录中
.pro文件中指定的 -
应该使用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;
返回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
How can I teach qt to search for the include files in the right directory?
注意:对于源代码周围的引用感到抱歉,但我没有通过简单的源代码“tag”设法在编号列表中突出显示代码 .
1 回答
也许这对这个问题的未来访问者有所帮助 . 我设法解决了这个问题 . 我甚至得到了asio运行的http服务器示例 . 同时也从ubuntu切换到debian,从qmake切换到cmake,但我认为这不是最终的原因 . 以下CMakeLists.txt适合我:
Note the -pthread option . 没有它我遇到了很多链接器错误 . 另见here . 文件夹结构与以前几乎相同: