How to build .so files from existing C++ app using Qt Creator
-
I know how to create Shared Library using New Project / .. notation
but how to make the same using existing project, it must be some flags/commands in Projects/Build/Run settings
Please share the instructions
-
@JacobNovitsky Do you mean you want to change a project which builds to an executable so that a shared library is created instead?
You need to change pro or CMakeLists.txt file of that project. You can simply compare it with a project which generates a shared library. -
In my shared library pro file there are following lines:
CONFIG -= qt TEMPLATE = lib DEFINES += SHARED_LIBRARY CONFIG += c++17 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ Shared.cpp HEADERS += \ shared_global.h \ Shared.h # Default rules for deployment. unix { target.path = /usr/lib } !isEmpty(target.path): INSTALLS += target
What should I do in .pro file of project I want to build to .so files?
I can suppose that I need to create global shared_global.h analog for each class (header) I have?if so, should I make it manually or you have tool to make it automatically
-
@JacobNovitsky you are already using the lib template so it should build a library. You don't need one
xxxx_globals.h
per classe. It's a header that exists once per module. -
@JacobNovitsky the project you are showing here already creates a library. That is the result you will get when compiling it.
So what exactly is your issue ?
-
@SGaist
I'm trying to make .so file using this pro file for new C++ projectTEMPLATE = lib
CONFIG += c++17
CONFIG -= app_bundle
CONFIG -= qtSOURCES +=
TestClass.cppHEADERS +=
TestClass.hSet the target type to shared
CONFIG += shared
Set the output directory for the shared library
DESTDIR = /home/j/
TARGET = $$DESTDIR/libTestLib.soit builds, but there is no .so file
upd: this pro file version made these dirs and its contains
j@j-BOHB-WAX9:~/testNewLib-Debug/shared-LIB/shared-LIB$ ls
liblibTestLib.so.so liblibTestLib.so.so.1.0
liblibTestLib.so.so.1 liblibTestLib.so.so.1.0.0TEMPLATE = lib CONFIG += c++17 CONFIG -= app_bundle CONFIG -= qt SOURCES += \ TestClass.cpp HEADERS += \ TestClass.h # Set the target type to shared CONFIG += shared # Set the output directory for the shared library DESTDIR = shared-LIB TARGET = $$DESTDIR/libTestLib.so
-
@JacobNovitsky
TARGET
should just contain the name of the library. Nothing else. No prefix, no suffix.