OpenCV linking problems with ROS - c++

I'm trying to compile this project (following the instructions given). When building it with rosmake, I get a bunch of undefined reference to cv::String::deallocate() and undefined reference to cv::String::allocate(unsigned long). I find curious that I'm getting an error just in those functions while the rest of the OpenCV functions seem to be working properly.
I know this happens because the linker can't find the objects where these functions were compiled to, but I'm kind of new to the ROS build system and can't find what's wrong.
I've tried using the CMakeLists.txt file provided, and also adding find_package(OpenCV REQUIRED) and target_link_libraries(xxx xxx ${OpenCV_LIBRARIES}), without that making any difference. I know OpenCV is installed and compiled properly (I've used it before), and I had installed ROS without any problems.
I'm using OpenCV 3, ROS Indigo, Ubuntu 14.04

I had this exact same problem - same error messages, same setup. I've managed to solve it, though I'm not exactly sure of the steps I did which actually contributed. As far as I can tell, it was due to a conflict of OpenCV versions - I think I had old versions of OpenCV cluttering my /usr/include and /usr/local. I uninstalled all OpenCV packages (including the ROS ones) and including my from-source install of OpenCV3 (also in /usr/local). Then I installed the ROS package vision_opencv, which seemed to install OpenCV 2.4.8 (incidentally the one recommended by LSD SLAM). Of course, this could be annoying if you need OpenCV3 for other things, but I now have that as a local install in my home directory (I couldn't figure out how to get ROS to link to this).
I think this solved the problem, the only issue remaining was that I got error messages saying was not found. This was because the package install leaves it in (similar for all module include files), whereas the make install step of the from-source install copies them into the parent folder. To get around this I simply edited the #include in the only file in which it is used (lsd_slam_core/src/IOWrapper/OpenCV/ImageDisplay_OpenCV.cpp). That seemed to solve it!
I hope this helps, I can give further details if needed.

I am using OpenCV 3.1.0(Bleeding edge), ROS Indigo, Ubuntu 14.04.
I ran in to similar trouble when trying to compile LSD-SLAM
I added:
find_package(OpenCV 3.1.0 REQUIRED COMPONENTS core highgui imgproc imgcodecs)
I also added opencv libs to target link libs:
target_link_libraries(lsdslam ${FABMAP_LIB} g2o_core g2o_stuff csparse cxsparse g2o_solver_csparse g2o_csparse_extension g2o_types_sim3 g2o_types_sba X11 opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs)
Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 2.8.12)
project(lsd_slam_core)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
find_package(OpenCV 3.1.0 REQUIRED COMPONENTS core highgui imgproc imgcodecs)
# Set the build type. Options are:
# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
# Debug : w/ debug symbols, w/o optimization
# Release : w/o debug symbols, w/ optimization
# RelWithDebInfo : w/ debug symbols, w/ optimization
# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
set(ROS_BUILD_TYPE Release)
rosbuild_init()
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
find_package(Eigen3 REQUIRED)
find_package(SuiteParse REQUIRED) # Apparently needed by g2o
find_package(X11 REQUIRED)
# FabMap
# uncomment this part to enable fabmap
#add_subdirectory(${PROJECT_SOURCE_DIR}/thirdparty/openFabMap)
#include_directories(${PROJECT_SOURCE_DIR}/thirdparty/openFabMap/include)
#add_definitions("-DHAVE_FABMAP")
#set(FABMAP_LIB openFABMAP )
# Dynamic Reconfigure Services
rosbuild_find_ros_package(dynamic_reconfigure)
include(${dynamic_reconfigure_PACKAGE_PATH}/cmake/cfgbuild.cmake)
gencfg()
# SSE flags
rosbuild_check_for_sse()
add_definitions("-DUSE_ROS")
add_definitions("-DENABLE_SSE")
# Also add some useful compiler flag
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} ${SSE_FLAGS} -march=native -std=c++0x"
)
# Set source files
set(lsd_SOURCE_FILES
${PROJECT_SOURCE_DIR}/src/DataStructures/Frame.cpp
${PROJECT_SOURCE_DIR}/src/DataStructures/FramePoseStruct.cpp
${PROJECT_SOURCE_DIR}/src/DataStructures/FrameMemory.cpp
${PROJECT_SOURCE_DIR}/src/SlamSystem.cpp
${PROJECT_SOURCE_DIR}/src/LiveSLAMWrapper.cpp
${PROJECT_SOURCE_DIR}/src/DepthEstimation/DepthMap.cpp
${PROJECT_SOURCE_DIR}/src/DepthEstimation/DepthMapPixelHypothesis.cpp
${PROJECT_SOURCE_DIR}/src/util/globalFuncs.cpp
${PROJECT_SOURCE_DIR}/src/util/SophusUtil.cpp
${PROJECT_SOURCE_DIR}/src/util/settings.cpp
${PROJECT_SOURCE_DIR}/src/util/Undistorter.cpp
${PROJECT_SOURCE_DIR}/src/Tracking/Sim3Tracker.cpp
${PROJECT_SOURCE_DIR}/src/Tracking/Relocalizer.cpp
${PROJECT_SOURCE_DIR}/src/Tracking/SE3Tracker.cpp
${PROJECT_SOURCE_DIR}/src/Tracking/TrackingReference.cpp
${PROJECT_SOURCE_DIR}/src/IOWrapper/Timestamp.cpp
${PROJECT_SOURCE_DIR}/src/GlobalMapping/FabMap.cpp
${PROJECT_SOURCE_DIR}/src/GlobalMapping/KeyFrameGraph.cpp
${PROJECT_SOURCE_DIR}/src/GlobalMapping/g2oTypeSim3Sophus.cpp
${PROJECT_SOURCE_DIR}/src/GlobalMapping/TrackableKeyFrameSearch.cpp
)
set(SOURCE_FILES
${lsd_SOURCE_FILES}
${PROJECT_SOURCE_DIR}/src/IOWrapper/ROS/ROSImageStreamThread.cpp
${PROJECT_SOURCE_DIR}/src/IOWrapper/ROS/ROSOutput3DWrapper.cpp
${PROJECT_SOURCE_DIR}/src/IOWrapper/OpenCV/ImageDisplay_OpenCV.cpp
)
include_directories(
${EIGEN3_INCLUDE_DIR}
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/thirdparty/Sophus
${CSPARSE_INCLUDE_DIR} #Has been set by SuiteParse
${CHOLMOD_INCLUDE_DIR} #Has been set by SuiteParse
)
# build shared library.
rosbuild_add_library(lsdslam SHARED ${SOURCE_FILES})
target_link_libraries(lsdslam ${FABMAP_LIB} g2o_core g2o_stuff csparse cxsparse g2o_solver_csparse g2o_csparse_extension g2o_types_sim3 g2o_types_sba X11 opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs)
rosbuild_link_boost(lsdslam thread)
# build live ros node
rosbuild_add_executable(live_slam src/main_live_odometry.cpp)
target_link_libraries(live_slam lsdslam)
# build image node
rosbuild_add_executable(dataset_slam src/main_on_images.cpp)
target_link_libraries(dataset_slam lsdslam)

Do you have multi-versions Opencv? if you have, maybe you should add the path to OpenCVConfig.cmake into CmakeList.txt. Just under the cmake_minimum_required(VERSION 2.8.12),like so:
set(OpenCV_DIR "/home/ubuntu/src/opencv-3.1.0/build")
That's all.

I also had the samme issue. Could not comment Osian's solution due to lack of rep, but this is the procedure I used:
sudo apt-get remove libopencv*
If you for some reason have OpenCV installed from source, enter your build directory and do:
sudo make uninstall
Then finally
sudo apt-get install ros-indigo-desktop-full

Related

CLion Not Finding GLUT with CMake

I have a problem that I can't seem to find the settings to modify.
When attempting to find the GLUT package using CLion's CMake utilities on Ubuntu, it does not find GLUT. Using command-line CMake and Makefile commands, however, finds the dependencies perfectly and allows the following to generate and compile:
# CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(mre)
set(CMAKE_CXX_STANDARD 20)
find_package(OpenGL REQUIRED) # Works in CLion and terminal
find_package(GLUT REQUIRED) # Works only in terminal
include_directories(GL)
add_executable(mre mre.cpp)
target_link_libraries(mre -lglut -lGLU -lGL)
// mre.cpp
#include <GL/gl.h>
#include <GL/glut.h>
int main()
{
return 0;
}
Whereas attempting to use these files in a CLion project would cause errors (first unable to find GLUT, mitigated by manually setting library and include variables; then GL/glut.h: No such file or directory, which I am unable to fix).
Does anyone have any suggestions? I'm assuming it's something to do with a working directory or prefixes, but CMAKE_PREFIX_PATH is unset in CLion, and setting it to various values does nothing to solve the problem.
Thanks!
You know something has gone wrong when you write include_directories or -l flags by hand. You should absolutely always link to libraries via their imported targets.
See the documentation:
OpenGL package: https://cmake.org/cmake/help/latest/module/FindOpenGL.html
GLUT package: https://cmake.org/cmake/help/latest/module/FindGLUT.html
Try this revision:
cmake_minimum_required(VERSION 3.16)
project(mre)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
add_executable(mre mre.cpp)
target_link_libraries(mre PRIVATE OpenGL::GL OpenGL::GLU GLUT::GLUT)
target_compile_features(mre PRIVATE cxx_std_20)
As for not being able to find GLUT... just set CMAKE_PREFIX_PATH in CLion's settings to whichever directory on your system contains include/GL/glut.h.
Alternative solution
CLion was installed through the Software Center via Flatpak, which uses some kind of filesystem sandboxing that may be interfering with paths. I tried explicitly allowing /usr and related paths, but had no effect.
I have reinstalled via JetBrains's official archive, which correctly detects GLUT and OpenGL. Their official snap also works properly.

How resolve the error find_package not providing in CMake [duplicate]

I wrote a CMakeLists.txt for a project in C++, which uses OpenCV libraries. When I try to create the project using cmake, I get the next configuration problem:
CMake Error at CMakeLists.txt:15 (find_package):
Could not find module FindOpenCV.cmake or a configuration file for package
OpenCV.
Adjust CMAKE_MODULE_PATH to find FindOpenCV.cmake or set OpenCV_DIR to the
directory containing a CMake configuration file for OpenCV. The file will
have one of the following names:
OpenCVConfig.cmake
opencv-config.cmake
The fact is that I have an environment variable for the path which I use in Visual Studio with no problems. If I don't include OpenCV, then I can configure and generate with no problem, but I need to solve the problem. I don't understand why cmake cannot find the OpenCV path or how to fix it.
I also used the recommendations mentioned in this link:
FindOpenCV.cmake
Does anybody had this problem too?
The error you're seeing is that CMake cannot find a FindOpenCV.cmake file, because cmake doesn't include one out of the box. Therefore you need to find one and put it where cmake can find it:
You can find a good start here. If you're feeling adventurous you can also write your own.
Then add it somewhere in your project and adjust CMAKE_MODULE_PATH so that cmake can find it.
e.g., if you have
CMakeLists.txt
cmake-modules/FindOpenCV.cmake
Then you should do a
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
In your CMakeLists.txt file before you do a find_package(OpenCV)
If you are on Linux, you just need to fill the OpenCV_DIR variable with the path of opencv (containing the OpenCVConfig.cmake file)
export OpenCV_DIR=<path_of_opencv>
apt-get install libopencv-dev
export OpenCV_DIR=/usr/share/OpenCV
the header of cpp file should contain:
#include
#include "opencv2/highgui/highgui.hpp"
#include
#include
not original cv.h
find / -name "OpenCVConfig.cmake"
export OpenCV_DIR=/path/found/above
I had this exact same problem. I fixed it by adding the following line to my FindOpenCV.cmake file. Put it anywhere at the top before the rest of the code.
set (OpenCV_DIR /home/cmake/opencv/compiled) #change the path to match your complied directory of opencv
Basically you are telling FindOpenCV.cmake where to find opencv files assuming the other compilation can find the FindOpenCV.cmake
I faced the same error. In my case this "OpenCVConfig.cmake" file is located in /usr/local/share/OpenCV. In CMakeLists.txt add the line
set(OpenCV_DIR /usr/local/share/OpenCV)
as suggested by the error message.
if you are on windows, you can add opencv path to OpenCV_DIR yourself.
(OpenCV_DIR is in the red region)
the path is like "D:/opencv244/build".
you can find file "OpenCVConfig.cmake" under the path.
Another possibility is to denote where you can find OpenCV_DIR in the CMakeLists.txt file. For example, the following cmake scripts work for me:
cmake_minimum_required(VERSION 2.8)
project(performance_test)
set(OpenCV_STATIC ON)
set(OpenCV_CUDA OFF)
set(OpenCV_DIR "${CMAKE_SOURCE_DIR}/../install")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_LIB_DIR})
file(GLOB my_source_files ./src/*)
add_executable( performance_test ${my_source_files})
target_link_libraries(performance_test ${OpenCV_LIBS})
Just to remind that you should set OpenCV_STATIC and OpenCV_CUDA as well before you invoke OpenCVConfig.cmake. In my case the built library is static library that does not use CUDA.
On my Fedora machine, when I typed "make" I got an error saying it could not find "cv.h". I fixed this by modifying my "OpenCVConfig.cmake" file.
Before:
SET(OpenCV_INCLUDE_DIRS "${OpenCV_INSTALL_PATH}/include/opencv;${OpenCV_INSTALL_PATH}/include")
SET(OpenCV_LIB_DIR "${OpenCV_INSTALL_PATH}/lib64")
After:
SET(OpenCV_INCLUDE_DIRS "/usr/include/opencv;/usr/include/opencv2")
SET(OpenCV_LIB_DIR "/usr/lib64")
I am using Windows and get the same error message. I find another problem which is relevant.
I defined OpenCV_DIR in my path at the end of the line. However when I typed "path" in the command line, my OpenCV_DIR was not shown. I found because Windows probably has a limit on how long the path can be, it cut my OpenCV_DIR to be only part of what I defined. So I removed some other part of the path, now it works.
I had the same error, I use windows. I add "C:\opencv\build" (opencv folder) to path at the control pannel.
So, That's Ok!!
For me (on Ubuntu), I just run:
sudo apt-get install libopencv-dev
Followed #hugh-pearse 's and #leszek-hanusz 's answers, with a little tweak. I had installed opencv from ubuntu 12.10 repository (libopencv-)* and had the same problem. Couldn't solve it with export OpenCV_DIR=/usr/share/OpenCV/ (since my OpenCVConfig.cmake whas there). It was solved when I also changed some lines on the OpenCVConfig.cmake file:
# ======================================================
# Include directories to add to the user project:
# ======================================================
# Provide the include directories to the caller
#SET(OpenCV_INCLUDE_DIRS "${OpenCV_INSTALL_PATH}/include/opencv;${OpenCV_INSTALL_PATH}/include")
SET(OpenCV_INCLUDE_DIRS "/usr/include/opencv;/usr/include/opencv2")
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
# ======================================================
# Link directories to add to the user project:
# ======================================================
# Provide the libs directory anyway, it may be needed in some cases.
#SET(OpenCV_LIB_DIR "${OpenCV_INSTALL_PATH}/lib")
SET(OpenCV_LIB_DIR "/usr/lib")
LINK_DIRECTORIES(${OpenCV_LIB_DIR})
And that worked on my Ubuntu 12.10. Remember to add the target_link_libraries(yourprojectname ${OpenCV_LIBS}) in your CMakeLists.txt.
When you install the libraries in the c drive (windows). the CMakeLists.txt shoud be looking like below:
cmake_minimum_required(VERSION 3.0.0)
project(test_opencv VERSION 0.1.0)
include(CTest)
enable_testing()
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(test_opencv main.cpp)
target_link_libraries(test_opencv ${OPENCV_LIBS})
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
finding the package and include directories
when building the project in VS code. Run the visual studio code with admin rights as the OpenCV is installed inside C drive.

CMake BUILD undefined reference (findpng)

I'm still very new to CMake so feedback is definitely welcome. So, I'm trying to build a simple application that should eventually create a pdf using the library libharu.
I think i figured it out how to link the library. But I still receive build errors for the findpng module (I suppose libharu depends on it)
CMakeLists.txt:
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR) # current latest stable version (if lower give FATAL_ERROR)
project(pdf_generator VERSION 0.1.0) # name of the project, version.
file(GLOB TARGET_SRC "./src/*.cpp") # Creates variable, using globbing.
include_directories(${PROJECT_SOURCE_DIR}/include) # list of directories to be used as header search paths.
add_executable(main ${TARGET_SRC}) # Create an executable of set of source files [exe name files to bundle].
find_library(libhpdf_location NAMES libhpdf.a) # find the location of libhpdf.a and save the value in the variable libhpdf_location.
message(STATUS ${libhpdf_location}) # print status of variable.
add_library(libhpdf STATIC IMPORTED) # Add library via a static import.
set_target_properties(
libhpdf PROPERTIES
IMPORTED_LOCATION ${libhpdf_location}
)
target_link_libraries(main libhpdf)
I've never worked with that particular library before, but skimming their CMakeLists.txt on GitHub it seems like libharu has optional dependencies on libpdf and zlib. Without knowing how you built your version of libharu I'm going to assume that both are needed.
Luckily, CMake comes with find-modules for both libpng and zlib, so adding the following should work:
find_package(PNG REQUIRED)
find_package(ZLIB REQUIRED)
set_target_properties(libhpdf
PROPERTIES
INTERFACE_LINK_LIBRARIES "ZLIB::ZLIB;PNG::PNG"
)
Looks like all you need to do is tell cmake to link libpng.

how to get CMake to add MagickWand library linking automatically everywhere

I want to use CMake in my software that uses MagickWand.
CMake works on my machine and generates a useful Makefile.
On another machine, I have to manually add
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lMagickWand-6.Q16 -lMagickCore-6.Q16")
otherwise the linker can't find MagickWandGenesis() and other functions.
I found that -l flags via pkg-config --cflags --libs MagickWand.
Shouldn't CMake already generate linker flags for me with TARGET_LINK_LIBRARIES?
Did I miss something obvious, or why is this not working everywhere?
I have this code in CMakeLists.txt:
FIND_PACKAGE(ImageMagick
REQUIRED
COMPONENTS MagickWand
)
[...]
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16")
[...]
INCLUDE_DIRECTORIES(
${Boost_INCLUDE_DIR}
${ImageMagick_INCLUDE_DIRS}
${ImageMagick_MagickWand_INCLUDE_DIRS}
)
[...]
TARGET_LINK_LIBRARIES(application_name
[...]
${Boost_LIBRARIES}
${CURL_LIBRARIES}
${ImageMagick_LIBRARIES}
${ImageMagick_MagickWand_LIBRARY}
)
That last ${ImageMagick_MagickWand_LIBRARY} shouldn't even be necessary.
Using Magick 6.8.9.9, CMake 3.0.2 on both machines (Debian Jessie).
Short answer: the package ImageMagick is buggy.
Looking in CMake's sources, the REQUIRED mechanism is handled exclusively through the variable package-_FOUND, independently of the required components.
Looking in the package ImageMagick here, ImageMagick_FOUND is set as follows:
set(ImageMagick_FOUND ${IMAGEMAGICK_FOUND})
But IMAGEMAGICK_FOUND is not set anywhere in the package, so the call will always unset ImageMagick_FOUND, and it will always be evaluated to true (not actively set to false), wether or not the components are effectively found.
You can either debug the package (and propose a pull request) or check the component variable:
if(NOT ImageMagick_MagickWand_FOUND)
message(FATAL_ERROR "MagickWand not found")
endif()
I guess the test will fail on your second machine.
By the way, you should only use ImageMagick_INCLUDE_DIRS and ImageMagick_LIBRARIES to link to the library (the ImageMagick_MagickWand* variables are here redundant). If you choose to debug the package, you may also declare imported targets.
Figured it out, despite the output of
MESSAGE(${ImageMagick_FOUND})
MESSAGE(${ImageMagick_INCLUDE_DIRS})
MESSAGE(${ImageMagick_LIBRARIES})
MESSAGE(${ImageMagick_MagickWand_FOUND})
MESSAGE(${ImageMagick_MagickWand_INCLUDE_DIRS})
MESSAGE(${ImageMagick_MagickWand_LIBRARY})
being identical, the installed packages differed. I installed the magick-dev packages via virtual packages in aptitude, which for some reason used the graphicsmagick suite for some packages (a imagemagick fork) instead of the original imagemagick suite.
For reference, the used aptitude search one-liner was aptitude search 'magick ?installed' | sort which listed three graphicsmagick packages on the second machine where imagemagick packages were on the first machine.

Compiling error: "cannot find -lQtCore4"

Yesterday I downloaded the Qt4 Opensource library for linux. After running
./configure
./make
./make install
And inserting this into my .bashrc-file:
PATH=/usr/local/TrollTech/Qt-4.7.3/bin:$PATH
export PATH
After this, I ran cmake in order to produce a Makefile for me. CMakeLists.txt:
project(VTKToVTFx)
cmake_minimum_required(VERSION 2.6)
find_package(VTK REQUIRED)
find_package(Qt4 REQUIRED)
include(${VTK_USE_FILE})
include(${QT_USE_FILE})
SET(VTK_TO_VTFX_FORMS main.ui)
QT4_WRAP_UI(VTK_TO_VTFX_FORMS_UIC ${VTK_TO_VTFX_FORMS})
SET(MOC_HEADERS VTKToVTFx.h)
qt4_wrap_cpp(MOC_OUTFILES ${MOC_HEADERS})
SET(CPP_SOURCES VTKToVTFx.cpp
VTKPatch.cpp
VTKFile.cpp
VTKData.cpp
VTKDataHolder.cpp
)
add_executable(VTKToVTFx ${CPP_SOURCES} ${VTK_TO_VTFX_FORMS_UIC} ${MOC_OUTFILES})
# Adds folders for Visual Studio solution explorer (and for Xcode explorer)
source_group( "Generated" FILES ${MOC_FILES_CPP} ${VTK_TO_VTFX_FORMS_UIC} ${QRC_FILES_CPP} ${MOC_OUTFILES})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(VTKToVTFx vtkHybrid)
target_link_libraries(VTKToVTFx QtCore4)
target_link_libraries(VTKToVTFx QtGUI4)
This CMakeLists.txt works perfectly well on Windows, but when I try to compile the output on my installation of Ubuntu, this error occurs:
/usr/bin/ld: cannot find -lQtCore4
/usr/bin/ld: cannot find -lQtGUI4
Anyone who could point me to my problem here?
In the unix[like] world, the slash is the path seperator, not the backslash.
\usr\local\TrollTech\Qt-4.7.3\bin evaluates to usrlocalTrollTechQt-4.7.3bin.
edit: Also, your CMakeLists.txt seems a bit foul. Have a look at http://qtnode.net/wiki/Qt4_with_cmake . Instead of
target_link_libraries(VTKToVTFx QtCore4)
use something like (source is the linked site):
To add support for Qt4 libraries like network or qttest, you need to add both the include files and corresponding libraries. For example, to add support for the network and qttest libraries, you can use:
INCLUDE_DIRECTORIES(
${QT_INCLUDE_DIR}
${QT_QTNETWORK_INCLUDE_DIR}
${QT_QTTEST_INCLUDE_DIR}
)
TARGET_LINK_LIBRARIES(
${QT_LIBRARIES}
${QT_QTNETWORK_LIBRARIES}
${QT_QTTEST_LIBRARIES}
)
Even within the 4.x line of releases, libraries have been renamed and will be renamed. Fortunately there is no need for hardcodery :)