Undefined reference to symbol 'gzclose' - c++

I guess this is a linker error, but I've spent a lot of time and haven't find a working answer. I have an OpenCV C++ program, when I try to compile something of the style cv::Mat newMatObject; it gives me the error /usr/local/lib/libopencv_core.a(persistence.cpp.o): undefined reference to symbol 'gzclose'.
The .pro file contains the following lines:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = QtTest
TEMPLATE = app
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_highgui -lz -ltbb -ltiff
SOURCES += main.cpp\
qttest.cpp
HEADERS += qttest.h
FORMS += qttest.ui
Am I forgetting something/doing something wrong?
Some Info:
Kubuntu 16.04 LTS 64 Bits
Qt Creator 4.0.2, based on Qt 5.7.0
OpenCV 2.4.13
Addendum:
I had the program working properly with OpenCV 2.4.9, no other changes. I decided to move on to 2.4.13 because of the extended gui, which didn't work on 2.4.9. I downloaded OpenCV 2.4.13 from the official website, and installed it with this script (except for the wget and unzip, which were made manually), initially didn't autoremove the previous library, but I did after the issue came up and rerun the previous script again, to ensure proper installation.
Edit 1:
Running
g++ -o opencvtest opencvtest.cpp `pkg-config opencv --cflags --libs`
with similar lines of code provides the desired result without a problem.

Add -lz to your LIBS:
LIBS += -L/usr/local/lib -lopencv_core -lopencv_highgui -lz

Related

Linking OpenCV to a shared library "mylib", `undefined reference to ...` errors

I am trying to use OpenCV-2.4.13 shared objects (libopencv_core.so,libopencv_imgproc.so etc.) in mylib.so.
These OpenCV shared objects are compiled and installed with standard build procedure (make, make install) and I confirmed that they are located in /usr/local/lib, they can be used directly with an application without any problem.
I am using Qt 5.8 on Ubuntu 16.04 for building process.
In mylib.so, I use common cv::Mat functions. Looking at the similar questions, I have already skimmed this article, it suggests either using -rpath or -rpath-link options during linking mylib.so with an application. I also did read this article from Qt and applied the suggested method when building mylib.so: adding a a_global.h and defining an export symbol as Q_DECL_EXPORT.
I am providing .pro file for mylib.so below.
QT -= gui
CONFIG += c++11
TARGET = mylib
TEMPLATE = lib
DEFINES += MYLIB_LIBRARY
SOURCES += a.cpp
HEADERS += a.h external_libraries.h a_global.h
unix {
target.path = /usr/lib
INSTALLS += target
}
INCLUDEPATH += "/usr/local/include"
LIBS += -L/usr/local/lib -lopencv_calib3d -lopencv_contrib -lopencv_core\
-lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgproc\
-lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_ocl\
-lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video\
-lopencv_videostab
Also, here is the .pro file for a dummy test application.
QT += core
QT -= gui
CONFIG += c++11
TARGET = apptest
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += "/home/foo/mylib/" #this is where `a.h` is
LIBS += "/home/foo/mylib/build/mylib.so.1.0.0"
QMAKE_CXXFLAGS += "-Wall"
QMAKE_LFLAGS += "-Wl,-rpath-link,/usr/local/lib"
QMAKE_LFLAGS += "-Wl,--unresolved-symbols=ignore-in-shared-libs"
You can see that I am providing /usr/local/lib as the -rpath-link where OpenCV shared objects reside. I am also instructing the linker to ignore unresolved symbols from shared libraries, which is suggested in this question and documented here.
The "right way" according to many sources is not to link OpenCV (or any dependency) in application, because this causes overlinking. In apptest, when I don't link OpenCV, I get the following linker error:
undefined reference to cv::Mat::deallocate()
undefined reference to cv::fastFree(void)
collect2: error: ld returned 1 exit status
Looking at the error, my intuition is, somehow -rpath-link is not doing what it is supposed to do.
I was not able to resolve this, I decided to deliberately link OpenCV with apptest just to see what happens. What happens is awkward: it compiles and links without errors (whether I provide --unresolved-symbols=ignore-in-shared-libs option or not). But when I run the app, it crashes without any exceptions from OpenCV; cv::imread operation does not work as expected, rows and cols of image is zero.
I checked both apptest and mylib.so with readelf -d. Nothing strange occured to me,
mylib.so depends on libQt5Core and libopencv_* and it has the right SONAME entry.
apptest depends on mylib.so,libQt5Core and also libopencv_* when I did the deliberate linking.
I also tried to debug apptest with gdb. Output was not very helpful...
(gdb) r
Starting program:
/home/foo/apptest/build/apptest
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x00007fffffffc9b0 in ?? ()
I assume linking is not done properly, but why? How can I resolve this without having to link OpenCV libs directly in app?

ft2build.h: No such file or directory - Freetype 2.6

I am trying to build from Linux cause I decided to start using Jenkins, my personal work but, even with freetype installed: v.2.6.3, it doens't recognize this ft2build.h.
This is the QT Pro with freetype loaded. I'm now running on UBuntu 16.04:
linux {
message("Build for Linux")
DEFINES += LINUX
DEFINES += BOOST_LOG_DYN_LINK
LIBS += -lGLU
LIBS += -lfreetype
LIBS += -L/usr/lib/x86_64-linux-gnu/-libboost_timer.so -libboost_log.so -libboost_log_setup.so -libboost_system.so -libboost_thread.so -libboost_filesystem.so
}
So i tried to change also the lib pointer doing manually as:
LIBS *= -L/usr/local/lib/ -lfreetype
but still nothing going properly. The error I get is from lGLU
In file included from displays/display.cpp:3:0:
displays/./../oglft/oglft.h:50:22: fatal error: ft2build.h: No such file or directory
compilation terminated.
Makefile:1093: recipe for target 'display.o' failed
I do always run 'qmake make clean' then /usr/lib/x86_64-linux-gnu/qt5/bin/qmake && make && make check to be sure it starts properly. Can someone help me solving the bug?
I've checked where freetype lib is located by doing:
pkg-config --cflags --libs freetype2
and this is what I get
-I/usr/local/include/freetype2 -L/usr/local/lib -lfreetype
PROBLEM SOLVED!
I have had to set FREETYPE in the environment variables as BOOST too and everything is now working properly!
Here is how is mine:
export BOOST=/var/lib/jenkins/workspace/boost_1_59_0
export FREETYPE=/var/lib/jenkins/workspace/freetype-2.6.3
I preferred to move those two libs under Jenkins to avoid permissions problems.
;-)

Undefined reference to boost libraries in QT creator on Windows

I am trying to run a QT project on Windows that I have developed on Linux Ubuntu. Unfortunately, I cannot manage it to properly link the boost library. Here is a detailed description of the problem.
I downloaded MinGW from https://nuwen.net/mingw.html, version 13.5, such that the gcc version 5.3.0 matches the MinGW version of QT. The reason to choose this version of MinGW is that it contains the boost libraries for compression such as zlib. From the command line I compile and run my program without any problems:
g++ -std=c++11 -w -IC:/MinGW/include -LC:/MinGW/lib bAya.cpp A.o B.o C.o -o baya -lboost_iostreams -lz -lbz2
where A,B, C are my pre-compiled object files.
In QT creator I selected the MinGW compiler (C:\MinGW_53\MinGW\bin\g++.exe) and created a new default kit with the compiler.
My .pro file looks as follows:
MAKE_CXXFLAGS += -std=c++11
INCLUDEPATH += C:/MinGW_53/MinGW/include \
C:/Users/kuzk/Documents/src
LIBS += -LC:/MinGW_53/MinGW/lib/mylib \
-lboost_system \
-lboost_iostreams \
-lz \
-lbz2
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES += main.cpp\
mainwindow.cpp \
../src/A.cpp \
../src/B.cpp \
../src/C.cpp
HEADERS += mainwindow.h \
../src/A.h \
../src/B.h \
../src/C.h
The folder C:/MinGW_53/MinGW/lib/mylib contains my .a files such as libboost_iostreams.a
When I build it, I get many undefined reference errors such as
error: undefined reference to `boost::iostreams::zlib::default_strategy'
Interestingly, if C:/MinGW_53/MinGW/lib/mylib contains also libstdc++.a I also get linking errors to std::cout, std::ifstream etc.
I am currently stuck and I will be very helpful for any feedback.
Best,
Konstantin
Adding the library path for boost_iostreams:
-LC:/MinGW/lib \
after the line:
LIBS += -LC:/MinGW_53/MinGW/lib/mylib \
should fix it.
At the end I was able to resolve the problem. Here is what I did. I am using QT 5.7 on Windows 10.
I compiled boost using QT's console as described here: http://cpp-qt-mac-win.blogspot.co.uk/2011/10/qt-boost-for-beginners-step-by-step.html
Then I created a new project and added the paths to boost and the necessary libraries, as described in my question.
An important note. I tried to update the paths in the existing project, by running qmake and then rebuilding the project. I was getting the very same errors as I was getting with the old paths to "standard" boost. Apparently, something was cached and the changes didn't do anything. However, if I give a wrong path to a library it complained. So, QT has very confusing behavior. If someone can explain it, it will be helpful.

Qt Creator cannot find openCV libraries

First of all I know this question has been asked (see here) but those solutions did not work for me.
I am trying to install opencv to use with Qt Creator on ubuntu 14.04.
I followed this tutorial exactly and confirmed that it worked by running the facedetect example.
I then started on this tutorial for using Qt creator with opencv. I followed the steps in the video exactly, however when I build and run the example I get the following errors:
/usr/bin/ld: cannot find -lopencv_core
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_highgui
full compile output:
g++ -Wl,-rpath,/home/tpst/Program_Files/Qt-5.3.1/5.3/gcc_64 -Wl,-rpath,/home/tpst/Program_Files/Qt-5.3.1/5.3/gcc_64/lib -o test main.o -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui -L/home/tpst/Program_Files/Qt-5.3.1/5.3/gcc_64/lib -lQt5Core -lpthread
/usr/bin/ld: cannot find -lopencv_core
/usr/bin/ld: cannot find -lopencv_imgcodecs
/usr/bin/ld: cannot find -lopencv_highgui
collect2: error: ld returned 1 exit status
make: *** [test] Error 1
23:02:50: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project test (kit: Desktop Qt 5.3 GCC 64bit)
When executing step 'Make'
And here is the contents of my .pro file:
QT += core
QT -= gui
TARGET = test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui
SOURCES += main.cpp
I have also tried to compile using terminal and get the same (/usr/bin/ld: cannot find -llib)
I dont understand why Qt cant find the libraries. You can see that they exist in the directory
Some help would be appreciated. I'm new to linux and Qt, I dont really understand the solutions posted to similar questions and have not been able to solve this myself.
afaik your linked libraries must look like libName.so but your libraries are named libName.so.version so the linker doesn't find them. Try to create symbolic links:
ln /usr/local/lib/libopencv_core.so.3.0.0 /usr/local/lib/libopencv_core.so
ln /usr/local/lib/libopencv_imgcodecs.so.3.0.0 /usr/local/lib/libopencv_imgcodecs.so
ln /usr/local/lib/libopencv_highgui.so.3.0.0 /usr/local/lib/libopencv_highgui.so

How do I integrate C++ Boost into a Qt project?

I would like to use boost/filesystem.hpp in my Qt app but the builder keeps saying:
Library not loaded: libboost_filesystem.dylib
Reason: image not found
here is how I try to link it:
INCLUDEPATH+= /installdir/boost_1_50_0
LIBS += -L/installdir/boost_1_50_0/stage/lib -lboost_filesystem
I've tried linking directly, too. I've also tried rebuilding boost according to jschoen's answer, no difference.
Im running a MacOSX Lion. How do I have to link boost properly?
In the meantime I have found a solution.
install boost with macports (sudo port install boost) Thanks to dies and Tim Cooper.
then link against:
INCLUDEPATH += /opt/local/include
LIBS += -L/opt/local/lib
LIBS += -lboost_system-mt -lboost_filesystem-mt