Kamoski
Kamoski

Reputation: 31

Error while running exe builded with cmake

I'm discovering OpenCV v4.1. I downloaded ready to go build version, and unpacked it into my C drive. I'm using VS studio 16 along with cmake to build project. I generate files using Ninja.

That's how my cmake looks like atm:

cmake_minimum_required (VERSION 3.8)

add_executable (opencv-fun "opencv-fun.cpp" "opencv-fun.h")

target_link_libraries(opencv-fun "path_to_lib_folder/opencv_world410d.lib")

Here's the error I'm getting:

"The code execution cannot proceed because opencv_world410d.lib was not found. Reinstalling [...]"

I'v already tried putting env variables in system path, copying lib to source folder, i've also used:

link_library("path")

Also i changed generator to VS one, that didn't help neither.

What's funny about all of that is fact that i can run my program in CMD, and it's running perfectly well. Error occurs only when i try to debug in visual studio.

EDIT: OS: Windows 10

EDIT 2: I had to be really tired cuz it was a .dll not .lib problem just as @PiotrK warned me. Sorry for calling out with such stupid problem. Thanks for answers guys. Just copy-pasting dll into exe directory solved a problem. Is there more clean way to link .dll so that i don't need to copy-paste it?

Upvotes: 0

Views: 161

Answers (2)

PiotrK
PiotrK

Reputation: 4453

Judging from the discussion, the problem is not with compilation but with execution.

I am really curious why you get .lib and not .dll problem, but let us leave it for now.

Right click project in Visual Studio -> Properties -> Debugging -> Working Directory and specify full path to executable (ommiting the executable itself).

Save it and try again

Upvotes: 0

Shayan
Shayan

Reputation: 2471

You can use the find_package() and set() functions to specify the path of your opencv directory and include the directories.

This is what my CMake looks like in Ubuntu.

cmake_minimum_required(VERSION 3.5)
project(test)

set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11 -O3")
set(OpenCV_DIR /home/shayan/opencv-4.1.0/local/share/OpenCV)

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(test main.cpp)
target_link_libraries(test ${OpenCV_LIBS}) 

Upvotes: 1

Related Questions