How to compile a so file in order to load it as a library.
-
I want to load a Qt library in Python
from ctypes import * libc = CDLL("mylib.so")
So first I create a library
g++ -fPIC -shared -o mylib.so mylib.o
But when I load I get
mylib.so: undefined symbol: _ZTI9QRunnableI aaded Q_DECL_EXPORT to my class
class Q_DECL_EXPORT SENSOR : public QObject
{
Q_OBJECTpublic: SENSOR(QObject *parent = nullptr); //and so on.....
}
But no so file was created.
So how can compile a *.so file recursively to include all related objects?
-
I want to load a Qt library in Python
from ctypes import * libc = CDLL("mylib.so")
So first I create a library
g++ -fPIC -shared -o mylib.so mylib.o
But when I load I get
mylib.so: undefined symbol: _ZTI9QRunnableI aaded Q_DECL_EXPORT to my class
class Q_DECL_EXPORT SENSOR : public QObject
{
Q_OBJECTpublic: SENSOR(QObject *parent = nullptr); //and so on.....
}
But no so file was created.
So how can compile a *.so file recursively to include all related objects?
@jenya7 said in How to compile a so file in order to load it as a library.:
But no so file was created.
So, then the compiler/linker failed, right? What about posting errors? Or did you only rerun "g++ -fPIC -shared -o mylib.so mylib.o
" - you of course have to rebuild mylib.o -
@jenya7 said in How to compile a so file in order to load it as a library.:
But no so file was created.
So, then the compiler/linker failed, right? What about posting errors? Or did you only rerun "g++ -fPIC -shared -o mylib.so mylib.o
" - you of course have to rebuild mylib.o@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.:
But no so file was created.
So, then the compiler/linker failed, right? What about posting errors? Or did you only rerun "g++ -fPIC -shared -o mylib.so mylib.o
" - you of course have to rebuild mylib.oNo failure. It compiled OK but no so file was created.
-
@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.:
But no so file was created.
So, then the compiler/linker failed, right? What about posting errors? Or did you only rerun "g++ -fPIC -shared -o mylib.so mylib.o
" - you of course have to rebuild mylib.oNo failure. It compiled OK but no so file was created.
@jenya7 said in How to compile a so file in order to load it as a library.:
It compiled OK but no so file was created
Then it did NOT compiled OK!
Did you rebuild mylib.o as I wrote? -
@jenya7 said in How to compile a so file in order to load it as a library.:
It compiled OK but no so file was created
Then it did NOT compiled OK!
Did you rebuild mylib.o as I wrote?@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.:
It compiled OK but no so file was created
Then it did NOT compiled OK!
Did you rebuild mylib.o as I wrote?OK. To make sure I delete the object file, compile (rebuild with Q_DECL_EXPORT option).
Then I do again
g++ -fPIC -shared -o mylib.so mylib.o
And see a new so file. However the same problem exists - mylib.so: undefined symbol: _ZTI9QRunnable -
@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.:
It compiled OK but no so file was created
Then it did NOT compiled OK!
Did you rebuild mylib.o as I wrote?OK. To make sure I delete the object file, compile (rebuild with Q_DECL_EXPORT option).
Then I do again
g++ -fPIC -shared -o mylib.so mylib.o
And see a new so file. However the same problem exists - mylib.so: undefined symbol: _ZTI9QRunnable@jenya7 said in How to compile a so file in order to load it as a library.:
QRunnable
QRunnable is part of QtCore Qt module, so your lib needs to link against QtCore.
-
@jenya7 said in How to compile a so file in order to load it as a library.:
QRunnable
QRunnable is part of QtCore Qt module, so your lib needs to link against QtCore.
@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.:
QRunnable
QRunnable is part of QtCore Qt module, so your lib needs to link against QtCore.
That is my question - how to compile recursively to include all related objects?
-
@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.:
QRunnable
QRunnable is part of QtCore Qt module, so your lib needs to link against QtCore.
That is my question - how to compile recursively to include all related objects?
@jenya7 said in How to compile a so file in order to load it as a library.:
how to compile recursively to include all related objects?
You do not compile recursevly, you link against libraries you depend on. Something like:
g++ -fPIC -shared -o mylib.so mylib.o -LPATH_TO_QT_LIB_FOLDER -lqtcore
-
@jenya7 said in How to compile a so file in order to load it as a library.:
how to compile recursively to include all related objects?
You do not compile recursevly, you link against libraries you depend on. Something like:
g++ -fPIC -shared -o mylib.so mylib.o -LPATH_TO_QT_LIB_FOLDER -lqtcore
@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.:
how to compile recursively to include all related objects?
You do not compile recursevly, you link against libraries you depend on. Something like:
g++ -fPIC -shared -o mylib.so mylib.o -LPATH_TO_QT_LIB_FOLDER -lqtcore
Too much to include I have in the source file
#include <QObject>
#include <QTime>
#include <QtConcurrent/QtConcurrent>
#include <QThread>
#include <QElapsedTimer>
#include <QApplication>It in its turn has its own dependencies. Is it doable at all?
-
@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.:
how to compile recursively to include all related objects?
You do not compile recursevly, you link against libraries you depend on. Something like:
g++ -fPIC -shared -o mylib.so mylib.o -LPATH_TO_QT_LIB_FOLDER -lqtcore
Too much to include I have in the source file
#include <QObject>
#include <QTime>
#include <QtConcurrent/QtConcurrent>
#include <QThread>
#include <QElapsedTimer>
#include <QApplication>It in its turn has its own dependencies. Is it doable at all?
@jenya7 said in How to compile a so file in order to load it as a library.:
Is it doable at all?
What is doable?
As I wrote: if you use a library then you have to link against that library... -
@jenya7 said in How to compile a so file in order to load it as a library.:
Is it doable at all?
What is doable?
As I wrote: if you use a library then you have to link against that library...@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.:
Is it doable at all?
What is doable?
As I wrote: if you use a library then you have to link against that library...I see. Where is LPATH_TO_QT_LIB_FOLDER located on Linux?
I can no t find -lqtcore library. -
@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.:
Is it doable at all?
What is doable?
As I wrote: if you use a library then you have to link against that library...I see. Where is LPATH_TO_QT_LIB_FOLDER located on Linux?
I can no t find -lqtcore 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. -
@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)