Author Topic: Linker error because of stripping off lib prefix  (Read 4724 times)

Offline sodev

  • Regular
  • ***
  • Posts: 497
Linker error because of stripping off lib prefix
« on: January 27, 2020, 02:18:34 pm »
In a workspace i have two projects, one produces an executable, the other one a static library the executable gets linked with. The library project is simply called libs, it produces the output liblibs.a. The executable project references the output as libs in the linker settings.

The linking step however fails because on the actual command line this setting is turned into a -ls. For some reason the lib prefix gets stripped off. If i rename the library to something that does not start with lib like simplelibs, which results into the output libsimplelibs.a and the linker setting simplelibs, it does work.

This happens on Linux and Windows with the compiler GCC, if i switch to MSVC on Windows, which results into the output libs.lib and the linker setting libs, the linking does succeed.
« Last Edit: January 27, 2020, 02:51:42 pm by sodev »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Linker error because of stripping off lib prefix
« Reply #1 on: January 27, 2020, 07:27:28 pm »
You'll have to manually pass the linker command using other linker options.
Or you'll have to inspect the code to see if the problem happens in the UI or somewhere deep in the compiler plugin.
If it happens in the UI it would probably be possible to fix this. If it is somewhere deep in the compiler plugin, it would probably be unfixable.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: Linker error because of stripping off lib prefix
« Reply #2 on: January 27, 2020, 08:12:07 pm »
You'll have to manually pass the linker command using other linker options.

Can't do that because i'm not hand writing the project files but generate them with my private Premake fork. I first thought that one is causing the error but it is not. I did inspect the .cbp file directly and there the library is correctly listed with the name libs.

I guess that rules out UI and falls into the unfixable case :-\

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Linker error because of stripping off lib prefix
« Reply #3 on: January 28, 2020, 08:43:38 am »
What happens if you use liblibs in the cbp? And if you already have a fork you can modify it to make it do whatever you want :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: Linker error because of stripping off lib prefix
« Reply #4 on: January 28, 2020, 04:43:38 pm »
Adding multiple lib prefixes only stripps off one of them.

Modifying the generator is quite some work i want to save, it is easier to change the output name in the script instead and push it into all projects. But that would violate the naming scheme :o, need to ask my OCD about it ;D.

Offline sodev

  • Regular
  • ***
  • Posts: 497
Re: Linker error because of stripping off lib prefix
« Reply #5 on: January 28, 2020, 05:26:43 pm »
For reference, i found the location that does that prefix stripping, it is CompilerCommandGenerator::FixupLinkLibraries(Compiler*, const wxString&).

There is some fancy stuff ongoing to "fix" library names but i do not really know why. Fix user error? Or fix results of lookup-tools like pkg-config? I'm afraid in that location it is impossible to figure out the source of the library to determine if a fix is needed or not. Maybe the prefix stripping can only be done if there is an extension present like the extension stripping is only done if a prefix is present. But chances are high that changing anything there will break something badly.

Not sure how many other libraries are out there whose name starts with lib (or whatever prefix the used compiler uses) and will run into that problem, so maybe it's not worth to investigate further.
« Last Edit: January 28, 2020, 05:30:21 pm by sodev »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Linker error because of stripping off lib prefix
« Reply #6 on: January 28, 2020, 07:47:05 pm »
I think the stripping should happen only in the UI, but I don't have time/desire to investigate this.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]