Ask Your Question
0

newbie dnn module problem with c++

asked 2018-07-03 02:49:30 -0600

holger gravatar image

updated 2018-07-03 03:11:36 -0600

berak gravatar image

Hello,

I compiled and installed opencv 3.4.1. When i write a small c++ program which reads in a torch model, it fails compiling with

CMakeFiles/nettest.dir/nettest.cpp.o: In function `main':
nettest.cpp:(.text+0x46): undefined reference to `cv::dnn::experimental_dnn_v4::readNetFromTorch(cv::String const&, bool)'
nettest.cpp:(.text+0x8b): undefined reference to `cv::dnn::experimental_dnn_v4::Net::~Net()'
nettest.cpp:(.text+0xc7): undefined reference to `cv::dnn::experimental_dnn_v4::Net::~Net()'
CMakeFiles/nettest.dir/nettest.cpp.o: In function `cv::String::String(char const*)':
nettest.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x54): undefined reference to `cv::String::allocate(unsigned long)'
CMakeFiles/nettest.dir/nettest.cpp.o: In function `cv::String::~String()':
nettest.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
collect2: error: ld returned 1 exit status
CMakeFiles/nettest.dir/build.make:94: recipe for target 'nettest' failed

The code:

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/dnn.hpp"
#include <math.h>
#include <iostream>
using namespace cv;
using namespace std;
using namespace dnn;

int main( int argc, char** argv)
{
  Net net = readNetFromTorch("openface.nn4.small2.v1.t7");  
  cout << "main" << endl;
  return 0;
}

Did i made something wrong during compiling / installing opencv or is there a stupid mistake in my program? Thank you very much + Greetings, Holger

edit retag flag offensive close merge delete

Comments

hi there, those are all linker errors. (missing opencv libs, your code is ok.)

could you add your CMakeLists.txt ? (there's probably something missing there)

berak gravatar imageberak ( 2018-07-03 03:00:19 -0600 )edit

Hello, here is my build file

cmake_minimum_required(VERSION 2.8)
project( nettest )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( nettest nettest.cpp )
holger gravatar imageholger ( 2018-07-03 03:04:36 -0600 )edit

you could also try to skip cmake, and simply compile it from the cmdline:

g++ my.cpp -lopencv_core -lopencv_dnn -lopencv_highgui -lopencv_imgcodecs -o myprog
berak gravatar imageberak ( 2018-07-03 03:06:16 -0600 )edit

I tried invoking the compile directly with your arguments, its compiling! But when i execute it - i get:

./nettest: error while loading shared libraries: libopencv_core.so.3.4: cannot open shared object file: No such file or directory

I think i should taker some steps back and get open cv running correctly first before trying the dnn module. Thank you for helping my recognizing that my setup is xxx.

holger gravatar imageholger ( 2018-07-03 03:15:12 -0600 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2018-07-03 03:09:41 -0600

berak gravatar image

there is a sample cmake project here , that you could use.

and indeed, your CmakeLists.txt is missing the last line (the one, that adds the opencv libs !)

# Link your application with OpenCV libraries
target_link_libraries(nettest ${OpenCV_LIBS})
edit flag offensive delete link more

Comments

1

Wow! Well that's what you mean with "those are all linker errors". I thought i followed every step from https://docs.opencv.org/3.4/db/df5/tu...

But i missed the last line putting my hands on head. Thank you very much for helping me - it would have taken literally hours for me to find the problem and fix it. Closing as fixed.

holger gravatar imageholger ( 2018-07-03 03:19:16 -0600 )edit

@berak Btw: Can you recommend me a good c++ ide for linux? On Windows i was using VisualStudio 2015.

P.S Please don't say vi or emacs or gedit XD

holger gravatar imageholger ( 2018-07-03 04:46:44 -0600 )edit

hehe, wrong person to ask (using sublime for anything i need) ;)

codebloxx was simple & ok.

berak gravatar imageberak ( 2018-07-03 04:59:47 -0600 )edit

Thank you! I heard codebloxx before, a friend of me (game developer) was once talking about it. But i didn't listened at that time because i was focused on java / not interested. I will give it a try!

I used sublime on a mac some time ago. Well its a text editor with syntax highlighting. Respect to the purists out there ^^.

holger gravatar imageholger ( 2018-07-03 05:08:08 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-07-03 02:49:30 -0600

Seen: 3,271 times

Last updated: Jul 03 '18