I am learning Coin3D and hence running an example C++ program that uses SoQt.h library: #include <Inventor/Qt/SoQt.h>
That's when I am getting this error:
In file included from /home/xxx/Playground/Coin3D/hello_cone.cpp:1:
/usr/local/include/Inventor/Qt/SoQt.h:48:10: fatal error: qobject.h: No such file or directory
48 | #include <qobject.h>
| ^~~~~~~~~~~
compilation terminated.
How can I include the file qobject.h?
I am using Xubuntu20.04.5 LTS, running C++ code in VSCode, with Microsoft's C/C++ Extension. Qt5 was installed by default along with the OS. I googled and learnt how to add include path in VSCode,then I searched in my drive and found the location of qobject.h: /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h
Now my .vscode/c_cpp_properties.json file is:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/include/**",
"/usr/include/x86_64-linux-gnu/qt5/QtCore/**",
"/usr/include/x86_64-linux-gnu/qt5/**",
"/usr/include/x86_64-linux-gnu/qt5/",
"/usr/include/x86_64-linux-gnu/qt5/QtCore/"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
Still I was getting error.
Then I copied qobject.h and the QtCore folder from the location of qobject.h to /usr/local/include/, now it seems like VSCode is able to find all the include files but still I get an error:
In file included from /usr/local/include/QtCore/qnamespace.h:43,
from /usr/local/include/QtCore/qobjectdefs.h:48,
from /usr/local/include/qobject.h:46,
from /usr/local/include/Inventor/Qt/SoQt.h:48,
from /home/xxx/Playground/Coin3D/hello_cone.cpp:1:
/usr/local/include/QtCore/qglobal.h:1187:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)."
1187 | # error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
| ^~~~~
Build finished with error(s).
I am new to C++, running C++ in VSCode and QT, Please help!
Edit: To .vscode/tasks.json's args I added:
"-I/usr/include/x86_64-linux-gnu/qt5/QtCore/",
"-I/usr/include/x86_64-linux-gnu/qt5/",
then I am getting the error:
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qnamespace.h:43,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs.h:48,
from /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:46,
from /usr/local/include/Inventor/Qt/SoQt.h:48,
from /home/egp/Playground/Coin3D/hello_cone.cpp:1:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:1187:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)."
1187 | # error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
Then I add "-fPIC", in the tasks.json's args, I again get:
Starting build...
/usr/bin/g++ -fdiagnostics-color=always -g /home/egp/Playground/Coin3D/hello_cone.cpp -fPIC -I/usr/include/x86_64-linux-gnu/qt5/QtCore/ -I/usr/include/x86_64-linux-gnu/qt5/ -o /home/egp/Playground/Coin3D/hello_cone
/usr/bin/ld: /tmp/cc6N1OvD.o: in function `main':
/home/egp/Playground/Coin3D/hello_cone.cpp:14: undefined reference to `SoQt::init(char const*, char const*)'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:18: undefined reference to `SoSeparator::SoSeparator()'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:19: undefined reference to `SoPerspectiveCamera::SoPerspectiveCamera()'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:20: undefined reference to `SoMaterial::SoMaterial()'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:21: undefined reference to `SoBase::ref() const'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:23: undefined reference to `SoDirectionalLight::SoDirectionalLight()'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:24: undefined reference to `SoMFColor::setValue(float, float, float)'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:26: undefined reference to `SoCone::SoCone()'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:30: undefined reference to `SoQtRenderArea::SoQtRenderArea(QWidget*, char const*, int, int, int)'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:33: undefined reference to `SoQtRenderArea::getViewportRegion() const'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:33: undefined reference to `SoCamera::viewAll(SoNode*, SbViewportRegion const&, float)'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:37: undefined reference to `SoQtComponent::setTitle(char const*)'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:40: undefined reference to `SoQt::show(QWidget*)'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:41: undefined reference to `SoQt::mainLoop()'
/usr/bin/ld: /home/egp/Playground/Coin3D/hello_cone.cpp:44: undefined reference to `SoBase::unref() const'
/usr/bin/ld: /tmp/cc6N1OvD.o:(.qtversion[qt_version_tag]+0x0): undefined reference to `qt_version_tag'
collect2: error: ld returned 1 exit status