Skip to content

Link order problem with remote packages #566

@mwik

Description

@mwik

Bug description

When a binary depends on two library targets that in turn depend on the same remote package the order of the link libraries gets wrong when linking the binary, causing undefined reference errors.

If an app depends on lib1 and lib2 and they in turn depend on say openssl, the resulting link line for the app will include -llib2 -lssl -lcrypto -llib1. But lib1 should come before -lssl and -lcrypto.

Expected behavior

Dependencies should occur after the dependent lib. No undefined references should occur when linking

Error output

$ xmake -v
configure
{
    ld = /usr/bin/g++
    ccache = true
    buildir = build
    mode = release
    ndk_stdcxx = true
    plat = linux
    ar = /usr/bin/ar
    cc = /usr/bin/gcc
    kind = static
    theme = default
    arch = x86_64
    host = linux
}
[100%]: linking.release app
/usr/bin/g++ -o build/linux/x86_64/release/app build/.objs/app/linux/x86_64/release/./main.c.o -Lbuild/linux/x86_64/release -L/usr/lib/x86_64-linux-gnu -Wl,-rpath=$ORIGIN -ltestlib2 -lssl -lcrypto -ltestlib1 -m64 -L/usr/local/lib -L/usr/lib
error: /usr/bin/ld: build/linux/x86_64/release/libtestlib1.a(testlib1.c.o): in function `init_testlib1':
testlib1.c:(.text+0xf): undefined reference to `OPENSSL_init_ssl'
collect2: error: ld returned 1 exit status

Related Environment

xmake v2.2.8+201909032242, linux

Additional context

A minimal example. Just clone and run xmake and it should trigger the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions