Implicit Linking for non-Visual Studio Exporters
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.
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 /*..*/
?
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.
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...
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.
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.