Skip to content

Linking order not preserved in pkg.lflags #429

@simonratner

Description

@simonratner

When specifying additional libraries to be linked with pkg.lflags, the order of the libraries is not preserved. Instead, flags seem to be sorted in alphabetical order.

This is a problem when symbols in one of the libraries are defined in another, e.g. the following fails to link:

nm liba.a

00000001 T foo

nm libb.a

00000001 U foo

cat pkg.yml:

pkg.lflags:
  - "-lb"
  - "-la"

Normally, foo from libb will be added to the undefined list, and then matched to foo in liba once it is encountered. However newt actually executes gcc ... -la -lb, which strips the unused foo from liba before processing libb and results in an undefined reference to foo.

A workaround is to rename or symlink the libraries into the order you wish them to be linked 🤮

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions