Can't generate shared library on ubuntu and can't link statically to a static library
-
Hi all,
I started a new project in Qt creator and chose c++ library and from it dynamic library on ubuntu when I build the project I end up with .a file not .so can anybody explain to me what I am doing wrong ?second problem is that when I try to link the shared library against a static library through add library it appears as it will link statically as wanted and it build without any error but the deployed shared library is much smaller than the static library and when I test it using another program it throws an error of no definition of static library's class and functions.
Any help would be greatly appreciated.
Thanks in advance. -
Can you share the relevant parts of your .pro files for both issues you mention?
-
Thanks for the fast reply , here are the .pro files :
shared library .pro :
#------------------------------------------------- # # Project created by QtCreator 2018-12-11T23:18:12 # #------------------------------------------------- QT -= gui TARGET = DLLtest TEMPLATE = lib DEFINES += DLLTEST_LIBRARY # The following define makes your compiler emit warnings if you use # any feature of Qt which as been marked as 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 SOURCES += dlltest.cpp HEADERS += dlltest.h\ dlltest_global.h unix { target.path = /usr/lib INSTALLS += target } unix:!macx: LIBS += -L$$PWD/../build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/ -lStaticTest INCLUDEPATH += $$PWD/../StaticTest DEPENDPATH += $$PWD/../StaticTest unix:!macx: PRE_TARGETDEPS += $$PWD/../build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/libStaticTest.aStatic library .pro :
#------------------------------------------------- # # Project created by QtCreator 2018-12-12T01:26:48 # #------------------------------------------------- QT -= gui TARGET = StaticTest TEMPLATE = lib CONFIG += staticlib # The following define makes your compiler emit warnings if you use # any feature of Qt which as been marked as 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 SOURCES += statictest.cpp HEADERS += statictest.h unix { target.path = /usr/lib INSTALLS += target }Test program .pro :
QT += core QT -= gui CONFIG += c++11 TARGET = test CONFIG += console CONFIG -= app_bundle 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 unix:!macx: LIBS += -L$$PWD/./ -lDLLtest INCLUDEPATH += $$PWD/../DLLtest DEPENDPATH += $$PWD/../DLLtest -
Hm, code looks good to be honest.
@Mohammedbie said in Can't generate shared library on ubuntu and can't link statically to a static library:
unix:!macx: LIBS += -L$$PWD/../build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/ -lStaticTest
Is there a .a in that folder? Perhaps you need to link specifically to .a and not use the general
-lflag. -
tried adding the following line with the same result :
LIBS += /home/softlock/build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/libStaticTest.a -
tried adding the following line with the same result :
LIBS += /home/softlock/build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/libStaticTest.a@Mohammedbie said in Can't generate shared library on ubuntu and can't link statically to a static library:
tried adding the following line with the same result :
LIBS += /home/softlock/build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/libStaticTest.aSorry I should have been more specific. You can provide full path to
-lflag:LIBS += -l/home/softlock/build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/libStaticTest.aOr, another option is to use the file name specifier:
unix:!macx: LIBS += -L$$PWD/../build-StaticTest-Desktop_Qt_5_8_0_GCC_64bit-Debug/ -l:libStaticTest.aStill, I don't know if that'll work.
-
Tried both with the same result too.
-
something I didn't mention as I didn't think it was related , I build the shared library with Qt static library which I built from sources .
Now when I try to build the shared library with the same version of Qt but dynamic it builds and generates .so file and the test application runs normally.
What might cause this ? -
something I didn't mention as I didn't think it was related , I build the shared library with Qt static library which I built from sources .
Now when I try to build the shared library with the same version of Qt but dynamic it builds and generates .so file and the test application runs normally.
What might cause this ?@Mohammedbie said in Can't generate shared library on ubuntu and can't link statically to a static library:
something I didn't mention as I didn't think it was related , I build the shared library with Qt static library which I built from sources .
Now when I try to build the shared library with the same version of Qt but dynamic it builds and generates .so file and the test application runs normally.
What might cause this ?Hm, not sure but maybe your Qt config or mkspecs leak into definitions of your project when qmake is run.
Try adding this in your shared lib .pro file:
CONFIG -= staticlib CONFIG += shared -
Thank you very much .
This solved it. -
@sierdzio sorry for bothering you but one last thing how to convert those lines to a cmake line ?
Thanks in advance
-
@sierdzio sorry for bothering you but one last thing how to convert those lines to a cmake line ?
Thanks in advance
@Mohammedbie said in Can't generate shared library on ubuntu and can't link statically to a static library:
@sierdzio sorry for bothering you but one last thing how to convert those lines to a cmake line ?
Thanks in advance
No idea, I don't know cmake well enough.
-
Ok thanks.
-
Hi,
You set that in the call to add_library.
-
Hi ,
what I understood from cmake documentation is that add_library() configure the current project as a library and don't add an external library what I used instead was target_link_libraries() and it did the job indeed. -
Ok, from you .pro file it looked like you were generating libraries.