开发者

How to make the visual studio 2008 IDE look at the right place for header files. Compiling Qt/C++ program

开发者 https://www.devze.com 2023-03-16 14:17 出处:网络
I am building an app on Qt 4.6.2 using visual studio 2008. I need to include the header <QtGui\\QDir>.

I am building an app on Qt 4.6.2 using visual studio 2008. I need to include the header <QtGui\QDir>.

Problem : The QDir header includes several headers. Once of them is qfile.h. Now the ide/compiler is unable to include this file and the error I get is this

c:\devprojects\myprojects\nttoolkit\trunk\external\qt\include\qtcore../../src/corelib/io/qfile.h(45) : fatal error C1083: Cannot open include file: 'Qt/include/QtCore/qiodevice.h': No such file or directory

I cannot change开发者_Python百科 the path in the file qfile.h since it is an external file to my project. How do I get it working.

Thanks.


The various places the preprocessor searches for include files is described in the Remarks section here.

Typically for an "SDK" like Qt people will change their VC++ Directories, Projects, Options under Tools | Options | "Projects and Solutions" | "VC++ Directories" so that the Include Files and Library Files lists include suitable Qt directories. That way, when the preprocessor searches for Qt include files, it will look in the right places and when the linker looks for .LIB files it will find them also.

One downside to changing those lists is that they apply to all projects built from that version of Visual Studio. That can be a pain in the neck if you have different projects that use different versions of an SDK. In those sorts of situations one solution is to create environment variables called INCLUDE and LIBPATH and then launch devenv with the /useenv switch to override the VC++ Directories settings from Tools | Options.

Finally, a third option is to provide the additional include and library folders via the project properties. In Project | Properties | C++ | General the first property is "Additional Include Directories". Values placed there are passed to the preprocessor via the /I switch. Similarly the Project | Properties | Linker | General tab has an "Additional Library Directories" property which gets passed to the linker via the /LIBPATH switch.

This third option seems attractive because it lets you set these additional directories on a project by project basis. The downside is that it "hard-codes" some directory names in the project. That can be a real pain if you move the project to a new machine where the Qt files are in a different directory or when you have to move the Qt directories to a different hard-drive, etc.


In VS2010, I go to:

Project Properties -> VC++ Directories -> Include Directories

And set the location of directories containing headers I need to include. I don't currently have access to a VS2008 install, but I think there is a similar configuration option available.

0

精彩评论

暂无评论...
验证码 换一张
取 消