Hi,
I am trying to add an external library to a qt application. But after building the application its showing cannot recognize file format. Library is in .so format and I am working on linux. Please help.
Hi,
I am trying to add an external library to a qt application. But after building the application its showing cannot recognize file format. Library is in .so format and I am working on linux. Please help.
Not sure I follow.
It sound like you can build the application.But after building the application
If this is true, then your lib is linked as it should, otherwise the linker would complain.
I guess what is not so clear is what do you mean with "adding" the lib.
More information would help.
It sound more like your are trying the open an *.so file with your application.
Is that the case?
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Currently the application has some cpp files which are included in the pro file. (It will give a successful build)
Instead what I am trying to do is to add those cpp files as a shared library.(On trying to build will show file format not recognised build failed)
Added after 1 43 minutes:
Please help me on how to add the cpp files as a shared library to a qt application.
Last edited by bravestar; 27th April 2017 at 07:25.
Ok, what you want is to build a shared lib.
You should do it in a separate project, either a completely separate project, or a sub-project of the one you have now.
If you are using QtCreator simply do: File->New File or project
Then select "Library" from the possible options on the left, and and C++ library on the right side.
Also have a look at this:
https://wiki.qt.io/How_to_create_a_l...an_application
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Thanks that really helped!
Is there anyway to know which all shared libraries are linked to an application in qt?
If you have the source code, and this is a qmake project (using *.pro files) you can look for the 'LIBS' variables in your *.pro/*.pri files.
Uder linux you can use the ldd command on the executable : http://man7.org/linux/man-pages/man1/ldd.1.html
For windows, you can use dependency walker: http://www.dependencywalker.com/
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Thanks
Now the shared library has been made.
I am making the shared library for a qt application which has to run on a target board. How will I link the shared library to the executable as it is running on a board.
Please help
If your executable is running on a board, then you have built it using a cross-compiler tool chain for that board, right? Your shared library has to be built with the same cross-compiler tool chain and symbolically linked into the executable (that is, the executable has been told that there are functions it will be calling that can be found in a shared library of a certain name).
You now need to install the shared library into the board's OS. Most of the time this is done by copying the file into a known location in the file system used by the board - the same folder as the executable or a known location for shared libraries.
If you are directly downloading the executable into the board's memory (like with an Arduino sketch), then you're going to have to consult the Arduino manuals for how to add this.
The question is, if you are running this on an embedded board, why do you need a shared library in the first place?
<=== The Great Pumpkin says ===>
Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.
@bravestar
What OS is running on your board?
If it is some sort of linux, you can put your shared lib in a path of your choice, and add that path to LD_LIBRARY_PATH. (in addition to putting it next to the application executable as d_stranz said)
The linker will look the path for the libs from that system variable.
Note: if your shared lib is doing write operations, or other operations that need elevated rights, and the application you are running is a user space application, make sure the location of your shared lib is not a location needing elevated rights.
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
bravestar (16th May 2017)
Thanks a lot.
I have added the LD_LIBRARY PATH, and tried to run the application. Its not working. Do I have to use subdirs for handling dependencies.
Added after 8 minutes:
@high_flyer OS is linux
Last edited by bravestar; 11th May 2017 at 07:38.
show the ldd output on your executable
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
Thank you very much guys. I tried making libraries using cmake and it worked!
Bookmarks