Solved Suddenly cannot rebuild, undefined reference to qt_version_tag
-
I have a project made with Qt5.7.0, it worked well until yesterday when I installed ROS and PCL 1.7.
Now when I build it show me:main.o:(.qtversion[qt_version_tag]+0x0): undefined reference to `qt_version_tag'
My .pro file is this:
QT += core gui CONFIG += c++11 CONFIG += opencv_core greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = myproject TEMPLATE = app INCLUDEPATH += /usr/local/include/opencv LIBS += -L/usr/lib/x86_64-linux-gnu/ -z LIBS += -L/usr/local/lib -lopencv_highgui -lopencv_core -lopencv_imgproc -lopencv_contrib SOURCES += somesources.cpp HEADERS += someheaderfiles.h FORMS += mainwindow.ui RESOURCES += \ images.qrc DISTFILES += \ CMakeLists.txt
Cmakelists:
cmake_minimum_required(VERSION 2.8) project(myproject) include_directories("${PROJECT_BINARY_DIR}") find_package(OpenCV REQUIRED) add_executable(some.h some.cpp) target_link_libraries(planedetection ${OpenCV_LIBS})
I uninstalled ROS but the problem remains as I expected...
It builds successfully other projects without opencv....
I did a lot of researches and attempts but I can't find a solution, maybe installing ROS and PCL 1.7 has changed something linked with Qt, but I can't find what it could be. It's really strange...I use Ubuntu 16.06, opencv 2.4.11 and Qt5.7.0
Any suggestion?
-
@Yaya Have you tried cleaning your build and remaking it? Simple I know but that problem seems like one that would be solved from a
make clean && make
.Edit:
Oh if you are using cmake, then do something like:
mkdir new-build cd new-build cmake .. make
If that doesn't work give us some more information, maybe the output of
make VERBOSE=1
, and the location of your Qt installation. It's possible you have multiple Qt installs and it is using a different one from your previous build.You can make sure you have QTDIR and PATH set up properly to detect the version you want to use properly.
-
@ambershark
Yes, i've already cleaned and rebuilt from QtCreator and I tried with the shell but it's the same result.
The make VERBORSE=1 result is:g++ -Wl,-rpath,/home/myname/Qt5.7.0/5.7/gcc_64/lib -o myprojectname main.o mainwindow.o my_lib.o qrc_images.o moc_mainwindow.o -L/usr/lib/x86_64-linux-gnu/ -z -L/usr/local/lib -lopencv_highgui -lopencv_core -lopencv_imgproc -lopencv_contrib -L/home/myname/Qt5.7.0/5.7/gcc_64/lib -lQt5Widgets -L/usr/X11R6/lib64 -lQt5Gui -lQt5Core -lGL -lpthread /usr/bin/ld: warning: -z -L/usr/local/lib ignored. main.o:(.qtversion[qt_version_tag]+0x0): undefined reference to `qt_version_tag' collect2: error: ld returned 1 exit status Makefile:234: recipe for target 'myprojectname' failed make: *** [myprojectname] Error 1
The location of my Qt installation: /home/Qt5.7.0/5.7/gcc_64/bin
In /usr/lib/x86_64-linux-gnu I have two Qt folders, Qt4 and Qt5, but in /usr/share/ I have only Qt4.The project on QtCreator should use the 5, if i'm not mistaken, but I think for some reason it use the older one (I don't even know why I have two Qt installs, maybe when I have installed ROS)
How can I set properly QTDIR and PATH? Can I do it from QtCreator? Or I have to set them from shell?Thank you.
-
@Yaya You are compiling against 1 set of headers and linking to a different set of libraries.
This is pretty common in linux. You need to make sure that your headers and libs come from the same install of Qt. Since Linux usually has multiple Qt installs, this is pretty common to get them out of sync.
You set your library directory in your make with -L but I never see you set the include path with -I. So it is using the system include path which will have the system level Qt which is probably not 5.7 in Ubuntu. Fix your makefile to include your includes path and you should be good to go.
I typically set mine in my .bashrc:
QTDIR="/usr/local/Qt" PATH="/usr/local/Qt/bin:$PATH" export QTDIR PATH
Edit: oops keep forgetting you are using cmake.. to fix this with cmake just add the following:
find_package(Qt5Core REQUIRED)
That should set your include path properly for you.
-
@ambershark Yes, it's surely due to the different Qt installs.
Two days ago I used a project (not mine) with cmake and in its CMakeLists there is:# QT4 required find_package(Qt4 REQUIRED) include(${QT_USE_FILE}) add_definitions(${QT_DEFINITIONS})
When i build it, it found the Qt4 properly in
Found Qt4: /usr/bin/qmake (found version "4.8.7")
So, since I've built this project with Qt4, the one (mine) with Qt5 don't work.
I added in the CMakeLists this:find_package(Qt5Core REQUIRED)
but nothing changed. I can't build yet, It shows me the same error...
I probably have to return to Ubuntu 14.04 in these days (because i cannot resolve another problem in the other project with -lvtkproj4 due to a unresolved bug in 16.04) but i think that when I will rebuild the two projects in the new system, the problem will reappear... So I should solve it anyway...
I can try to add this in CMake?
get_target_property(QtCore_location Qt5::Core LOCATION)
I used /home/myname/Qt5.7.0/5.7/gcc_64/bin/qmake (I think this is where it should find qt5) as LOCATION but nothing changed...
If it could be helpful, in /usr/bin/ there is qmake and qmake-qt4.... and qmake refers to 4.8.7, so maybe there's no more linker to the 5...
and the output of qmake --version is:QMake version 2.01a Using Qt version 4.8.7 in /usr/lib/x86_64-linux-gnu
-
@Yaya Well the easy fix is to use my bashrc stuff above. It will make sure you use the qmake and Qt5 stuff from your Qt5 home directory.
Once you start a new shell (after adding it), run a
qmake --version
and make sure it's the 5.7 one. Also you can runwhich qmake
and make sure it's pointing at your Qt5 install.Once those are set, run your build from the command line in a new directory:
cd /your/project mkdir build cd build cmake .. make
That should work, if it doesn't show me the output of
cmake ..
and the output ofmake VERBOSE=1
.Also the other project with the cmake that requires Qt4, that's not part of your build is it? That would screw things up in cmake more than likely.
-
@ambershark
I have set this in .bashrc:QTDIR="/home/myname/Qt5.7.0/5.7/gcc_64" PATH="/home/myname/Qt5.7.0/5.7/gcc_64/bin:$PATH" export QTDIR PATH
The output of cmake .. is:
-- The C compiler identification is GNU 5.4.0 -- The CXX compiler identification is GNU 5.4.0 -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /usr/bin/c++ -- Check for working CXX compiler: /usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done -- Build files have been written to: /home/ayoub/Desktop/PerTesi/PlaneDetection/build
And make VERBOSE=1:
/usr/bin/cmake -H/home/ayoub/Desktop/PerTesi/PlaneDetection -B/home/ayoub/Desktop/PerTesi/PlaneDetection/build --check-build-system CMakeFiles/Makefile.cmake 0 /usr/bin/cmake -E cmake_progress_start /home/ayoub/Desktop/PerTesi/PlaneDetection/build/CMakeFiles /home/ayoub/Desktop/PerTesi/PlaneDetection/build/CMakeFiles/progress.marks make -f CMakeFiles/Makefile2 all make[1]: Entering directory '/home/ayoub/Desktop/PerTesi/PlaneDetection/build' make -f CMakeFiles/planedetection.dir/build.make CMakeFiles/planedetection.dir/depend make[2]: Entering directory '/home/ayoub/Desktop/PerTesi/PlaneDetection/build' cd /home/ayoub/Desktop/PerTesi/PlaneDetection/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/ayoub/Desktop/PerTesi/PlaneDetection /home/ayoub/Desktop/PerTesi/PlaneDetection /home/ayoub/Desktop/PerTesi/PlaneDetection/build /home/ayoub/Desktop/PerTesi/PlaneDetection/build /home/ayoub/Desktop/PerTesi/PlaneDetection/build/CMakeFiles/planedetection.dir/DependInfo.cmake --color= Dependee "/home/ayoub/Desktop/PerTesi/PlaneDetection/build/CMakeFiles/planedetection.dir/DependInfo.cmake" is newer than depender "/home/ayoub/Desktop/PerTesi/PlaneDetection/build/CMakeFiles/planedetection.dir/depend.internal". Dependee "/home/ayoub/Desktop/PerTesi/PlaneDetection/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/home/ayoub/Desktop/PerTesi/PlaneDetection/build/CMakeFiles/planedetection.dir/depend.internal". Scanning dependencies of target planedetection make[2]: Leaving directory '/home/ayoub/Desktop/PerTesi/PlaneDetection/build' make -f CMakeFiles/planedetection.dir/build.make CMakeFiles/planedetection.dir/build make[2]: Entering directory '/home/ayoub/Desktop/PerTesi/PlaneDetection/build' [ 20%] Building CXX object CMakeFiles/planedetection.dir/main.cpp.o /usr/bin/c++ -I/home/ayoub/Desktop/PerTesi/PlaneDetection/build -I/usr/local/include/opencv -I/usr/local/include -o CMakeFiles/planedetection.dir/main.cpp.o -c /home/ayoub/Desktop/PerTesi/PlaneDetection/main.cpp In file included from /home/ayoub/Desktop/PerTesi/PlaneDetection/main.cpp:1:0: /home/ayoub/Desktop/PerTesi/PlaneDetection/mainwindow.h:4:33: fatal error: lib_plane_detection.h: No such file or directory compilation terminated. CMakeFiles/planedetection.dir/build.make:62: recipe for target 'CMakeFiles/planedetection.dir/main.cpp.o' failed make[2]: *** [CMakeFiles/planedetection.dir/main.cpp.o] Error 1 make[2]: Leaving directory '/home/ayoub/Desktop/PerTesi/PlaneDetection/build' CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/planedetection.dir/all' failed make[1]: *** [CMakeFiles/planedetection.dir/all] Error 2 make[1]: Leaving directory '/home/ayoub/Desktop/PerTesi/PlaneDetection/build' Makefile:83: recipe for target 'all' failed make: *** [all] Error 2
It seems like it can't find that header file, I tried to change the include in mainwindow.h (#include <lib_plane_detection.h>) but no changes...
By the way, using cmake and make without QtCreator it seems go well now, it can find Qt5. Thank you so much!
How can I fix it to build with QtCreator too?And... No, the other project is in another path and build.
-
It seems like it can't find that header file, I tried to change the include in mainwindow.h (#include <lib_plane_detection.h>) but no changes...
By the way, using cmake and make without QtCreator it seems go well now, it can find Qt5. Thank you so much!
How can I fix it to build with QtCreator too?And... No, the other project is in another path and build.
To use cmake from QtCreator, you just need to generate the project from cmake. When you choose to open a project you can choose the CMakeLists.txt file instead of the .pro. It will handle the rest for you.
As for your include problem.. Where is
lib_plane_detection.h
in your source? It sounds like you don't have an include directory set. To fix this you would add the directory containing that file to yourinclude_directories
cmake command. Make sure you don't use a full path but instead a relative one to theCMakeLists.txt
file.If you cd to your project root dir, and give me the output of
find .
as well as the contents of yourCMakeLists.txt
I can tell you what you need to change to make it work. -
@ambershark Thank you so much!
I've resolved this last problem looking for the differences between using only the CMakeLists.txt and using the .pro file too.
WIth the CMakeLists.txt only, I had to add more libraries and files linking than i have done in the configuration with the .proNow, it builds good without any problem.
Maybe, in the next weeks I will try again to make it working with the .pro file too, but it's not a priority.With your help I learned a lot about cmake and qmake.
I really appreciate the effort you make to help me, thank you! -
With your help I learned a lot about cmake and qmake.
I really appreciate the effort you make to help me, thank you!No problem at all, happy to help. :)
Cmake is awesome, the more you use it and get used to using it the more you'll love it. At least I did. I haven't used qmake on my projects in years now because cmake has been so good. Not that qmake is bad, but cmake is just way better. ;)
-
hey @Yaya
I'm facing a similar problem and getting the same error
can you please provide some more information how did you include the libraries.Thank You
Or Hirshfeld
Control SW Engineer
https://www.linkedin.com/in/orhirshfeld/ -
@Or-Hirshfeld This thread is a year old, lol. If you read my answers to his questions you'll get the answer for yours as well.
TLDR: you are mixing 2 versions of Qt.