Author Topic: Linking .so library problem with prefix lib name  (Read 168 times)

Offline cdavalillo

  • Single posting newcomer
  • *
  • Posts: 3
Linking .so library problem with prefix lib name
« on: September 06, 2020, 01:41:15 am »
Ok this is my problem.

I just starting to program in Linux. I'm using Code::Blocks 20.03 on Fedora 32 with g++ compiler. I'm trying to link two .so libraries. The project for library 1 yield a file with name lets say library1.so, for project 2 the name is library2.so. But the project 2 must link against to library1.so so in this project I have in Build options->Linker settings->Link libraries the library1 added with no prefix lib and no .so extension. When I compile the linker says ld cannot find -llibrary1

Then after search in this forum and the internet I found that the name of linking file must have the prefix lib. So I added and then after successfully compile the output of library2 project is library2.so file.

My question is, there is a way to automatically generate both the liblibrary1.so and the library1.so file when compiling.   And more important if the final library the .so file is the one against one link to why must be changed the name of the library appending the lib prefix to correctly link in Code::Blocks?

I'm doing something wrong? I missed something?

Thank you in advance.

« Last Edit: September 06, 2020, 02:27:22 am by cdavalillo »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2814
Re: Linking .so library problem with prefix lib name
« Reply #1 on: September 06, 2020, 01:48:22 pm »
Quote
Then after search in this forum and the internet I found that the name of linking file must have the prefix lib. So I added and then after successfully compile the output of library2 project is library2.so file.
Have you looked at the actual name of the binary file? i think codeblocks adds lib infront automatically if you create a library. You can change the output file name in Project->Properties->Build targets->output filename

Quote
My question is, there is a way to automatically generate both the liblibrary1.so and the library1.so file when compiling
There are multiple ways to do this.
Way 1 (personally my preferred way):
Use one project for all libraries and the executable. Use a target for each library and one for the final binary. Then create a virtual target that builds all targets in order. If nothing changed codeblocks will jump over this target..

Way 2:
Use multiple project and add dependencies to each other:
1) All projects have to be in the same workspace
2) Project->Properties->Project settings->Projects dependencies->Select your project from the drop down (should be default) -> Tick all projects this project depends on
3) Set up a external dependency to the library binary file: Project->Properties->Build targets->Dependencies->External dependency->Add the library file

Step 2) will check if the other project is up to date
Step 3) will check the explicit binary output file from the other project.

[Edit:] Workspace does only mean, they have to be open in the codeblocks editor, not in the same folder as for example in eclipse....

hope this helps...
greetings
« Last Edit: September 06, 2020, 01:51:39 pm by BlueHazzard »