Author Topic: Codeblocks cant find include files  (Read 9216 times)

Offline LeslieS

  • Single posting newcomer
  • *
  • Posts: 8
Codeblocks cant find include files
« on: February 21, 2022, 06:53:38 am »
Hello, I am new to CodeBlocks and C++. 

I am trying out QT5 (on Ubuntu) following https://zetcode.com/gui/qt5/introduction/ and can't figure out how to point CodeBlocks to the header files.   
Code
#include <QtCore>
#include <iostream>

int main() {
   
    std::cout << "Qt version: " << qVersion() << std::endl;
}
I get "no such file or directory" on the #include <QtCore> line.
If I type it in manually CodeBlocks auto completes the include and I can see many QT headers available such as QVersionNumber
When I try to run this code the header file named in qversionnumber.h  "<QtCore/qnamespace.h>" is not found.
Code
#include <qt5/QtCore/QVersionNumber>
int main() {
    return 0;
}

   
I used "whereis qt5" and added all (3) the directories to link libraries and to search directories but it didn't fix the issue.   
I know I am missing something. 
How do I get CodeBlocks to see these headers?



Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Codeblocks cant find include files
« Reply #1 on: February 21, 2022, 07:16:24 am »
1. Either:
  •    A) Right Click on your project in the Management window and select the "Build Options..."
  •     B) In the Project menu select the "Build Options..."
2.Then click on the "Search directories" tab
3. In the Compiler Tab add the directory where the includes files are.

If you get stuck have a look at the following page:http://www.kerrywong.com/2008/07/12/codeblocks-settings-for-qt-development/

Offline LeslieS

  • Single posting newcomer
  • *
  • Posts: 8
Re: Codeblocks cant find include files
« Reply #2 on: February 21, 2022, 09:02:49 am »
I follow your directions and add the QT directories to the compiler tab of search directories and the same problem persists. 
No such file or directory. 
 
 
« Last Edit: February 21, 2022, 09:31:39 am by LeslieS »

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Codeblocks cant find include files
« Reply #3 on: February 21, 2022, 09:18:08 am »
Sound like you should be using the "File->New Project" menu to create a project as C::B uses projects to build "things" (DLL, Plugins, exe etc) and then projects can be combined into workspaces. I would suggest having a quick/skim read of the C::B manual, even though it is IMHO missing allot of bits it is better then nothing. The manual is not currently included in the Linux release, but is available from the following page:
https://www.codeblocks.org/user-manual/
If you ever do any wxWidget work then the C::B manual is IMHO for C:B & wxwidget is available from https://github.com/PBfordev/wxpbguide.You can use SDL2 in QT as well if you want, but unfortunately there is no manual for this and I cannot remember where I found the relevant info.

Offline LeslieS

  • Single posting newcomer
  • *
  • Posts: 8
Re: Codeblocks cant find include files
« Reply #4 on: February 21, 2022, 09:32:23 am »
Unfortunately I spoke too soon.   
I did create a project and tried your solution but it doesn't work for me.     
I can get this to run because their is no dependancies in the header file.
Code
#include <qt5/QtCore/QtCoreVersion>
//#include <qt5/QtCore/QVersionNumber>
#include <iostream>
int main() {
    std::cout << QTCORE_VERSION_STR;

}
 
But as soon as a header file has an include then it is not found.   
I think it has something to do with the fact that the header files are prefixed with qt5 whereas the dependant files don't have the prefix.   
« Last Edit: February 21, 2022, 09:42:39 am by LeslieS »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Codeblocks cant find include files
« Reply #5 on: February 21, 2022, 09:49:27 am »
Post a full rebuild log, see this link

Offline AndrewCot

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 678
Re: Codeblocks cant find include files
« Reply #6 on: February 21, 2022, 11:49:07 am »
LeslieS, Can you please also upload the project CBP file as well as the log.

Offline LeslieS

  • Single posting newcomer
  • *
  • Posts: 8
Re: Codeblocks cant find include files
« Reply #7 on: February 21, 2022, 05:32:57 pm »
Build log:
Code
-------------- Build: Debug in sss (compiler: GNU GCC Compiler)---------------

g++ -Wall -g -I/usr/lib/x86_64-linux-gnu/qt5 -I/usr/lib/qt5 -I/usr/share/qt5 -I/usr/lib/x86_64-linux-gnu/qt5 -I/usr/lib/qt5 -I/usr/share/qt5 -c /home/noone/new.cpp -o obj/Debug/new.o
g++  -o bin/Debug/sss obj/Debug/new.o   
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVersionNumber:1,
                 from /home/noone/new.cpp:2:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qversionnumber.h:45:10: fatal error: QtCore/qnamespace.h: No such file or directory
   45 | #include <QtCore/qnamespace.h>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 
cbp:
Code
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="sss" />
<Option execution_dir="." />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/sss" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add directory="/usr/lib/x86_64-linux-gnu/qt5" />
<Add directory="/usr/lib/qt5" />
<Add directory="/usr/share/qt5" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/sss" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="new.cpp" />
<Extensions />
</Project>
</CodeBlocks_project_file>
   
 
Note that the compiler options mentioned in the faq are not found in the compiler settings (at least not in that I could find). In fact I couldn't find those options anywhere. 
Code
Code::Blocks version, compiler log (go to Settings->Compiler and debugger...->Build options (tab) and check Save build log and Always output the full command line),

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Codeblocks cant find include files
« Reply #8 on: February 21, 2022, 05:46:35 pm »
Remove this paths from the compiler search directories and global compiler search directories from all targets:
Code
/usr/lib/x86_64-linux-gnu/qt5
/usr/lib/qt5
/usr/share/qt5
and add only this (and only to the project build options):
Code
/usr/include/x86_64-linux-gnu/qt5

Offline LeslieS

  • Single posting newcomer
  • *
  • Posts: 8
Re: Codeblocks cant find include files
« Reply #9 on: February 21, 2022, 07:04:44 pm »
If I did it correctly it seems to be the same result.
Using the menu options to change the settings didn't actually change the cbp file. 
I had to go in and manually remove the items from it using a text editor I am not 100% sure I got it right.       
Code
-------------- Build: Debug in sss (compiler: GNU GCC Compiler)---------------

g++ -Wall -g -I/usr/lib/x86_64-linux-gnu/qt5 -c /home/noone/new.cpp -o obj/Debug/new.o
g++  -o bin/Debug/sss obj/Debug/new.o   
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/QVersionNumber:1,
                 from /home/noone/new.cpp:2:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qversionnumber.h:45:10: fatal error: QtCore/qnamespace.h: No such file or directory
   45 | #include <QtCore/qnamespace.h>
      |          ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 
 
   
Code
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="sss" />
<Option execution_dir="." />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/sss" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add directory="/usr/lib/x86_64-linux-gnu/qt5" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/sss" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="new.cpp" />
<Extensions />
</Project>
</CodeBlocks_project_file>
I also tried to start a new project but have run into some strangeness there too. It is endlessly looping "It seems that this project has not been built yet. Do you want to build it now?". Selecting yes just brings this up again.   
Selecting no brings up a window "sh: 1: /home/noone/bin/debug/test2: file not found".     

I think that maybe CodeBlocks is geared towards people who are already quite familiar with the intricacies of C/C++ compiling.   
It could be that there is too much I don't know.   

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1553
Re: Codeblocks cant find include files
« Reply #10 on: February 21, 2022, 07:10:14 pm »
Can you spot the difference between what I said and what you wrote?
Code
Me:  /usr/include/x86_64-linux-gnu/qt5
You: /usr/lib/x86_64-linux-gnu/qt5

Offline LeslieS

  • Single posting newcomer
  • *
  • Posts: 8
Re: Codeblocks cant find include files
« Reply #11 on: February 21, 2022, 08:03:25 pm »
I see it now. That change worked. 
There is now a brand new set of errors. Lol. But for sure it can see the directory now.   

I can't run the examples from the web site in post 1 because it won't accept any of the includes directly (ex #include <QtCore>.   
At this point in time I need things to be simple. 

I can run the examples from the web site in post 1 without errors using the qmake/make system. 
Unfortunately that means using a text editor with no code completion but it has to be this route for me. 

Once I get to know the nuances of compiling and Qt I will have a better idea of how to approach your ide. 
I'll come back to it then.
I have taken enough of your time. Thank you for the help.