I am trying to build a glfw and glew c++ code but while building I am getting the following error:
fatal error C1034: GL/glew.h: no include path set
any help is appreciated.
OS: Windows 10
compiler: MSVC++ 17.0.3
package-installer: vcpkg
IDE: Visual Studio Code
Build: Cmake
CmakeLists.txt :
cmake_minimum_required(VERSION 3.0.0)
project(my_project VERSION 0.1.0)
include(CTest)
enable_testing()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_TOOLCHAIN_FILE C:/Users/pc/vcpkg/scripts/buildsystems/vcpkg.cmake)
add_executable(
my_project
main.cpp
)
INCLUDE_DIRECTORIES(
c:/Users/pc/vcpkg/installed/x86-windows/include/
)
LINK_DIRECTORIES(
c:/Users/pc/vcpkg/installed/x86-windows/lib/
)
find_package(fmt CONFIG REQUIRED)
find_package(GLEW REQUIRED)
find_package(glfw3 REQUIRED)
find_package(freetype CONFIG REQUIRED)
find_package(glm CONFIG REQUIRED)
TARGET_LINK_LIBRARIES(my_project
glfw glm::glm GLEW::GLEW freetype fmt::fmt
)
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
Setting CMAKE_TOOLCHAIN_FILE after project(my_project VERSION 0.1.0) does not work since project(my_project VERSION 0.1.0) loads the CMAKE_TOOLCHAIN_FILE. So move it before project()
Also remove
INCLUDE_DIRECTORIES(
c:/Users/pc/vcpkg/installed/x86-windows/include/
)
LINK_DIRECTORIES(
c:/Users/pc/vcpkg/installed/x86-windows/lib/
)
since linking against the above targets should be more than enough! (also always use target_* functions instead.)
Furthermore increase
cmake_minimum_required(VERSION 3.0.0)
to something reasonable. You probably don't plan on supporting ancient versions of cmake. If you don't need to support ancient linux distros you can just move to at least 3.17. If you only plan to support windows you can directly move to 3.22 or use whatever vs uses. vcpkg is currently at 3.21.
Related
I download OpencV using VCPKG:
./vcpkg install opencv2:x64-windows
Computing installation plan...
The following packages are already installed:
opencv2[core,eigen,jpeg,png,tiff]:x64-windows -> 2.4.13.7#5
Package opencv2:x64-windows is already installed
Total elapsed time: 2.225 ms
The package opencv2:x64-windows provides CMake targets:
find_package(OpenCV CONFIG REQUIRED)
# Note: 15 target(s) were omitted.
target_link_libraries(main PRIVATE opencv_ml opencv_ts opencv_gpu opencv_ocl)
and write cmakelists like this:
cmake_minimum_required(VERSION 3.10)
set(CMAKE_TOOLCHAIN_FILE E:/vcpkg/scripts/buildsystems/vcpkg.cmake
CACHE STRING "Vcpkg toolchain file")
# set the project name
project(QRCODE)
# add the executable
add_executable(qrcode main.cpp)
find_package(OpenCV COMPONENTS REQUIRED)
# Additional Include Directories
include_directories( ${OpenCV_INCLUDE_DIRS} )
# Additional Library Directories
link_directories( ${OpenCV_LIB_DIR} )
# Additional Dependencies
target_link_libraries(qrcode ${OpenCV_LIBS})
message("${OpenCV_DIR}")
message("${OpenCV_INCLUDE_DIRS}")
and what puzzles me is that cmake output looks like this:
E:/vcpkg/installed/x64-windows/share/opencv
/include/opencv;/include
it seems like opencv was not installed successfully, or cmake couldn't find opencv install path.
When I built the project using cmake tool, encountered with fatal error: “opencv2/core/core.hpp”: No such file or directory.
I have been losing my head over this for some time now. So I need to use the opencv in a ros melodic package built by the catkin on the Ubuntu 18.04. The idea is to make a package which is actually just a library and this library using all the regular ros packages (image_transport, cv_bridge, roscpp, rospy, std_msgs, genmsg, tf, actionlib_msgs, actionlib ).
Just to let you know, I have 2 opencv installed, the openCV 3.2 in the usr/share and the openCV 4.3 in the usr/local/share, that is why I have specifically set the openCV_DIR to point to the 3.2 version.
I have tried to add message to the CMakeList.txt to print out the opencv_version, opencv_include_dir and opencv_libs and the version is 3.2.0, include_dirs is /usr/include;/usr/include/opencv and libs are opencv_calib3d;opencv_core;opencv_features2d;opencv_flann;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_shape;opencv_stitching;opencv_superres;opencv_video;opencv_videoio;opencv_videostab;opencv_viz;opencv_aruco;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_datasets;opencv_dpm;opencv_face;opencv_freetype;opencv_fuzzy;opencv_hdf;opencv_line_descriptor;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_reg;opencv_rgbd;opencv_saliency;opencv_stereo;opencv_structured_light;opencv_surface_matching;opencv_text;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto
in my pkg_library CMakeList.txt I have this:
cmake_minimum_required(VERSION 2.8.3)
project(pkg_libraries)
## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)
set( OpenCV_DIR "/usr/share/OpenCV/" )
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(
catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
genmsg
tf
actionlib_msgs
actionlib
sensor_msgs
cv_bridge
image_transport
message_generation
)
find_package(
OpenCV REQUIRED
)
catkin_package(
INCLUDE_DIRS include
LIBRARIES pkg_libraries
CATKIN_DEPENDS roscpp rospy std_msgs tf actionlib actionlib_msgs cv_bridge
)
include_directories(
include
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
add_library(${PROJECT_NAME}
src/imageSaver.cpp
)
target_link_libraries( ${PROJECT_NAME} ${catkin_LIBRARIES} ${OpenCV_LIBS} )
install(
TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
)
install(
DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
)
the compilation of the pkg_libraries with the catkin_build looks just fine, but later when I try to do catkin_build in the another package which includes the pkg_libraries, it fails with the error:
libpkg_libraries.so: undefined reference to
`cv::imwrite(std::__cxx11::basic_string,
std::allocator > const&, cv::_InputArray const&,
std::vector > const&)'
Which I would say looks like the linker error, because I have used the cv::imwrite only in the pkg_libraries. and the package which reports the error includes only the pkg_libraries. So the pkg_libraries but it is obviously not linked properly, but it is built without errors.
What am I missing here?
Thanks
the problem was because of the pkg_libraries is built like a shared library in which I have had another .cpp and .h which were using different openCV versions (default opencv 3.2) and I think the problem happened because by loading the libpkg_libraries.so I have made a conflict between openCV version.
Anyway, now I have made separate libraries and it works as it suppose to work.
Thanks
I'm getting this error when I catkin_make my workspace:
[100%] Linking CXX executable /home/ankilp/test_ws/devel/lib/lidar_depth/lidar_depth
/usr/bin/ld: cannot find -lQt5::Widgets
This is my CMakeList file:
cmake_minimum_required(VERSION 2.8.3)
project(lidar_depth)
## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
std_msgs
genmsg
)
find_package( PCL REQUIRED)
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
include(${QT_USE_FILE})
add_definitions(-DQT_NO_KEYWORDS)
catkin_package(
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
${catkin_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
)
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(${PROJECT_NAME} src/LidarDepth.cpp src/Projection_matrices.hpp)
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
${PCL_LIBRARIES}
${QT_LIBRARIES}
)
I don't explicitly use anything related to Qt. I installed Qt5 separately but the problem persists. Is there a separate process to link Qt to my system?
It looks like you're using at least ROS Kinetic (based on the comment where you add compile options). Most things in Kinetic depend on Qt5 instead of Qt4. Try making the following changes to your CMakeLists.txt file:
Replace this line
find_package(Qt4 COMPONENTS QtCore QtGui REQUIRED)
with these lines
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
set(QT_LIBRARIES Qt5::Widgets)
If this doesn't work for you, leave a comment as I have a working CMakeLists.txt file for Qt5 in Kinetic and can probably determine what else needs changed, but I think that is the minimal change to make.
If you have installed Qt seperately, you have to tell CMAKE where it can find you installation. This can be done by specifying the CMAKE_PREFIX_PATH inside the CMakeLists.txt file or in the terminal before executing cmake (ref). E.g.:
$ export CMAKE_PREFIX_PATH=/location/to/you/installation
I'm trying to load OpenCV Libraries in CMakeFile.txt but it always ends with this error:
CMake Error at CMakeLists.txt:21 (target_link_libraries):
Cannot specify link libraries for target "HelloWorld" which is not built by
this project.
I've searched on the Internet but have got no solution.
cmake_minimum_required(VERSION 3.8)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/KotlinCMakeModule)
project(untitled1 Kotlin)
find_package(OpenCV REQUIRED)
IF (OpenCV_FOUND)
include_directories(/usr/local/Cellar/opencv/3.4.0_1/include)
link_libraries(/usr/local/Cellar/opencv/3.4.0_1/lib)
ENDIF(OpenCV_FOUND)
konanc_executable(
NAME HelloWorld
SOURCES hello.kt
)
target_link_libraries(HelloWorld
/usr/local/Cellar/opencv/3.4.0_1/lib
)
Someone can help me? I think it's not working because on the use of konanc_executable instead of add_executable but I need to use Kotlin so I cannot use the add_executable command.
I'm running RHEL 5.1 and use gcc.
How I tell cmake to add -pthread to compilation and linking?
#Manuel was part way there. You can add the compiler option as well, like this:
If you have CMake 3.1.0+, this becomes even easier:
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(my_app PRIVATE Threads::Threads)
If you are using CMake 2.8.12+, you can simplify this to:
find_package(Threads REQUIRED)
if(THREADS_HAVE_PTHREAD_ARG)
target_compile_options(my_app PUBLIC "-pthread")
endif()
if(CMAKE_THREAD_LIBS_INIT)
target_link_libraries(my_app "${CMAKE_THREAD_LIBS_INIT}")
endif()
Older CMake versions may require:
find_package(Threads REQUIRED)
if(THREADS_HAVE_PTHREAD_ARG)
set_property(TARGET my_app PROPERTY COMPILE_OPTIONS "-pthread")
set_property(TARGET my_app PROPERTY INTERFACE_COMPILE_OPTIONS "-pthread")
endif()
if(CMAKE_THREAD_LIBS_INIT)
target_link_libraries(my_app "${CMAKE_THREAD_LIBS_INIT}")
endif()
If you want to use one of the first two methods with CMake 3.1+, you will need set(THREADS_PREFER_PTHREAD_FLAG ON) there too.
The following should be clean (using find_package) and work (the find module is called FindThreads):
cmake_minimum_required (VERSION 2.6)
find_package (Threads)
add_executable (myapp main.cpp ...)
target_link_libraries (myapp ${CMAKE_THREAD_LIBS_INIT})
Here is the right anwser:
ADD_EXECUTABLE(your_executable ${source_files})
TARGET_LINK_LIBRARIES( your_executable
pthread
)
equivalent to
-lpthread
target_compile_options solution above is wrong, it won't link the library.
Use:
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -pthread")
OR
target_link_libraries(XXX PUBLIC pthread)
OR
set_target_properties(XXX PROPERTIES LINK_LIBRARIES -pthread)