How to link .so files's header to other project
-
main_project.cpp
pro:
TEMPLATE = app CONFIG += console c++17 CONFIG -= app_bundle CONFIG -= qt LIBS += -L/home/j/shared-Debug/ -lshared INCLUDEPATH += /home/j/shared SOURCES += \ main.cppmain.cpp:
#include <iostream> #include <Shared.h> using namespace std; int main() { cout << "Hello World!" << endl; Shared s; s.test(); return 0; }all correct now?
it builds, but still I dont understand how it worksSo every time I have change in header, I need rebuild it to new so ?
@JacobNovitsky said in How to link .so files's header to other project:
So every time I have change in header, I need rebuild it to new so ?
Your library mainly consists of the Shared.cpp. If you change the library header you may need to rebuild the library (depends on the changes in the header file) and also your main project.
It is not that complex: you build the library to a so file. In the project where you want to use it you link the so (this is what LIBS is used for). But in order to use the functionality of the library in your main project (like using data types, calling functions, ...) you also need to include the header file from the library which defines the interface. This is done by adding INCLUDEPATH to tell the preprocessor where to look for header files and including the header file in your main project.
-
main_project.cpp
pro:
TEMPLATE = app CONFIG += console c++17 CONFIG -= app_bundle CONFIG -= qt LIBS += -L/home/j/shared-Debug/ -lshared INCLUDEPATH += /home/j/shared SOURCES += \ main.cppmain.cpp:
#include <iostream> #include <Shared.h> using namespace std; int main() { cout << "Hello World!" << endl; Shared s; s.test(); return 0; }all correct now?
it builds, but still I dont understand how it worksSo every time I have change in header, I need rebuild it to new so ?
@JacobNovitsky
I just amended function in shared program, saved cpp but did not built and main program sees previous version -
@JacobNovitsky
I just amended function in shared program, saved cpp but did not built and main program sees previous version@JacobNovitsky said in How to link .so files's header to other project:
I just amended function in shared program, saved cpp but did not built and main program sees previous version
Not sure what this mean. If you mean you changed something in the shared library without rebuilding it and your main application still sees the old version then it is just logical, right? You need to rebuild the lib if you change it.
-
@JacobNovitsky said in How to link .so files's header to other project:
I just amended function in shared program, saved cpp but did not built and main program sees previous version
Not sure what this mean. If you mean you changed something in the shared library without rebuilding it and your main application still sees the old version then it is just logical, right? You need to rebuild the lib if you change it.
@jsulm what is faster?
pre-compiled headers or same headers built to objects?
I used per-compiled headers and it seem to slightly speed up compilation, but I'm not sure -
@jsulm what is faster?
pre-compiled headers or same headers built to objects?
I used per-compiled headers and it seem to slightly speed up compilation, but I'm not sure@JacobNovitsky I never used pre compiled headers and as far as I know only Microsoft compiler supports them (but I could be wrong on that).
-
@JacobNovitsky I never used pre compiled headers and as far as I know only Microsoft compiler supports them (but I could be wrong on that).
@jsulm oh! thanks :)
any guideline how to speed compilation/execution/building time, on Ubuntu, Qt Creator 6.4.2, Qt6, gcc?
I'd like to build all neat and fully debug function to so files, it seems reasonable, but I believe I can miss something powerfulPls advise :J
-
@JacobNovitsky I never used pre compiled headers and as far as I know only Microsoft compiler supports them (but I could be wrong on that).
@jsulm said in How to link .so files's header to other project:
@JacobNovitsky I never used pre compiled headers and as far as I know only Microsoft compiler supports them (but I could be wrong on that).
Pre-compiled headers are available through gcc and clang as well.
@JacobNovitsky before diving into that kind of consideration, you should first analyze what you are currently using for your application. You example library does not really warrant the use of pre-compiled headers seeing the side and number of includes it has. Take a look at the Wikipedia entry.
As for debugging, you might want to check the "release with debug info" topic. Note that you should first start with a working implementation and then pursue optimization.
-
@jsulm oh! thanks :)
any guideline how to speed compilation/execution/building time, on Ubuntu, Qt Creator 6.4.2, Qt6, gcc?
I'd like to build all neat and fully debug function to so files, it seems reasonable, but I believe I can miss something powerfulPls advise :J
@JacobNovitsky Do you use more than one build process? With make you can do that like this: make -j NUMBER_OF_PARALLEL_BUILD_JOBS
I think QtCreator does this by default already. -
@JacobNovitsky Do you use more than one build process? With make you can do that like this: make -j NUMBER_OF_PARALLEL_BUILD_JOBS
I think QtCreator does this by default already.@jsulm yes, it uses "/usr/bin/make" -j8
but still it calls 30-60 seconds per build, which is way too much -
@jsulm yes, it uses "/usr/bin/make" -j8
but still it calls 30-60 seconds per build, which is way too much@JacobNovitsky said in How to link .so files's header to other project:
but still it calls 30-60 seconds per build
Are we talking about complete rebuild of the project or incremental builds after changing some parts of the code? How big is the project (how many lines of code)?