Automatically include needed files in .pro file
-
I have been experimenting with creating shared libraries under linux. All is working well but i've discovered something unusual.
I can use/reference some other class in my .so file and it compiles without issue. However, when I try to use methods in the .so file the app crashes dues to symbol undefined or similar.
It seems that I must add the .h and .cpp for every class I reference in my library into the .pro file for the lib; otherwise I get runtime errors (but no compilation errors) Is this normal?
Next, is there a way for Qt Creator to automatically add all of the needed .h and .cpp files (references by files in the .so) into my .pro file? Or do I have to add them all by hand?
-
@jsulm I actually meant the other way around. The .so is accessing classes/methods in the app (that loads the .so)...so it seems I have to include those classes' .h and .cpp when compiling the .so
I would like QT to automatically figure out which .h and .cpp files my shared library needs and add them to the library's .pro
@ocgltd It is totally up to you how to build shared libs, like which classes are added to .so. Qt can not automatically detect what is included in the lib. But when Qt code uses any of classes which are supposed to be in the lib, they should be there. Otherwise, you will see errors like undefined symbols.
-
I have been experimenting with creating shared libraries under linux. All is working well but i've discovered something unusual.
I can use/reference some other class in my .so file and it compiles without issue. However, when I try to use methods in the .so file the app crashes dues to symbol undefined or similar.
It seems that I must add the .h and .cpp for every class I reference in my library into the .pro file for the lib; otherwise I get runtime errors (but no compilation errors) Is this normal?
Next, is there a way for Qt Creator to automatically add all of the needed .h and .cpp files (references by files in the .so) into my .pro file? Or do I have to add them all by hand?
@ocgltd You need to export symbols you want to use outside of the library. See https://doc.qt.io/qt-6/sharedlibrary.html
Then only header file from the lib is needed where the library is used. -
@ocgltd You need to export symbols you want to use outside of the library. See https://doc.qt.io/qt-6/sharedlibrary.html
Then only header file from the lib is needed where the library is used.@jsulm I actually meant the other way around. The .so is accessing classes/methods in the app (that loads the .so)...so it seems I have to include those classes' .h and .cpp when compiling the .so
I would like QT to automatically figure out which .h and .cpp files my shared library needs and add them to the library's .pro
-
@jsulm I actually meant the other way around. The .so is accessing classes/methods in the app (that loads the .so)...so it seems I have to include those classes' .h and .cpp when compiling the .so
I would like QT to automatically figure out which .h and .cpp files my shared library needs and add them to the library's .pro
@ocgltd said in Automatically include needed files in .pro file:
I would like QT to automatically figure out which .h and .cpp files my shared library needs and add them to the library's .pro
why would you add e.g. iostream header to your pro file?
-
@jsulm I actually meant the other way around. The .so is accessing classes/methods in the app (that loads the .so)...so it seems I have to include those classes' .h and .cpp when compiling the .so
I would like QT to automatically figure out which .h and .cpp files my shared library needs and add them to the library's .pro
@ocgltd It is totally up to you how to build shared libs, like which classes are added to .so. Qt can not automatically detect what is included in the lib. But when Qt code uses any of classes which are supposed to be in the lib, they should be there. Otherwise, you will see errors like undefined symbols.
-
O ocgltd has marked this topic as solved on