xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.14k stars 782 forks source link

动态库set_version的soname配置交叉编译平台不生效 #5478

Closed NameisNone closed 2 months ago

NameisNone commented 3 months ago

Xmake 版本

2.9.4

操作系统版本和架构

windows11 23H2 WSL2 ubuntu22.04.3

描述问题

通过xmake f -p xxx,设置一个嵌入式交叉编译平台,交叉编译一个动态库,需要设置库的soname,通过以下设置未生效,未生成对应的软链接文件,且无readelf -d 查看动态库,未设置soname: set_version("1.0.0.19", { soname = true })

期待的结果

xmake f -p xxx切换平台,编译后生成对应软链接文件,且存在soname字段

工程配置

add_rules("mode.debug", "mode.release")

toolchain("imx8m_cc")
    set_kind("standalone")
    set_sdkdir("../toolchain/toolchain-imx8m/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu")

target("foo")
    set_version("1.0.0.19", { soname = true })
    set_kind("shared")
    add_files("src/foo.c")
    on_load(function (target)
        local platform = "imx8m"
        if target:is_plat("imx8m") then 
            platform = "imx8m"
            target:set("toolchains", "imx8m_cc")
        -- 后续添加其他平台
        end 
        target:add("linkdirs", "dep_libs/" .. platform)
    end)

附加信息和错误日志

> xmake f -p imx8m
checking for architecture ... x86_64

 ~/test                                                                                                                          18:18:49 
> xmake f -v      
configure
{
    ccache = true
    mode = release
    arch = x86_64
    buildir = build
    ndk_stdcxx = true
    target_os = linux
    plat = imx8m
    kind = static
    host = linux
}

 ~/test                                                                                                                          18:18:52 
> rm build -r  

 ~/test                                                                                                                          18:19:00 
> xmake -rv 
checking for aarch64-linux-gnu-gcc ... ../toolchain/toolchain-imx8m/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc
checking for the c compiler (cc) ... aarch64-linux-gnu-gcc
checking for ../toolchain/toolchain-imx8m/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc ... ok
checking for flags (-fPIC) ... ok
checking for flags (-O3) ... ok
checking for flags (-DNDEBUG) ... ok
[ 50%]: cache compiling.release src/foo.c
../toolchain/toolchain-imx8m/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc -c -fPIC -O3 -DNDEBUG -o build/.objs/foo/imx8m/x86_64/release/src/foo.c.o src/foo.c
checking for flags (-MMD -MF) ... ok
checking for flags (-fdiagnostics-color=always) ... ok
checking for aarch64-linux-gnu-g++ ... ../toolchain/toolchain-imx8m/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
checking for the shared library linker (sh) ... aarch64-linux-gnu-g++
checking for ../toolchain/toolchain-imx8m/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ ... ok
checking for flags (-fPIC) ... ok
[ 75%]: linking.release libfoo.so
../toolchain/toolchain-imx8m/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ -o build/imx8m/x86_64/release/libfoo.so build/.objs/foo/imx8m/x86_64/release/src/foo.c.o -shared -fPIC -Ldep_libs/imx8m -s
[100%]: build ok, spent 0.587s

 ~/test                                                                                                                          18:19:02 
> tree build 
build
└── imx8m
    └── x86_64
        └── release
            └── libfoo.so

3 directories, 1 file
Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


Title: The soname configuration of the dynamic library set_version cross-compilation platform does not take effect

NameisNone commented 3 months ago

通过xmake f --toolchain切换工具链soname是可以生效的,但是某些库是按平台做路径区分的,所以想通过设置plat的方式动态切换一些路径和编译工具链。

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


Switching the tool chain soname through xmake f --toolchain can take effect, but some libraries are path-divided according to platforms, so I want to dynamically switch some paths and compilation tool chains by setting plat.

waruqi commented 2 months ago

可以的么

$ xmake f -p cross
$ xmake
$ tree build/cross/none/release/
build/cross/none/release/
├── libfoo.so -> libfoo.so.1
├── libfoo.so.1 -> libfoo.so.1.0.0.19
├── libfoo.so.1.0.0.19
└── test
set_version("1.0.0.19", { soname = true })

toolchain("imx8m_cc")
    set_kind("standalone")
    set_sdkdir("~/.xmake/packages/m/muslcc/20210202/d8df8518d75f4c899fdd7b947fb7c863/")
toolchain_end()

set_toolchains("imx8m_cc")

target("foo")
    set_kind("shared")
    add_files("src/foo.cpp")

target("test")
    set_kind("binary")
    add_deps("foo")
    add_files("src/main.cpp")
NameisNone commented 2 months ago

可以的么

$ xmake f -p cross
$ xmake
$ tree build/cross/none/release/
build/cross/none/release/
├── libfoo.so -> libfoo.so.1
├── libfoo.so.1 -> libfoo.so.1.0.0.19
├── libfoo.so.1.0.0.19
└── test
set_version("1.0.0.19", { soname = true })

toolchain("imx8m_cc")
    set_kind("standalone")
    set_sdkdir("~/.xmake/packages/m/muslcc/20210202/d8df8518d75f4c899fdd7b947fb7c863/")
toolchain_end()

set_toolchains("imx8m_cc")

target("foo")
    set_kind("shared")
    add_files("src/foo.cpp")

target("test")
    set_kind("binary")
    add_deps("foo")
    add_files("src/main.cpp")

目前是有多个平台需要通过xmake f -p imx8m,xmake f -p imx6u来切换,只能xmake f -p cross吗? 按照您这里的示例,set_toolchains放在全局是可以的,在target描述域里面根据平台判断再set_toolchains也不行:

add_rules("mode.debug", "mode.release")

toolchain("imx8m_cc")
    set_kind("standalone")
    set_sdkdir("../projects/toolchain/toolchain-imx8m/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu")
toolchain_end()

-- set_toolchains("imx8m_cc")

target("foo")
    set_kind("shared")
    set_version("1.0.0.19", { soname = true })
    add_files("src/foo.cpp")
    if is_plat("imx8m") then 
        set_toolchains("imx8m_cc")
    end 

target("test")
    set_kind("binary")
    add_deps("foo")
    add_files("src/main.cpp")
    if is_plat("imx8m") then 
        set_toolchains("imx8m_cc")
    end 

配置和编译结果:

none@ubuntu:~/test$ tree build/
build/
└── imx8m
    └── x86_64
        └── release
            ├── libfoo.so
            └── test

3 directories, 2 files
none@ubuntu:~/test$ xmake f -v
configure
{
    target_os = linux
    host = linux
    plat = imx8m
    mode = release
    buildir = build
    arch = x86_64
    ndk_stdcxx = true
    kind = static
    ccache = true
}

编译输出,可以看到没有设置-Wl,-soname:

~/test$ xmake -rv
[ 37%]: cache compiling.release src/foo.cpp
../projects/toolchain/toolchain-imx8m/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc -c -fPIC -O3 -DNDEBUG -o build/.objs/foo/imx8m/x86_64/release/src/foo.cpp.o src/foo.cpp
[ 50%]: cache compiling.release src/main.cpp
../projects/toolchain/toolchain-imx8m/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc -c -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -o build/.objs/test/imx8m/x86_64/release/src/main.cpp.o src/main.cpp
[ 62%]: linking.release libfoo.so
../projects/toolchain/toolchain-imx8m/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ -o build/imx8m/x86_64/release/libfoo.so build/.objs/foo/imx8m/x86_64/release/src/foo.cpp.o -shared -fPIC -s
[ 87%]: linking.release test
../projects/toolchain/toolchain-imx8m/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ -o build/imx8m/x86_64/release/test build/.objs/test/imx8m/x86_64/release/src/main.cpp.o -Lbuild/imx8m/x86_64/release -Wl,-rpath=$ORIGIN -s -lfoo
[100%]: build ok, spent 0.198s
waruqi commented 2 months ago

再试试,xmake update -s dev

Issues-translate-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically.


Try again, xmake update -s dev

NameisNone commented 2 months ago

再试试,xmake update -s dev

可以了

Issues-translate-bot commented 2 months ago

Bot detected the issue body's language is not English, translate it automatically.


Try again, xmake update -s dev

That's ok