1

I'got a problem with compiling linking of a program with multiple files by g++ (I usually use vstudio, but...).

  1. If I use only main.cpp (and include appropriate header files for openCV), everything is ok with

    g++ main.cpp -o main  -I"C:\OpenCV2.1\include\opencv" -L"C:\OpenCV2.1\lib" 
    -lcxcore210 -lcv210 -lhighgui210
    
  2. If I have main.cpp and some otherfile.cpp (both need openCV) and use

    g++ main.cpp otherfile.cpp -o main  -I"C:\OpenCV2.1\include\opencv" 
    -L"C:\OpenCV2.1\lib" -lcxcore210 -lcv210 -lhighgui210
    

    it simply doesn't work and I got

    c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: a
    uto-importing has been activated without --enable-auto-import specified on the c
    ommand line.
    This should work unless it involves constant data structures referencing symbols
     from auto-imported DLLs.
    C:\Users\ONDEJM~1\AppData\Local\Temp\ccNisCoC.o:main.cpp:(.text+0x16d0): undefin
    ed reference to `cv::Mat::Mat(_IplImage const*, bool)'
    C:\Users\ONDEJM~1\AppData\Local\Temp\ccNisCoC.o:main.cpp:(.text+0x16f1): undefin
    ed reference to `cv::FAST(cv::Mat const&, std::vector<cv::KeyPoint, std::allocat
    or<cv::KeyPoint> >&, int, bool)'
    C:\Users\ONDEJM~1\AppData\Local\Temp\ccNisCoC.o:main.cpp:(.text$_ZN2cv3Mat7relea
    seEv[cv::Mat::release()]+0x3f): undefined reference to `cv::fastFree(void*)'
    collect2: ld returned 1 exit status
    

What am I doing wrong?

morph
  • 61
  • 1
  • 7
  • 2
    This is a linking problem rather than a compilation problem. Have you tried compiling main.cpp and otherfile.cpp separately then linking the resulting .o files together? Does this affect the error at all? – Dan Jul 10 '11 at 14:29
  • yes, I tried. Compiling of both files separately is not a problem, however, building them together returns the same error – morph Jul 10 '11 at 14:38
  • See the related http://stackoverflow.com/questions/1095298/gcc-c-linker-errors-undefined-reference-to-vtable-for-xxx-undefined-referen/1095321#1095321 for more info on this – jonsca Jul 10 '11 at 15:14
  • tried to change the order of -l, however didn't help :( – morph Jul 10 '11 at 16:09

2 Answers2

0

Pass "-Wl,--enable-auto-import" to g++. Read ld's documentation about this.

LeleDumbo
  • 9,192
  • 4
  • 24
  • 38
0

Hm, it seems that I made a silly mistake... solution is simple: just recompile all openCV binarries by g++ and everything will be ok!

morph
  • 61
  • 1
  • 7