Undefined reference to symbol 'gzclose'

9.3k Views Asked by At

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.

1

There are 1 best solutions below

6
On

Add -lz to your LIBS:

LIBS += -L/usr/local/lib -lopencv_core -lopencv_highgui -lz