Search code examples
c++qtcodeblocksheader-files

Compiler cannot find .h files (code blocks)


I am trying to include a few libraries in code blocks, however when I add the path of the .h files to the search directory (example C:\Qt\5.1.1\mingw48_32\include\QtNetwork), it only seems to identify the ones in the main file and I think that is due to the fact that in the main file they are included as such (for example) #include "qtcpsocket.h", whereas in the .h file they are included as (for example) #include <QtNetwork/qabstractsocket.h>.

Apart from the fact that one includes the folder in which it is located, what is the major difference? Why it may not work? and what do it need to do to change it?

one more thing I'm sure the files are in the folder. Here are a few code snippets if this helps

location of file

error


Solution

  • If your source code contains, e.g.

    #include <QtNetwork/qabstractsocket.h>
    

    then you are requesting the preprocessor to find and include a file called

    QtNetwork/qabstractsocket.h
    

    (or, QtNetwork\qabstractsocket.h, if you're on Windows, as you are)

    in one of its search directories.

    And if you have specified compiler search directories:

    C:\Qt\5.5.1\mingw48_32\include\QtNetwork
    C:\Qt\5.5.1\mingw48_32\include\QtCore
    

    then the preprocessor will search the first directory for:

    C:\Qt\5.5.1\mingw48_32\include\QtNetwork\QtNetwork\qabstractsocket.h
    

    which does not exist. And it will search the second directory for:

    C:\Qt\5.5.1\mingw48_32\include\QtCore\QtNetwork\qabstractsocket.h
    

    which does not exist either.

    The usual way would be to specify the compiler search directory:

    C:\Qt\5.5.1\mingw48_32\include
    

    and in your code write your #include <...> directives like:

    #include <QtNetwork/...>
    #include <QtCore/...>