Hello, I am new to CodeBlocks and C++.
I am trying out QT5 (on Ubuntu) following https://zetcode.com/gui/qt5/introduction/ (https://zetcode.com/gui/qt5/introduction/) and can't figure out how to point CodeBlocks to the header files.
#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.
#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?
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.
#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.
Build log:
-------------- 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:
<?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::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),
Remove this paths from the compiler search directories and global compiler search directories from all targets:
/usr/lib/x86_64-linux-gnu/qt5
/usr/lib/qt5
/usr/share/qt5
and add only this (and only to the project build options):
/usr/include/x86_64-linux-gnu/qt5
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.
-------------- 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))
<?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.
Can you spot the difference between what I said and what you wrote?
Me: /usr/include/x86_64-linux-gnu/qt5
You: /usr/lib/x86_64-linux-gnu/qt5