Critical errors with static linking (Bug #591)


Added by Valérie Vallet over 14 years ago. Updated almost 14 years ago.


Status:Done Start date:
Priority:High Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:build/install
Target version:-
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

I have compiled both the official opencv.2.1 and the latest tested SVN trunk with the static library option (-D BUILD_SHARED_LIBS=OFF) and then I try to link a very simple program that displays an image.
I get the following error messages in both cases
/tmpdir/vallet/ccgtPDmv.o: In function @cvDecRefData':
displayimage.c:(.text+0x9f5): undefined reference to @cvFree_'
displayimage.c:(.text+0xa7a): undefined reference to @cvFree_'
/tmpdir/vallet/ccgtPDmv.o: In function @cvGetRow':
displayimage.c:(.text+0xb8b): undefined reference to @cvGetRows'
/tmpdir/vallet/ccgtPDmv.o: In function @cvGetCol':
displayimage.c:(.text+0xbb6): undefined reference to @cvGetCols'
/tmpdir/vallet/ccgtPDmv.o: In function @cvReleaseMatND':
displayimage.c:(.text+0xbcd): undefined reference to @cvReleaseMat'
/tmpdir/vallet/ccgtPDmv.o: In function @cvSubS':
displayimage.c:(.text+0xd3a): undefined reference to @cvAddS'
/tmpdir/vallet/ccgtPDmv.o: In function @cvCloneSeq':
displayimage.c:(.text+0xd70): undefined reference to @cvSeqSlice'
/tmpdir/vallet/ccgtPDmv.o: In function @cvSetNew':
displayimage.c:(.text+0xdd9): undefined reference to @cvSetAdd'
/tmpdir/vallet/ccgtPDmv.o: In function @cvGetSetElem':
displayimage.c:(.text+0xe7d): undefined reference to @cvGetSeqElem'
/tmpdir/vallet/ccgtPDmv.o: In function @cvEllipseBox':
displayimage.c:(.text+0xf78): undefined reference to @cvEllipse'
/tmpdir/vallet/ccgtPDmv.o: In function @cvFont':
displayimage.c:(.text+0xfd6): undefined reference to @cvInitFont'
/tmpdir/vallet/ccgtPDmv.o: In function @cvReadIntByName':
displayimage.c:(.text+0x10e3): undefined reference to @cvGetFileNodeByName'
/tmpdir/vallet/ccgtPDmv.o: In function @cvReadRealByName':
displayimage.c:(.text+0x1194): undefined reference to @cvGetFileNodeByName'
/tmpdir/vallet/ccgtPDmv.o: In function @cvReadStringByName':
displayimage.c:(.text+0x1235): undefined reference to @cvGetFileNodeByName'
/tmpdir/vallet/ccgtPDmv.o: In function @cvReadByName':
displayimage.c:(.text+0x126c): undefined reference to @cvGetFileNodeByName'
displayimage.c:(.text+0x127c): undefined reference to @cvRead'

and even more in the latest trunk version.

Can you please correct compilation of static libraries! I urgently need it to prepare programs to be ported on a computer center.


Associated revisions

Revision c865b282
Added by Andrey Kamaev about 12 years ago

Merge pull request #591 from jet47:gpu-sanity-tests

History

Updated by grzesiek grz over 14 years ago

Confirmed on version SVN 08102010

Updated by anonymous - over 14 years ago

Can somebody fix the problem?

Updated by grzesiek grz over 14 years ago

Good solution , at the moment, seems to be dynamic linking and putting all shared libs to subdirectory with your application.

The you can export LD_LIBRARY_PATH pointing to that directory, what will let you run your application.

You need to copy all necessary libs that differs from those, installed on remote system (libopencv_* along with custom libav* if you app utilises ffmpeg functionality etc.)

Bad news is that, same version of libc is required (you can copy all necessary libraries, except of libc).

Hope this helps.

Updated by Valérie Vallet over 14 years ago

The reason I want to use static linking is because I want to transfer the opencv to a computer center, without having to recompile Opencv.

When I look again at the errors with static, it seems to me that some functions might not be compiled properly. Could that be? Has static linking ever been working in previous versions of opencv? I sincerely wish it could work with the latest version!

Updated by grzesiek grz over 14 years ago

Replying to [comment:4 valerie.vallet]:

The reason I want to use static linking is because I want to transfer the opencv to a computer center, without having to recompile Opencv.

As I said - solutions for this is including shared libs in subfolder and using LD_LIBRARY_PATH. I had same situtation, and it worked for me. Use @ldd binary' to determine what libraries do you need.

This will only work if your libc versions are same on both machines, and of course is you have same architectures.

Updated by Victor Eruhimov over 14 years ago

  • Status deleted (Open)

Updated by Vadim Pisarevsky over 14 years ago

looks like something's wrong with the linker options. You can use CMake with the supplied OpenCVConfig.cmake.in file (that is translated to OpenCVConfig.cmake file by CMake)

  • Status set to Done
  • (deleted custom field) set to worksforme

Updated by Valérie Vallet over 14 years ago

I don't understand your comment. I am using the OpenCVConfig.cmake.in with the _D BUILD_SHARED_LIBS=OFF option.
Why can't I afterwards link with the static library. If you managed, can you detail your procedure?

  • Status changed from Done to Cancelled
  • (deleted custom field) deleted (worksforme)

Updated by Vadim Pisarevsky over 14 years ago

ok, I was wrong, OpenCVConfig.cmake did not support static libs properly. Now (r4281) it should work fine. Build OpenCV in static configuration. Then include OpenCV into your project using find_package(), as shown in https://code.ros.org/svn/opencv/trunk/opencv/samples/c/example_cmake/CMakeLists.txt.
At configuration stage, if it reports errors, set OpenCV_DIR to the OpenCV build directory (it should contain OpenCVConfig.cmake). Then your code should build fine.

  • Status changed from Cancelled to Done
  • (deleted custom field) set to fixed

Updated by Valérie Vallet over 14 years ago

  • Status changed from Done to Cancelled
  • (deleted custom field) deleted (fixed)

Updated by Valérie Vallet over 14 years ago

Still a problem!
I have downloaded the latest revision, compiled the opencv library with
cmake -D BUILD_PYTHON_SUPPORT=OFF -D BUILD_NEW_PYTHON_SUPPORT=OFF -D BUILD_SHARED_LIBS=OFF -D CMAKE_INSTALL_PREFIX=/share/apps ..

I then compile my program with:

gcc -I/share/apps/include/opencv -I/share/apps/include -L/share/apps/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -o $1 $1.c

The linking option beeing obtained from the command pkg-config --cflags --libs opencv

What shall I do to avoid these compilation errors!

====================
Here are the compilation errors! ====================

/tmpdir/vallet/ccuaE8fA.o: In function @cvDecRefData':
displayimage.c:(.text+0x9f5): undefined reference to @cvFree_'
displayimage.c:(.text+0xa7a): undefined reference to @cvFree_'
/tmpdir/vallet/ccuaE8fA.o: In function @cvGetRow':
displayimage.c:(.text+0xb8b): undefined reference to @cvGetRows'
/tmpdir/vallet/ccuaE8fA.o: In function @cvGetCol':
displayimage.c:(.text+0xbb6): undefined reference to @cvGetCols'
/tmpdir/vallet/ccuaE8fA.o: In function @cvReleaseMatND':
displayimage.c:(.text+0xbcd): undefined reference to @cvReleaseMat'
/tmpdir/vallet/ccuaE8fA.o: In function @cvSubS':
displayimage.c:(.text+0xd3a): undefined reference to @cvAddS'
/tmpdir/vallet/ccuaE8fA.o: In function @cvCloneSeq':
d

==================
Here is the sample program ==================

#include "cv.h"
#include "highgui.h"

int main( int argc, char** argv ) {
// cvLoadImage determines an image type and creates datastructure with appropriate size
IplImage* img = cvLoadImage( argvr1, CV_LOAD_IMAGE_ANYDEPTH|CV_LOAD_IMAGE_ANYCOLOR);

// create a window. Window name is determined by a supplied argument
cvNamedWindow( argvr1, CV_WINDOW_AUTOSIZE );
// Display an image inside and window. Window name is determined by a supplied argument
cvShowImage( argvr1, img );
// wait indefinitely for keystroke
cvWaitKey(0);

// release pointer to an object
cvReleaseImage( &img );
// Destroy a window
cvDestroyWindow( argvr1 );
}

Updated by Vadim Pisarevsky over 14 years ago

opencv.pc does not support static linking yet. please, use cmake. On my machine the list of linked libraries is the following (it depends on the configuration, actually):

dl m pthread rt stdc++ gtk-x11-2.0 gdk-x11-2.0 atk-1.0 gio-2.0 pangoft2-1.0 pangocairo-1.0 gdk_pixbuf-2.0 m cairo png12 pango-1.0 freetype fontconfig gobject-2.0 gmodule-2.0 gthread-2.0 rt glib-2.0 gthread-2.0 rt glib-2.0 avcodec avformat avutil swscale dc1394 opencv_core opencv_imgproc opencv_features2d opencv_gpu opencv_calib3d opencv_objdetect opencv_video opencv_highgui opencv_ml opencv_legacy opencv_contrib opencv_flann jpeg png z tiff jasper zlib opencv_lapack

also, I tried to use your list of libs:
gcc ... -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -o $1 $1.c

it reported about many unresolved symbols, but not about cvFree_ etc. It must be something wrong with the generated libopencv_core.a (and possibly other libs).

have you tried dynamic linking? does it work well?

Updated by Vadim Pisarevsky over 14 years ago

  • Status deleted (Cancelled)

Updated by Valérie Vallet over 14 years ago

Compilation with dynamic linking works!
I have now managed using cmake, but I still don't understand why opencv.pc does not support static linking. Could this be changed?

Updated by Vadim Pisarevsky over 14 years ago

great, since you get it working, I lower the priority and mark it as enhancement. We made static linking working through CMake just before the release. opencv.pc will be extended rather soon.

Updated by Alexandre Anoutchine about 14 years ago

@valerie.vallet

Hi, I'm experiencing the same problem. If I get it right you managed to compile your app with the static libraries. So I will really appreciate it if you can explain how you get it work. I'm new to OpenCV. I need compile my application under Linux (Ubuntu) using OpenCV static libraries in order to get it running on other machine.

You said you've managed it get compiled using cmake. What parameters are you using ?

Thanks in advance.

Updated by Alexandre Anoutchine about 14 years ago

Hi, when i'm trying to link opencv statically i'm getting this error:

g++ -Wall -ldl -lm -lpthread -lrt -lstdc++ -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lm -lcairo -lpng12 -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lavcodec -lavformat -lavutil -lswscale -o test main.cpp -I/usr/local/include -I/usr/local/include/opencv -I/usr/local/include/opencv2 /usr/local/lib/libopencv_core.a /usr/local/lib/libopencv_imgproc.a /usr/local/lib/libopencv_features2d.a /usr/local/lib/libopencv_gpu.a /usr/local/lib/libopencv_calib3d.a /usr/local/lib/libopencv_objdetect.a /usr/local/lib/libopencv_video.a /usr/local/lib/libopencv_highgui.a /usr/local/lib/libopencv_ml.a /usr/local/lib/libopencv_legacy.a /usr/local/lib/libopencv_contrib.a /usr/local/lib/libopencv_flann.a /usr/lib/libjpeg.so /usr/lib/libpng.so /usr/lib/libz.so /usr/lib/libtiff.so /usr/lib/libjasper.so /usr/lib/libjpeg.so /usr/local/share/opencv/3rdparty/lib/libzlib.a /usr/local/share/opencv/3rdparty/lib/libopencv_lapack.a

/usr/local/lib/libopencv_highgui.a(loadsave.o): In function @cv::imdecode_(cv::Mat const&, int, int, cv::Mat*)':
loadsave.cpp:(.text._ZN2cvL9imdecode_ERKNS_3MatEiiPS0_+0x217): warning: the use of @tmpnam' is dangerous, better use @mkstemp'
/usr/local/lib/libopencv_highgui.a(window_gtk.o): In function @cvImageWidgetSetImage(_CvImageWidget*, void const*)':
window_gtk.cpp:(.text._Z21cvImageWidgetSetImageP14_CvImageWidgetPKv+0x79): undefined reference to @cvResize'
/usr/local/lib/libopencv_highgui.a(window_gtk.o): In function @cvImageWidget_size_allocate(_GtkWidget*, _GdkRectangle*)':
window_gtk.cpp:(.text._ZL27cvImageWidget_size_allocateP10_GtkWidgetP13_GdkRectangle+0xef): undefined reference to @cvResize'
collect2: ld returned 1 exit status

What's going wrong ? Do you have any idea ? Thanks in adavnce !

Updated by Vadim Pisarevsky almost 14 years ago

OpenCV static libs together with the samples build fine in SVN trunk. I believe, the above command is incorrect. "-l" option should be used to link libraries, and the library path should be passed using "-L" option.

g++ -Wall -ldl -lm -lpthread -lrt -lstdc++ -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lm -lcairo -lpng12 -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lgthread-2.0 -lrt -lglib-2.0 -lavcodec -lavformat -lavutil -lswscale -o test main.cpp -I/usr/local/include -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib -lopencv_core -lopencv_imgproc ...
  • Status set to Done
  • (deleted custom field) set to worksforme

Also available in: Atom PDF