1

I want to add new method in OpenCV library. I made my_funct.cpp whose code is as simple as:

#include "precomp.hpp" #include <stdio.h> void cv::my_funct(){ printf("%s\n","Hello world!"); }

and I added header CV_EXPORTS_W void my_funct(); to files C:\opencv\build\include\opencv2\imgproc\imgproc.hpp and C:\opencv\sources\modules\imgproc\include\opencv2\imgproc\imgproc.hpp. Then I used CMake to build new binaries for whole library, but when I make a new project in which I use my_funct() I get an error:

The procedure entry point _ZN2cv8my_functEv could not be located in the dynamic link library path_to_this_project\project.exe.

Other opencv functions work just fine. I'm using mingw32 to compile library and the version of OpenCV is 2.4.9. Can you tell me what am I doing wrong?

Curious
  • 154
  • 1
  • 8
  • How is this question related to CMake? Please clarify or remove the tag. – usr1234567 Dec 07 '15 at 12:54
  • I'm using it to generate build files. So I thought that, maybe, I should do something different than usual in this case and that someone who is more familiar with this program can help me. – Curious Dec 07 '15 at 13:23
  • The CMake tag made me look at the question, I don't like to see non-CMake problems, just because people wrongly tag their question. – usr1234567 Dec 07 '15 at 14:07
  • Well, I don't know what I am doing wrong during this procedure in which I use CMake, so I put that tag in case there is something I need to do differently in CMake part. I know that it's not likely, but I'm not 100% sure. I agree that this may not be CMake problem, but it is definitely CMake related question. I'm new here so I might have misunderstood on how to use tags. – Curious Dec 07 '15 at 14:49
  • @usr1234567 It seems indeed that this problem is related to cmake, as the my_funct.cpp code is seemingly not compiled and not included in the library generated. – Antonio Dec 07 '15 at 16:31
  • 1
    @Curious, why don't you simply append your code to any of the files in opencv\modules\imgproc\src? – Antonio Dec 07 '15 at 16:34
  • If it was a CMake issue, we cannot find it without some (changed) CMake code. – usr1234567 Dec 07 '15 at 17:10
  • I've done that and I'm still getting same error. – Curious Dec 07 '15 at 19:53

1 Answers1

1

This looks like an MinGW run-time error. So going by the assumption that you didn't get any compiler or linker errors while building project.exe, your executable most likely doesn't find the matching .dll to your .dll.a import library (which must have included the my_funct() definition).

I would recommend during developments phase - not talking about the install() scripting - to add a post-build step using add_custom_command() and generator expressions to copy the right DLL next to your project.exe:

add_custom_command(
    TARGET project
    POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy  
                     "<... path to matching DLL ...>" 
                     "$<TARGET_FILE_DIR:project>"
)

Certainly you could also let CMake find the matching DLL, but before I could go into details there I would need to see your project.exe CMake script.

Maybe also good idea - if you are in the process of extending OpenCV code - would be to use ExternalProject_Add() to include OpenCV into your project.

References

Community
  • 1
  • 1
Florian
  • 39,996
  • 9
  • 133
  • 149