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

Implicit Linking for non-Visual Studio Exporters #2344

Open
nickclark2016 opened this issue Nov 26, 2024 · 5 comments
Open

Implicit Linking for non-Visual Studio Exporters #2344

nickclark2016 opened this issue Nov 26, 2024 · 5 comments

Comments

@nickclark2016
Copy link
Member

What problem will this solve?
Currently, dependencies on projects will resolve in different behaviors between Visual Studio and other exporters. Currently, only VS support implicit transitive linking based on project dependencies. I propose that we expose that behavior across other exporters.

What might be a solution?
From a user perspective, I propose adding an API such as:

implicitlinks "On"
implicitlinks "Off"
implicitlinks "Default"

This would allow the user to specify whether or not to use the implicit linking functionality. By default, I would propose turning this on. Visual Studio already turns this on by default (see the NoImplicitLinks flag).

In the generator, this would equate to performing a walk of the dependencies to get all static libraries and shared libraries to link to based on if they allow for implicit links. If implicit links are allowed on platforms that don't support implicit links directly, we would then emit rules in the generated files that specify the binary files to link against (and the appropriate linker search directories).

What other alternatives have you already considered?
Currently, the manual approach to this is to add all linkages manually to each project, ensuring that the behavior is consistent.

Anything else we should know?
Talking with various users across the community, this is something that would be useful to unify behavior across exporters.

@Jarod42
Copy link
Contributor

Jarod42 commented Nov 28, 2024

Not sure to understand what flags "NoImplicitLink" does (and so what it should do for other exporters).

It seems related to links and not dependson

Is it to turn

links "MyLib"

to

gcc -lMyLib -L%{targetdir} /*..*/

instead of

gcc %{targetdir}/libMyLib.a /*..*/

?

@nickclark2016
Copy link
Member Author

Visual Studio implicitly links all dependent projects together when you build a DLL or EXE. When you're using other exporters, you need to explicitly link transient project dependencies.

@Jarod42
Copy link
Contributor

Jarod42 commented Nov 29, 2024

I tried (https://github.com/Jarod42/premake-sample-projects/blob/implicit_link/projects/project-implicit_link):

flags { "NoImplicitLink" }
project "app"
	kind "ConsoleApp"

	files { "src/app/main.cpp" }
	links { "libA" } -- no "libB"

project "libA"
	kind "StaticLib"

	files { "src/libA/lib.cpp" }
	links { "libB" }

project "libB"
	kind "StaticLib"

	files { "src/libB/lib.cpp" }

And, indeed non-msvc generators fail to link with missing function from libB.
For msvc, with or without flags { "NoImplicitLink" }, it links...

@nickclark2016
Copy link
Member Author

I'm probably misinterpreting what the flag is for then. I'll rewrite the issue, but basically, I want to allow for linking of the entire project dependency chain implicitly.

@nickclark2016
Copy link
Member Author

nickclark2016 commented Nov 29, 2024

Looking into it, I'm not 100% sure if the flag is even working based on the description in the documentation. At least, it may not work at workspace scope and may need to be at project scope.

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

No branches or pull requests

2 participants