External Compiled Library Linking Issue: Undefined Reference

asked 2018-04-02 20:03:33 +0200

m3x1m0m gravatar image

updated 2018-04-06 00:37:40 +0200

I am not getting anywhere trying to link my code, that uses libcurlpp in Qt Creator. The individual object files are being created, but the linking fails, because of undefined references to libcurlpp:

https://gist.github.com/m3x1m0m/9a55d32f5fd77b496032de3760f45d27#file-compile_output-txt-L80

I compiled libcurlpp in the build engine and copied the installation into a subdirectory of the project. I think the project file simply does not configure the linking process correctly. This is the project file (with the rest of the project):

https://github.com/m3x1m0m/testapp/blob/master/cppqml.pro

Relevant part:

# Path to installation of CURLPP
CONFIG(debug,debug|release){ CURLPP_PATH = lib/curlpp-inst-arm }
CONFIG(release,debug|release){ CURLPP_PATH = lib/curlpp-inst-i486 }

QMAKE_LFLAGS += -Wl,-lc -Wl,-lz

# Add libcurl
PKGCONFIG += libcurl

# Add curlpp include files
INCLUDEPATH += $$CURLPP_PATH/include

# Point to library files
LIBS += -L$$PWD/$$CURLPP_PATH/lib/libcurlpp.so

# Static library path
lib.files += $$PWD/$$CURLPP_PATH/lib/libcurlpp.a

# I don't know what this does
lib.path = /usr/share/harbour-test/lib
INSTALLS += lib

What is it I am missing out on? I am thankful for every hint.

EDIT:

Following three trivial steps how I got libcurl in combination with libcurlpp running. In addition, this article was extremely helpful.

  1. Linking properly is ALWAYS done pointing to the place where the shared objects are stored with the -L option assuming gcc is used.
  2. With the -l option gcc is told how the libraries are called, that one wants to link against. The order is crucial here! First -lcurl, then pointing to the other shared objects, then the name -lcurlpp.
  3. In case of shared objects, these need to be deployed, so the code can load the library during runtime. According to the harbour FAQ this has to be taken care of by the developer by copying the .so files to /usr/share/APP_NAME/lib. That only works, if RPM packages are chosen as deployment mode.

This script excerpt is a working draft (not claiming being perfect yet).

# Path to installation of CURLPP
CONFIG(debug,debug|release){ CURLPP_PATH = lib/curlpp-inst-arm }
CONFIG(release,debug|release){ CURLPP_PATH = lib/curlpp-inst-i486 }

# Add curlpp include files
INCLUDEPATH += $$CURLPP_PATH/include

# Tell linker to link libcurl first, then libcurlpp
LIBS += -lcurl\
-L$$PWD/$$CURLPP_PATH/lib\
-lcurlpp

# Install file on system
lib.files += $$CURLPP_PATH/lib/libcurlpp.so\
$$CURLPP_PATH/lib/libcurlpp.so.1\
$$CURLPP_PATH/lib/libcurlpp.so.1.0.0

lib.path = /usr/share/$$TARGET/lib
INSTALLS += lib
edit retag flag offensive close delete

Comments

1

See corrected reply regarding libcurl linking

rinigus ( 2018-04-02 20:09:35 +0200 )edit

Yes. Saw it. Changed it. Tested it. No victory :(

m3x1m0m ( 2018-04-02 20:16:56 +0200 )edit
2

Well, you should either let it link with all object files of the library or, package library for SFOS, and link to it as appropriate. What you were doing seems to be halfway mix

rinigus ( 2018-04-02 21:31:52 +0200 )edit

Thank you @rinigus. I bodged something together without having full understanding. Shame.

m3x1m0m ( 2018-04-03 02:55:53 +0200 )edit