Ask Your Question
0

Ubuntu 12.04 64 bit gcc linking problem with static openCV libraries

asked 2014-01-18 03:02:20 -0600

erotavlas gravatar image

updated 2014-01-18 03:07:55 -0600

berak gravatar image

Hi,

I'm trying to compile my code in static way. I know that gcc is able to do that with the flag -static and that the only thing that I need is the static version of all the library (.a). I installed openCV following the official guide of Ubuntu https://help.ubuntu.com/community/OpenCV and I installed the latest available version of openCV 2.4.8. The only thing that I changed is the flag that enables static compilation -DBUILD_SHARED_LIBS=OFF.

Now I have problem about the compilation of my code. During the linking phase, the linker is not able to find some library even if the library are present in their paths. My command is this

g++ -static example.cpp -L/usr/local/lib -lopencv_highgui -lopencv_imgproc -lopencv_core -o example

The code of the example is taken from the website of Ubuntu https://help.ubuntu.com/community/OpenCV. It works in case of shared compilation.

[CODE] include<opencv2 highgui="" highgui.hpp=""> int main() { IplImage* img = cvLoadImage("/home/USER/Pictures/python.jpg",CV_LOAD_IMAGE_COLOR); cvNamedWindow("opencvtest",CV_WINDOW_AUTOSIZE); cvShowImage("opencvtest",img); cvWaitKey(0); cvReleaseImage(&img); return 0; } [/CODE]

The message that I receive from the linker is very long, I reported only the first error:

/usr/local/lib//libopencv_highgui.a(window_QT.cpp.o): In function GuiReceiver::~GuiReceiver()': window_QT.cpp:(.text._ZN11GuiReceiverD2Ev+0x49): undefined reference toQObject::~QObject()' window_QT.cpp:(.text._ZN11GuiReceiverD2Ev+0x3e): undefined reference to QObject::~QObject()' /usr/local/lib//libopencv_highgui.a(window_QT.cpp.o): In functionCvWinModel::~CvWinModel()': window_QT.cpp:(.text._ZN10CvWinModelD2Ev[_ZN10CvWinModelD5Ev]+0x19): undefined reference to QWidget::~QWidget()' /usr/local/lib//libopencv_highgui.a(window_QT.cpp.o): In functionCvWinModel::~CvWinModel()': window_QT.cpp:(.text._ZN10CvWinModelD0Ev[_ZN10CvWinModelD0Ev]+0x1d): undefined reference to QWidget::~QWidget()' /usr/local/lib//libopencv_highgui.a(window_QT.cpp.o): In functionOpenGlViewPort::sizeHint() const': window_QT.cpp:(.text._ZNK14OpenGlViewPort8sizeHintEv+0x21): undefined reference to QWidget::sizeHint() const' /usr/local/lib//libopencv_highgui.a(window_QT.cpp.o): In functionCvWindow::keyPressEvent(QKeyEvent)': window_QT.cpp:(.text._ZN8CvWindow13keyPressEventEP9QKeyEvent+0x14): undefined reference to QTest::keyToAscii(Qt::Key)' window_QT.cpp:(.text._ZN8CvWindow13keyPressEventEP9QKeyEvent+0x27): undefined reference toQKeyEvent::modifiers() const' window_QT.cpp:(.text._ZN8CvWindow13keyPressEventEP9QKeyEvent+0x3f): undefined reference to QMutex::lock()' window_QT.cpp:(.text._ZN8CvWindow13keyPressEventEP9QKeyEvent+0x4e): undefined reference toQMutex::unlock()' window_QT.cpp:(.text._ZN8CvWindow13keyPressEventEP9QKeyEvent+0x5a): undefined reference to QWaitCondition::wakeAll()' window_QT.cpp:(.text._ZN8CvWindow13keyPressEventEP9QKeyEvent+0x65): undefined reference toQWidget::keyPressEvent(QKeyEvent)' window_QT.cpp:(.text._ZN8CvWindow13keyPressEventEP9QKeyEvent+0x7c): undefined reference to QKeyEvent::nativeVirtualKey() const' /usr/local/lib//libopencv_highgui.a(window_QT.cpp.o): In functionOpenGlViewPort::setSize(QSize)': window_QT.cpp:(.text._ZN14OpenGlViewPort7setSizeE5QSize+0x5): undefined reference to QWidget::updateGeometry()' /usr/local/lib//libopencv_highgui.a(window_QT.cpp.o): In functionOpenGlViewPort::~OpenGlViewPort()': window_QT.cpp:(.text._ZN14OpenGlViewPortD2Ev+0x28): undefined reference to QGLWidget::~QGLWidget()' /usr/local/lib//libopencv_highgui.a(window_QT.cpp.o): In functionOpenGlViewPort::makeCurrentOpenGlContext()': window_QT.cpp:(.text._ZN14OpenGlViewPort24makeCurrentOpenGlContextEv+0x1): undefined reference to QGLWidget::makeCurrent()' /usr/local/lib//libopencv_highgui.a(window_QT.cpp.o): In functionOpenGlViewPort::updateGl()': window_QT.cpp:(.text._ZN14OpenGlViewPort8updateGlEv+0x1): undefined reference to `QGLWidget::updateGL()'

I think that the problem is the order in which I pass the libraries to the linker ... (more)

edit retag flag offensive close merge delete

Comments

you're not linking any Qt libs.

(the 'dynamic' version of opencv_highgui would do this automaically, but now, that you're linking statically, you have to do that on your own)

berak gravatar imageberak ( 2014-01-18 03:11:07 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
-1

answered 2014-01-18 18:43:47 -0600

keghn gravatar image

updated 2014-01-18 18:45:22 -0600

Hello.

g++ pro.cpp -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -lopencv_core -lopencv_ml -lopencv_features2d -lopencv_objdetect -lopencv_flann -lopencv_video -lopencv_highgui -o pro

It was a BBBBEEEEEiiiiiiiCCCCHHHHH installing then is was a nightmare compiling code. cmake install cmake to compile code. Cmake dose not work that well!!!!!!!!!!!!!!!!!!!!!!!!!!! for anything!!!!!

I use this to compile my code:

    "g++ p.cpp -o p `pkg-config --cflags --libs opencv`"

This web site help allot:

http://stackoverflow.com/questions/15320267/package-opencv-was-not-found-in-the-pkg-config

Could not find my .bash_profile so I just type the each line into the terminal:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig

export PKG_CONFIG_PATH

I run it with:

./pro

or if i am to supply an image:

./pro butterfly.jpg

#include <opencv2/objdetect/objdetect.hpp>

#include <opencv2/highgui/highgui.hpp>

#include <opencv2/imgproc/imgproc.hpp>

#include <opencv/highgui.h>

#include <ostream>

#include <stdio.h>

#include <stdlib.h>

using namespace cv;

using namespace std;

In old code i replace includes with the above and it work fine and as well with the new stuff.

Good luck,

keghn

edit flag offensive delete link more

Comments

your sloppy answer has got nothing to do with the problem

berak gravatar imageberak ( 2014-01-19 03:37:03 -0600 )edit

Question Tools

Stats

Asked: 2014-01-18 03:02:20 -0600

Seen: 1,960 times

Last updated: Jan 18 '14