问题
I am running into a problem I have not been able to avoid. Redhat 6 (or most linux packages) comes with a default QT package installed with headers/etc in the /usr/lib and /usr/include folders.
Now, I am wanting to link against a newer version of QT without removing the older version. Unfortunately, since the headers are in the /include/ folder, gcc automatically finds them, and then uses the wrong include files (instead of those which I have elsewhere).
I cannot seem to stop the compiler from automatically doing this. I have gotten around it previously by simply manually removing the old libraries/headers but this is a terrible solution long term.
I do not think this problem is specific to QT either, it just happens to be my current instance of it.
Any suggestions?
Many thanks :)
回答1:
If you give the include directories of the newer Qt installation through -I
option, it should be searched before the standard include directories (i.e. /usr/include, etc.) Removing the standard include directories from the search path completely is likely not a good idea because standard headers will also be found there (note that the Qt headers themselves most likely include standard headers and will not work if those are not found).
However if you really don't want the standard include directories to be searched, the option -nostdinc
should do what you want.
回答2:
My issue turned out to be related to an incorrect version of qmake being used. It was finding a previous version of qmake, and even though it was from qt4, it was linking to the wrong includes.
Updating the qmake paths worked to fix this issue.
来源:https://stackoverflow.com/questions/8143829/how-to-exclude-usr-include-path-from-linux-application