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 #3144

Closed
Arthapz opened this issue Dec 7, 2022 · 3 comments
Closed

Link order #3144

Arthapz opened this issue Dec 7, 2022 · 3 comments
Labels
Milestone

Comments

@Arthapz
Copy link
Member

Arthapz commented Dec 7, 2022

Xmake Version

2.7.3-dev

Operating System Version and Architecture

Archlinux

Describe Bug

set_xmakever("2.7.3")
set_project("foo")

target("a")
    set_kind("static")
    add_files("src/a.cpp")

target("b")
    set_kind("static")
    add_files("src/b.cpp")

target("foo")
    set_kind("binary")
    add_files("src/main.cpp")
    add_deps("a", "b")
cmake_minimum_required(VERSION 3.7...3.25)
project(Foo LANGUAGES CXX)

add_library(a STATIC src/a.cpp)
add_library(b STATIC src/b.cpp)

add_executable(foo src/main.cpp)
target_link_libraries(foo a b)
// main.cpp
#include <iostream>
extern int b;
int main() {
    std::cout << b << std::endl;
    return b;
}

// a.cpp
int b = 1;

// b.cpp
int b = 0;

produce different link behavior

xmake: /usr/sbin/g++ -o build/linux/x64/release/foo build/.objs/foo/linux/x64/release/src/main.cpp.o -m64 -Lbuild/linux/x64/release -lb -la
cmake: /usr/sbin/c++ CMakeFiles/foo.dir/src/main.cpp.o -o foo liba.a libb.a

image

Expected Behavior

Both same link behavior

Project Configuration

No response

Additional Information and Error Logs

tested on gcc and msvc

this also affect GCC module support as the link order doesn't match the import order (this doesn't affect msvc through, i don't know for clang)

@Arthapz Arthapz added the bug label Dec 7, 2022
@waruqi waruqi mentioned this issue Dec 8, 2022
@waruqi
Copy link
Member

waruqi commented Dec 8, 2022

try it again on dev

@waruqi waruqi added this to the v2.7.4 milestone Dec 8, 2022
@Arthapz
Copy link
Member Author

Arthapz commented Dec 8, 2022

it works fine now !

@waruqi waruqi closed this as completed Dec 8, 2022
waruqi added a commit that referenced this issue Dec 18, 2022
@waruqi
Copy link
Member

waruqi commented Dec 18, 2022

The previous fix was wrong, please continue to test the latest dev version.

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