linking to a shared object in Linux
-
wrote on 28 May 2017, 01:22 last edited by mzimmers
Hi -
I'm trying to follow a very simple tutorial on using shared libraries. Unfortunately for me, the author of the tutorial used Windows as his platform, and I'm trying to do this on Linux.
I've created the library, and have moved them into the source directory of my app that is to use the library. When I build, I get this error message:
:-1: error: cannot find -l097sharedlib.so
I've put this line in my .pro file:
LIBS += -L/home/mzimmers/QtStuff/tutorials/098sharedlibuser -l097sharedlib.so
According the wiki, this should work. What might I be doing wrong?
Thanks...
-
Hi -
I'm trying to follow a very simple tutorial on using shared libraries. Unfortunately for me, the author of the tutorial used Windows as his platform, and I'm trying to do this on Linux.
I've created the library, and have moved them into the source directory of my app that is to use the library. When I build, I get this error message:
:-1: error: cannot find -l097sharedlib.so
I've put this line in my .pro file:
LIBS += -L/home/mzimmers/QtStuff/tutorials/098sharedlibuser -l097sharedlib.so
According the wiki, this should work. What might I be doing wrong?
Thanks...
Ordinarily libraries are prefixed on Linux, so a library named
SomeLibrary
will be present on the filesystem aslibSomeLibrary.so
. Whenever you link it through theLIBS
variable you don't specify the prefix nor the suffix, so you'd link as:LIBS += -L/path/to/some/library -lSomeLibrary
-
wrote on 28 May 2017, 02:10 last edited by
Hi, Kshegunov -
Thanks for that; I'd forgotten about that little Linux nauance. Unfortunately, it's still giving me the same error code. Here's the .pro file:
QT += core QT -= gui CONFIG += c++11 TARGET = 098sharedlibuser CONFIG += console CONFIG -= app_bundle LIBS += -L/home/mzimmers/QtStuff/tutorials/098sharedlibuser -l097sharedlib TEMPLATE = app SOURCES += main.cpp # The following define makes your compiler emit warnings if you use # any feature of Qt which as been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 HEADERS += \ _097sharedlib.h \ _097sharedlib_global.h
-
wrote on 28 May 2017, 02:20 last edited by
Oops - disregard my latest message. I'd neglected the "_" at the start of the library name. Now I build OK. Thanks!
1/4