Ask Your Question

Revision history [back]

Ubuntu 12.04 64 bit gcc linking problem with static openCV libraries

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 but I'm not able to figure out where is the problem. In particular I verified in the file pkg_config/opencv.pc that the order of the library of openCV is correct.

Any suggestions?

click to hide/show revision 2
retagged

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

berak gravatar image

Ubuntu 12.04 64 bit gcc linking problem with static openCV libraries

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 but I'm not able to figure out where is the problem. In particular I verified in the file pkg_config/opencv.pc that the order of the library of openCV is correct.

Any suggestions?