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

Offline cdavalillo

  • Single posting newcomer
  • *
  • Posts: 4
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: 2848
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 »

Offline cdavalillo

  • Single posting newcomer
  • *
  • Posts: 4
Re: Linking .so library problem with prefix lib name
« Reply #2 on: October 04, 2020, 06:50:05 am »
Ok Thanks for the help.

I do what you told me in the way 2 and now I get the following

/usr/bin/ld: obj/Debug/main.o: in function `main':
/home/davalillocm/CodeBlocks_Projects/exp00023/main.cpp:56: undefined reference to `canonbit_definitions::mathematical_definitions::Add(canonbit_definitions::mathematical_definitions::Holor const&, double const&, canonbit_definitions::mathematical_definitions::Holor&)'

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7012
    • My Best Post
Re: Linking .so library problem with prefix lib name
« Reply #3 on: October 04, 2020, 09:19:25 am »
Without a full rebuild log it will be hard to help you!
Edit2: Full rebuild only needed for the project with the linking error.

Please read http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F

It gives directions on how to post a full build log.

Edit: You still need to link to libraries needed by the file(s) being compiled.

Tim S.
« Last Edit: October 04, 2020, 09:40:16 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org