How to use external library in C++ program

I do not have idea of how to use external libraries in C++ program either in Eclipse or using CMakeLists. This is structure of my project:

HelloProject
-- src
|hello.cpp
|CMakeLists.txt
-- include
-- build
-- CMakeLists.txt

I am able to run simple program. But Now I want to use external libraries such as opencv in my project. To install opencv in C++, I have followed steps from this link: http://www.codebind.com/cpp-tutorial/install-opencv-ubuntu-cpp/

I have opencv installed inside /usr/opt directory.
This is how my main CMakeLists.txt looks:

1
2
3
4
5
6
  cmake_minimum_required (VERSION 2.6)
  project (RandomHello)
  set(CMAKE_CXX_STANDARD 11)
  set(CMAKE_BUILD_TYPE Debug)
  include_directories(include)
  add_subdirectory(src)


Could anyone please help with this?
So you want to use CMake to manage dependencies and generate an Eclipse solution?

I would set the CMAKE_BUILD_TYPE to Release, btw.

Can probably just leverage find_package to detect where it's installed on the system
https://vovkos.github.io/doxyrest-showcase/opencv/sphinx_rtd_theme/page_tutorial_linux_gcc_cmake.html

You need a line for add_library(if you're making a static .lib; add SHARED to make an .so), or add_executable (executables). Then you use that name to link to any libs with target_link_libraries

project will be the name of the solution. As you may know, CMake can generate lots of solutions, e.g. Visual Studio .sln files. In your case to generate an Eclipse solution, you'd first want to descend to your target (build) directory, and then point to the top-level CMakeLists.txt (usually some form of parent directory with "..") file with the correct generator (run cmake help). It'd be something like:

1
2
3
mkdir target
cd target
cmake -G "Eclipse CDT4" ..


Topic archived. No new replies allowed.