I'm trying to compile a project using OpenCV 2.4 on ubuntu 16.04. I installed opencv using apt-get:
sudo apt-get install libopencv-dev
sudo apt-get install libopencv-nonfree-dev
However, when compiling the project I'm getting the following error message:
undefined reference to `cv::imread(std::string const&, int)'
My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.5)
project(Ex)
find_package(OpenCV REQUIRED )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c99")
message(STATUS "CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}}")
message(STATUS "OpenCV_LIBS=${OpenCV_LIBS}")
set(SOURCE_FILES main.cpp)
add_executable(Ex ${SOURCE_FILES})
target_link_libraries(Ex ${OpenCV_LIBS})
set_property(TARGET Ex PROPERTY C_STANDARD 99)
Does anyone know how to solve this?
Edit
The output of the second message is
OpenCV_LIBS=opencv_videostab;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_photo;opencv_ocl;opencv_objdetect;opencv_nonfree;opencv_ml;opencv_legacy;opencv_imgproc;opencv_highgui;opencv_gpu;opencv_flann;opencv_features2d;opencv_core;opencv_contrib;opencv_calib3d
Related
I'm attempting to set up an environment in which I can use gtkmm for C++ development. My CMakeLists.txt file looks like this:
cmake_minimum_required(VERSION 3.0.2)
project(program)
find_package(PkgConfig)
pkg_check_modules(GTKMM gtkmm-3.0)
link_directories(${GTKMM_LIBRARY_DIRS})
include_directories(include ${GTKMM_INCLUDE_DIRS})
file(GLOB SOURCES "*.cpp")
add_executable(program ${SOURCES})
target_link_libraries(program ${GTKMM_LIBRARIES})
Yet when I try to include the line include <gtkmm.h> in main I am met with this error from CMake:
fatal error: 'gtkmm.h' file not found
#include <gtkmm.h>
I installed gtkmm with brew using the command brew install gtkmm and brew install gtkmm3 to insure versions were not the issue. What can I do to get this working?
Be sure to install pkg-config (using brew).
Here is a CMakeLists.txt file that will work:
cmake_minimum_required(VERSION 3.16)
project(program LANGUAGES CXX)
find_package(PkgConfig)
pkg_check_modules(GTKMM gtkmm-3.0)
add_executable(program)
target_compile_features(program PRIVATE cxx_std_17)
target_sources(program PRIVATE main.cpp)
target_include_directories(program PRIVATE ${GTKMM_INCLUDE_DIRS})
target_link_directories(program PRIVATE ${GTKMM_LIBRARY_DIRS})
target_link_libraries(program PRIVATE ${GTKMM_LIBRARIES})
I'm trying to compile a simple Qt program with make after using CMake and I keep getting this error:
/usr/bin/ld: warning: libGL.so.1, needed by /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1, not found (try using -rpath or -rpath-link)
/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1: undefined reference to `glGetTexParameterfv'
/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1: undefined reference to `glHint'
/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1: undefined reference to `glClearColor'
/usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.5.1: undefined reference to `glFlush'
...
collect2: error: ld returned 1 exit status
I have re-installed libgl1-mesa-dev via sudo apt install --reinstall libgl1-mesa-dev, made sure I have libGL.so.1 installed in my /usr/lib/x86_64-linux-gnu/mesa directory and I have run sudo ldconfig to no avail.
I'm not sure what is causing this and I haven't seen this problem anywhere else. It seems to be a dependency I'm ignoring, however I installed Qt using sudo apt install qt5-default so I would think the dependencies would be handled.
Here's my CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
project(SimpleQt)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets CONFIG REQUIRED)
include_directories(include)
add_executable(SimpleQt src/main.cpp)
target_link_libraries(growth Qt5::Widgets)
I figured out a way to make it work thanks to Ripi2 in the comments. Apparently I had to link OpenGL with my project. Here's my updated CMakeLists.txt:
cmake_minimum_required(VERSION 2.6)
project(SimpleQt)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_AUTOMOC ON)
find_package(OpenGL Required) # Added this line
find_package(Qt5Widgets CONFIG REQUIRED)
include_directories(include ${OPENGL_INCLUDE_DIRS}) # Updated this line
add_executable(SimpleQt src/main.cpp)
target_link_libraries(growth Qt5::Widgets ${OPENGL_LIBRARIES}) # Updated this line
I'm leaving this unanswered though because this is definitely not how it should be. All the examples on Qt's site do not show OpenGL as a link requirement, so I feel there must be a better way.
Hello i installed boost using comand
brew install boost
it installed 1.66.0 version
I edited CMakeLists in this way
cmake_minimum_required(VERSION 3.8)
project(fraction)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp source/Fraction.cpp headers/Fraction.h headers/MyStack.h unitTest.cpp)
add_executable(fraction ${SOURCE_FILES})
set(BOOST_ROOT "/usr/local/Cellar/boost/1.66.0")
find_package(Boost 1.66.0)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
I don't have any error, in file unitTest.cpp I want to write test and I'm trying to include this
#include <boost/test/unit_test.hpp>
but I got error "Cannot find 'boost'"
What I do wrong ?
Ok I find why it doesn't work, brew didn't link boost
on high sierra it should be in this way
if usr/local/include and usr/local/Frameworks don't exist it must be created by
sudo mkdir usr/local/include
sudo mkdir usr/local/Frameworks
after that we can chown usr/local/include by
sudo chown -R $(whoami) $(brew --prefix)/*
Hey im trying to use the OpenCV Lib on elementary OS (based on Ubuntu).
I followed this tutorial:
https://www.youtube.com/watch?v=i1K9rXiei9I
I added this lines to the CmakeList.txt:
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(myOpenCVTest ${OpenCV_LIBS})
But when i build the project it fails with some errors like:
/usr/bin/ld: cannot find -lopencv_core
...
Can anyone help me???
I solved the problem.
First I deleted all old OpenCV files and installations.
After that I followed this guide to install OpenCV and all required packages.
And now everything is working with this CmakeList.txt:
cmake_minimum_required(VERSION 2.8.4)
project(OpenCVTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package( OpenCV REQUIRED )
set(SOURCE_FILES main.cpp)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries( ${PROJECT_NAME} ${OpenCV_LIBS} )
I had to forcefully declare OpenCV_FOUND 1 in the cmake file, The whole file looks like :
cmake_minimum_required(VERSION 3.3)
project(testing)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(OpenCV_FOUND 1)
find_package( OpenCV REQUIRED )
set(SOURCE_FILES main.cpp)
add_executable(testing ${SOURCE_FILES})
target_link_libraries(testing ${OpenCV_LIBS})
(following our chat in the comments section)
I am not sure what video did you use for the installation, but assuming you used cmake based installation you usually run make followed by sudo make install that copies everything to the right location
Alternatively you can add link_directories(home/Projects/opencv/opencv-3/build/lib/)
and include_directories((home/Projects/opencv/opencv-3/include/) to your CMakeLists.txt
I've previous boost installation from ubuntu repo which is 1.42 and its installed in /usr/lib Now I downloaded 1.52 and ./b2 install that installed it in /usr/local/lib. now cmake is detecting 1.52 only and using include Path from /usr/local/include (which is 1.52) and using library directory /usr/lib (which is 1.42) and giving undefined reference errors.
cmake_minimum_required(VERSION 2.6)
PROJECT(app)
set(Boost_USE_MULTITHREADED ON)
FIND_PACKAGE(Boost 1.52 COMPONENTS filesystem program_options thread system serialization REQUIRED)
ADD_EXECUTABLE(app list_of_cpp_files)
MESSAGE(STATUS "** Boost Include: ${Boost_INCLUDE_DIR}")
MESSAGE(STATUS "** Boost Libraries: ${Boost_LIBRARIES}")
TARGET_LINK_LIBRARIES(app ${Boost_LIBRARIES})
if(CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-g -O2")
set(CMAKE_EXE_LINKER_FLAGS "-s")
endif()
even if I give a LIBRARY_PATH in CMakeLists.txt it still uses /usr/lib
What should be done now ? would I do a booststrap.sh --prefix=/usr but wont that make duplicate copies ? also Do I need change all symlinks manually ?
or I'll remove previous installation (1.42) from repo (apt-get) ? I cannot remove all because there are dependant packages.
Solved by doing a ./bjam --layout=tagged install