How to compile a so file in order to load it as a library.
-
@jenya7 said in How to compile a so file in order to load it as a library.:
PATH_TO_QT_LIB_FOLDER
This was apparently just a placeholder for the real path. It needs to be the folder where libqtcore.so file is located.
See https://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html for example.@jsulm said in How to compile a so file in order to load it as a library.:
@jenya7 said in How to compile a so file in order to load it as a library.:
PATH_TO_QT_LIB_FOLDER
This was apparently just a placeholder for the real path. It needs to be the folder where libqtcore.so file is located.
See https://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html for example.I did a search in all folders
find / libqtcore.so
no such file reported.
What I've managed to find is
/usr/lib/arm-linux-gnueabihf/libQt5Core.so.5
and it's a shortcut file which I can not open. -
@jsulm said in How to compile a so file in order to load it as a library.:
@jenya7 said in How to compile a so file in order to load it as a library.:
PATH_TO_QT_LIB_FOLDER
This was apparently just a placeholder for the real path. It needs to be the folder where libqtcore.so file is located.
See https://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html for example.I did a search in all folders
find / libqtcore.so
no such file reported.
What I've managed to find is
/usr/lib/arm-linux-gnueabihf/libQt5Core.so.5
and it's a shortcut file which I can not open.@jenya7 said in How to compile a so file in order to load it as a library.:
and it's a shortcut file which I can not open
Why do you want to open it?
Did you try:g++ -fPIC -shared -o mylib.so mylib.o -L/usr/lib/arm-linux-gnueabihf -lQt5Core
?
Are you on ARM platform or are you doing cross compilation? -
@jenya7 said in How to compile a so file in order to load it as a library.:
and it's a shortcut file which I can not open
Why do you want to open it?
Did you try:g++ -fPIC -shared -o mylib.so mylib.o -L/usr/lib/arm-linux-gnueabihf -lQt5Core
?
Are you on ARM platform or are you doing cross compilation?@jsulm said in How to compile a so file in order to load it as a library.:
@jenya7 said in How to compile a so file in order to load it as a library.:
and it's a shortcut file which I can not open
Why do you want to open it?
Did you try:g++ -fPIC -shared -o mylib.so mylib.o -L/usr/lib/arm-linux-gnueabihf -lQt5Core
?
Are you on ARM platform or are you doing cross compilation?It's Raspberry Pi - Debian. Qt installed on board and I build directly on board.
-
@jsulm said in How to compile a so file in order to load it as a library.:
@jenya7 said in How to compile a so file in order to load it as a library.:
and it's a shortcut file which I can not open
Why do you want to open it?
Did you try:g++ -fPIC -shared -o mylib.so mylib.o -L/usr/lib/arm-linux-gnueabihf -lQt5Core
?
Are you on ARM platform or are you doing cross compilation?It's Raspberry Pi - Debian. Qt installed on board and I build directly on board.
-
@jsulm said in How to compile a so file in order to load it as a library.:
@jenya7 Then -lQt5Core should be enough, no need for -L
Thank you.
g++ -fPIC -shared -o mylib.so mylib.o -L/usr/lib/arm-linux-gnueabihf -lQt5Core
It works. Now it's quit a nightmare - it's like a chain reaction - demands more and more dependencies. I include each time, hope it'll come till the end eventually. My command line string takes the full screen already. -
@jsulm said in How to compile a so file in order to load it as a library.:
@jenya7 Then -lQt5Core should be enough, no need for -L
Thank you.
g++ -fPIC -shared -o mylib.so mylib.o -L/usr/lib/arm-linux-gnueabihf -lQt5Core
It works. Now it's quit a nightmare - it's like a chain reaction - demands more and more dependencies. I include each time, hope it'll come till the end eventually. My command line string takes the full screen already. -
@jenya7 You should use a proper build system like QMake or CMake instead of hacking around with all these manually...
-
@jsulm
One dependence I can't resolve - undefined symbol: _ZN7QAction16staticMetaObjectE
Where could it be - QAction - is it a separate library?@jenya7 If you go to https://doc.qt.io/qt-6/qaction.html you will see what Qt module it is (hint: qmake: QT += gui)
-
@jenya7 If you go to https://doc.qt.io/qt-6/qaction.html you will see what Qt module it is (hint: qmake: QT += gui)
@jsulm said in How to compile a so file in order to load it as a library.:
@jenya7 If you go to https://doc.qt.io/qt-6/qaction.html you will see what Qt module it is (hint: qmake: QT += gui)
sorry to bother but I included
-L/usr/lib/arm-linux-gnueabihf/ -lQt5Gui
and QAction is good now but I get
undefined symbol: _ZN12QActionGroup16staticMetaObjectE
but I see QAction and QActionGroup in the same library (QT += gui)
Do I miss some lib? -
@jsulm said in How to compile a so file in order to load it as a library.:
@jenya7 If you go to https://doc.qt.io/qt-6/qaction.html you will see what Qt module it is (hint: qmake: QT += gui)
sorry to bother but I included
-L/usr/lib/arm-linux-gnueabihf/ -lQt5Gui
and QAction is good now but I get
undefined symbol: _ZN12QActionGroup16staticMetaObjectE
but I see QAction and QActionGroup in the same library (QT += gui)
Do I miss some lib?@jenya7
Same as before --- you need to look at the doc page! You are now getting an error aboutQActionGroup
instead ofQAction
. So you need to look at theQActionGroup
page for what it tells you you will need to add, just like before. And note that you are using Qt5 so you will need to be careful to look at that documentation, https://doc.qt.io/qt-5/qactiongroup.html, because at Qt6 (the default now when you search online)QActionGroup
actually changed module!but I see QAction and QActionGroup in the same library (QT += gui)
Yes in Qt6, not in Qt5!
-
@jsulm said in How to compile a so file in order to load it as a library.:
@jenya7 If you go to https://doc.qt.io/qt-6/qaction.html you will see what Qt module it is (hint: qmake: QT += gui)
sorry to bother but I included
-L/usr/lib/arm-linux-gnueabihf/ -lQt5Gui
and QAction is good now but I get
undefined symbol: _ZN12QActionGroup16staticMetaObjectE
but I see QAction and QActionGroup in the same library (QT += gui)
Do I miss some lib?@jenya7 said in How to compile a so file in order to load it as a library.:
but I see QAction and QActionGroup
This is wrong, please look again...
-
@jenya7 said in How to compile a so file in order to load it as a library.:
but I see QAction and QActionGroup
This is wrong, please look again...
-
@jsulm
Well. It shows no mercy. To make a single .so file I have to include ALL -lQt5** files and ALL object files in the build folder. Start to learn QMake file usage.@jenya7
Not sure what you are saying here. In order to create a shared library file --- or for that matter an executable --- yes, you have to provide the linker with all the-l...
libraries it will need to resolve all the references. And that includes other libraries which each one references. This will not be an unending/large number: there are only a limited number of libraries supplied for Qt, it's not like it's one for each class. Note btw that it will not statically include those library files into your executable or library --- it will use references to the shared library files to load at runtime. -
@jenya7
Not sure what you are saying here. In order to create a shared library file --- or for that matter an executable --- yes, you have to provide the linker with all the-l...
libraries it will need to resolve all the references. And that includes other libraries which each one references. This will not be an unending/large number: there are only a limited number of libraries supplied for Qt, it's not like it's one for each class. Note btw that it will not statically include those library files into your executable or library --- it will use references to the shared library files to load at runtime. -
@JonB
But when I try to link the resulting so file to Pythonfrom ctypes import * libc = CDLL("mylib.so")
It throws exceptions till I include ALL files in so file build.
@jenya7 said in How to compile a so file in order to load it as a library.:
till I include ALL files in so file build
You need to add all files which you link to your mylib.so (so, all the -l*.so)