Fix order of singlefilehost libarires passed to the linker #42094
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We give a list of arguments to the linker which includes a list of static objects we want to be linked together and a set of system-wide native libraries they should be dynamically linked against.
Some build environments, such as Fedora, use the
--as-needed
linker flag. This makes the linker pay attention to the order in which libraries appear and remove uneeded libararies.When the linker sees this:
It works from left to right and sees that nothing so far depends on libz. The linker removes libz from the set of objects being linked. Then it links staticobject.a, which needs symbols from libz. The linker then complains that it contains an undefined reference.
We can fix that by changing the order so that dependencies appear last in the linker command line:
This makes the linker link staticobject.a against libz correctly.