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

Link order problem with remote packages #566

Closed
mwik opened this issue Sep 4, 2019 · 4 comments
Closed

Link order problem with remote packages #566

mwik opened this issue Sep 4, 2019 · 4 comments
Labels
Milestone

Comments

@mwik
Copy link

mwik commented Sep 4, 2019

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.

@waruqi waruqi added the bug label Sep 4, 2019
@waruqi waruqi added this to the v2.2.9 milestone Sep 4, 2019
@waruqi
Copy link
Member

waruqi commented Sep 4, 2019

Ok, I will fix it.

@waruqi
Copy link
Member

waruqi commented Sep 5, 2019

I have fixed it, you can update dev branch and try it again. xmake update -s dev

@mwik
Copy link
Author

mwik commented Sep 5, 2019

Beautiful! It works for both my testcases. Fix confirmed! Thanks.

@waruqi
Copy link
Member

waruqi commented Sep 29, 2023

Now we can sort links better. #1452 (comment)

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

No branches or pull requests

2 participants