Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Links with :static suffix do not generate correct target dependencies #1685

Closed
piotrdz opened this issue Aug 6, 2021 · 7 comments · Fixed by #1975
Closed

Links with :static suffix do not generate correct target dependencies #1685

piotrdz opened this issue Aug 6, 2021 · 7 comments · Fixed by #1975
Labels

Comments

@piotrdz
Copy link

piotrdz commented Aug 6, 2021

What seems to be the problem?
Given this sample project where links is used with :static suffix to enable putting the static library in static section of link libraries (-Wl,-Bstatic):

workspace "MyWorkspace"
    configurations { "Debug" }
    toolset "gcc"

    project "MyLib"
        kind "StaticLib"
        files { "lib.cpp" }

    project "MyApp"
        kind "ConsoleApp"
        libdirs { "bin/Debug" }
        links { "MyLib:static" }
        files { "app.cpp" }

When premake is called to generate gmake Makefiles, and make is invoked to build MyApp:

$ premake5 gmake
$ make MyApp

Then it fails to build with the compiler not finding the MyLib:

==== Building MyApp (debug) ====
Creating obj/Debug/MyApp
app.cpp
Creating bin/Debug
Linking MyApp
/usr/bin/ld: cannot find -lMyLib
collect2: error: ld returned 1 exit status
make[1]: *** [MyApp.make:54: bin/Debug/MyApp] Error 1
make: *** [Makefile:31: MyApp] Error 2

This is because MyApp in generated Makefiles does not include a dependency on MyLib target. Therefore, MyLib is never built and the linking phase of MyApp fails.

What did you expect to happen?
Generated Makefiles should contain the correct dependency of MyApp on MyLib and make MyApp should build first MyLib, then MyApp successfully.

What have you tried so far?
The only workaround is to manually build MyLib first, then MyApp.

How can we reproduce this?
Run the example given above.

What version of Premake are you using?
premake5 (Premake Build Script Generator) 5.0.0-alpha16

Anything else we should know?
When not using the :static suffix, the dependencies are correct and the build works as expected:

However, that is not a valid workaround for the project I am working on. In this particular case, putting the library in -Wl,-Bstatic section is quite important for building the project correctly.

@piotrdz piotrdz added the bug label Aug 6, 2021
@nickclark2016
Copy link
Member

Could you attach the makefile that premake generates?

@piotrdz
Copy link
Author

piotrdz commented Aug 15, 2021

Here is a zip archive of the Makefiles.
makefiles.zip

@kevza
Copy link

kevza commented Sep 16, 2022

The lib project lookup doesn't take into account :static or :shared in the lib name.

https://gist.github.com/kevza/ec6a8c6f58019f367b50cc45f666d746

@samsinsane
Copy link
Member

@piotrdz Can you elaborate on why linking the sibling project normally is not an option? Having the linking decorators being handled properly for sibling projects is non-trivial but ignoring them is pretty simple - see the patch @kevza has linked.

@kevza
Copy link

kevza commented Oct 3, 2022

@samsinsane, @piotrdz and I work together on the same project.

Our build is really, really complicated and there are a bunch of targets that get assembled with different linking requirements (Plugins v/s Applications etc..) so we have to use the :shared :static annotations depending on what the target is.

We have added the patch I attached to our build of premake and everything is working as expected.

@samsinsane
Copy link
Member

@kevza Can you submit that as a PR? Otherwise, I'll create a PR after work.

@kevza
Copy link

kevza commented Oct 5, 2022

@samsinsane thank you for creating that PR. Apologies for not getting to it sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants