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

在xmake.lua中set_config修改sdk没有效果 #923

Closed
skyfireitdiy opened this issue Aug 21, 2020 · 14 comments
Closed

在xmake.lua中set_config修改sdk没有效果 #923

skyfireitdiy opened this issue Aug 21, 2020 · 14 comments

Comments

@skyfireitdiy
Copy link

描述问题

如题,日志如下:
add_defines生效了,但是set_config("sdk","....")未生效,日志见下文

期待的结果

应该和xmake f --sdk="..."效果一致才对。

错误信息

如果可能,请尽量附加程序运行过程中的错误输出信息。

如果是xmake相关编译问题,请加上-vD参数运行,并给出详细编译输出信息。

相关环境

请提供编译和运行环境信息,下面是一些必须填写的基础信息,便于我们针对性排查问题:

其他信息

shell日志:

skyfire@skyfire-pc /m/B/c/c/APM> rm -rf .xmake/
skyfire@skyfire-pc /m/B/c/c/APM> cat xmake.lua 
add_includedirs("./Utils/include", "./NetBase/include")
add_cxxflags("-Wall")
if is_mode("debug") then
    add_cxxflags("-g", "-Og")
end
if is_plat("x86_64") then
    add_defines("TEST")
    set_config("sdk","/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0")
end

target("APM")
    set_kind("static")
    add_files("./Utils/source/*.cpp", "./NetBase/source/*.cpp")
    set_languages("c++11")


target("TestUDP")
    set_kind("binary")
    add_deps("APM")
    add_files("./Test/Udp/main.cpp")
    add_links("pthread")
skyfire@skyfire-pc /m/B/c/c/APM> xmake f --plat=x86_64
checking for the architecture ... none
skyfire@skyfire-pc /m/B/c/c/APM> xmake -v
checking for the c++ compiler (cxx) ... gcc
checking for the c++ compiler (cxx) ... gcc
checking for the c++ compiler (cxx) ... gcc
checking for the c++ compiler (cxx) ... gcc
checking for the c++ compiler (cxx) ... gcc
checking for the c++ compiler (cxx) ... gcc
checking for the flags (-Wall) ... ok
[ 23%]: ccache compiling.release Utils/source/apm_time_resolve.cpp
/usr/bin/ccache /usr/lib64/ccache/gcc -c -std=c++11 -IUtils/include -INetBase/include -DTEST -Wall -o build/.objs/APM/x86_64/none/release/Utils/source/apm_time_resolve.cpp.o Utils/source/apm_time_resolve.cpp
[ 38%]: ccache compiling.release Utils/source/apm_any.cpp
/usr/bin/ccache /usr/lib64/ccache/gcc -c -std=c++11 -IUtils/include -INetBase/include -DTEST -Wall -o build/.objs/APM/x86_64/none/release/Utils/source/apm_any.cpp.o Utils/source/apm_any.cpp
[ 46%]: ccache compiling.release NetBase/source/apm_net_utils.cpp
/usr/bin/ccache /usr/lib64/ccache/gcc -c -std=c++11 -IUtils/include -INetBase/include -DTEST -Wall -o build/.objs/APM/x86_64/none/release/NetBase/source/apm_net_utils.cpp.o NetBase/source/apm_net_utils.cpp
[ 30%]: ccache compiling.release Utils/source/apm_logger.cpp
/usr/bin/ccache /usr/lib64/ccache/gcc -c -std=c++11 -IUtils/include -INetBase/include -DTEST -Wall -o build/.objs/APM/x86_64/none/release/Utils/source/apm_logger.cpp.o Utils/source/apm_logger.cpp
[ 53%]: ccache compiling.release NetBase/source/apm_abstract_network_manager.cpp
/usr/bin/ccache /usr/lib64/ccache/gcc -c -std=c++11 -IUtils/include -INetBase/include -DTEST -Wall -o build/.objs/APM/x86_64/none/release/NetBase/source/apm_abstract_network_manager.cpp.o NetBase/source/apm_abstract_network_manager.cpp
[ 61%]: ccache compiling.release NetBase/source/apm_abstract_udp_manager.cpp
/usr/bin/ccache /usr/lib64/ccache/gcc -c -std=c++11 -IUtils/include -INetBase/include -DTEST -Wall -o build/.objs/APM/x86_64/none/release/NetBase/source/apm_abstract_udp_manager.cpp.o NetBase/source/apm_abstract_udp_manager.cpp
checking for the flags (-MMD -MF) ... ok
checking for the flags (-fcolor-diagnostics) ... no
checking for the flags (-fdiagnostics-color=always) ... ok
[ 69%]: ccache compiling.release Test/Udp/main.cpp
/usr/bin/ccache /usr/lib64/ccache/gcc -c -IUtils/include -INetBase/include -DTEST -Wall -o build/.objs/TestUDP/x86_64/none/release/Test/Udp/main.cpp.o Test/Udp/main.cpp
[ 76%]: archiving.release libAPM.a
/usr/bin/ar -cr build/x86_64/none/release/libAPM.a build/.objs/APM/x86_64/none/release/Utils/source/apm_time_resolve.cpp.o build/.objs/APM/x86_64/none/release/Utils/source/apm_logger.cpp.o build/.objs/APM/x86_64/none/release/Utils/source/apm_any.cpp.o build/.objs/APM/x86_64/none/release/NetBase/source/apm_net_utils.cpp.o build/.objs/APM/x86_64/none/release/NetBase/source/apm_abstract_network_manager.cpp.o build/.objs/APM/x86_64/none/release/NetBase/source/apm_abstract_udp_manager.cpp.o
checking for the g++ ... /usr/lib64/ccache/g++
checking for the linker (ld) ... g++
[ 92%]: linking.release TestUDP
/usr/lib64/ccache/g++ -o build/x86_64/none/release/TestUDP build/.objs/TestUDP/x86_64/none/release/Test/Udp/main.cpp.o -Lbuild/x86_64/none/release -lAPM -lpthread
[100%]: build ok!
skyfire@skyfire-pc /m/B/c/c/APM> xmake f --sdk="/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0"
checking for the architecture ... x86_64
skyfire@skyfire-pc /m/B/c/c/APM> xmake -v
checking for the c++ compiler (cxx) ... x86_64-pc-linux-gnu-gcc
checking for the c++ compiler (cxx) ... x86_64-pc-linux-gnu-gcc
checking for the c++ compiler (cxx) ... x86_64-pc-linux-gnu-gcc
checking for the c++ compiler (cxx) ... x86_64-pc-linux-gnu-gcc
checking for the c++ compiler (cxx) ... x86_64-pc-linux-gnu-gcc
checking for the c++ compiler (cxx) ... x86_64-pc-linux-gnu-gcc
checking for the flags (-Wall) ... ok
[ 23%]: ccache compiling.release Test/Udp/main.cpp
/usr/bin/ccache /usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/bin/x86_64-pc-linux-gnu-gcc -c -IUtils/include -INetBase/include -I/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/include -Wall -o build/.objs/TestUDP/linux/x86_64/release/Test/Udp/main.cpp.o Test/Udp/main.cpp
[ 38%]: ccache compiling.release Utils/source/apm_logger.cpp
/usr/bin/ccache /usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/bin/x86_64-pc-linux-gnu-gcc -c -std=c++11 -IUtils/include -INetBase/include -I/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/include -Wall -o build/.objs/APM/linux/x86_64/release/Utils/source/apm_logger.cpp.o Utils/source/apm_logger.cpp
[ 61%]: ccache compiling.release NetBase/source/apm_abstract_network_manager.cpp
/usr/bin/ccache /usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/bin/x86_64-pc-linux-gnu-gcc -c -std=c++11 -IUtils/include -INetBase/include -I/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/include -Wall -o build/.objs/APM/linux/x86_64/release/NetBase/source/apm_abstract_network_manager.cpp.o NetBase/source/apm_abstract_network_manager.cpp
[ 53%]: ccache compiling.release NetBase/source/apm_net_utils.cpp
/usr/bin/ccache /usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/bin/x86_64-pc-linux-gnu-gcc -c -std=c++11 -IUtils/include -INetBase/include -I/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/include -Wall -o build/.objs/APM/linux/x86_64/release/NetBase/source/apm_net_utils.cpp.o NetBase/source/apm_net_utils.cpp
[ 30%]: ccache compiling.release Utils/source/apm_time_resolve.cpp
/usr/bin/ccache /usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/bin/x86_64-pc-linux-gnu-gcc -c -std=c++11 -IUtils/include -INetBase/include -I/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/include -Wall -o build/.objs/APM/linux/x86_64/release/Utils/source/apm_time_resolve.cpp.o Utils/source/apm_time_resolve.cpp
[ 46%]: ccache compiling.release Utils/source/apm_any.cpp
/usr/bin/ccache /usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/bin/x86_64-pc-linux-gnu-gcc -c -std=c++11 -IUtils/include -INetBase/include -I/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/include -Wall -o build/.objs/APM/linux/x86_64/release/Utils/source/apm_any.cpp.o Utils/source/apm_any.cpp
checking for the flags (-MMD -MF) ... ok
checking for the flags (-fcolor-diagnostics) ... no
checking for the flags (-fdiagnostics-color=always) ... ok
[ 69%]: ccache compiling.release NetBase/source/apm_abstract_udp_manager.cpp
/usr/bin/ccache /usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/bin/x86_64-pc-linux-gnu-gcc -c -std=c++11 -IUtils/include -INetBase/include -I/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/include -Wall -o build/.objs/APM/linux/x86_64/release/NetBase/source/apm_abstract_udp_manager.cpp.o NetBase/source/apm_abstract_udp_manager.cpp
[ 76%]: archiving.release libAPM.a
/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/bin/x86_64-pc-linux-gnu-ar -cr build/linux/x86_64/release/libAPM.a build/.objs/APM/linux/x86_64/release/Utils/source/apm_time_resolve.cpp.o build/.objs/APM/linux/x86_64/release/Utils/source/apm_logger.cpp.o build/.objs/APM/linux/x86_64/release/Utils/source/apm_any.cpp.o build/.objs/APM/linux/x86_64/release/NetBase/source/apm_net_utils.cpp.o build/.objs/APM/linux/x86_64/release/NetBase/source/apm_abstract_network_manager.cpp.o build/.objs/APM/linux/x86_64/release/NetBase/source/apm_abstract_udp_manager.cpp.o
checking for the x86_64-pc-linux-gnu-g++ ... /usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/bin/x86_64-pc-linux-gnu-g++
checking for the linker (ld) ... x86_64-pc-linux-gnu-g++
[ 92%]: linking.release TestUDP
/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/bin/x86_64-pc-linux-gnu-g++ -o build/linux/x86_64/release/TestUDP build/.objs/TestUDP/linux/x86_64/release/Test/Udp/main.cpp.o -Lbuild/linux/x86_64/release -L/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0/lib -lAPM -lpthread
[100%]: build ok!
skyfire@skyfire-pc /m/B/c/c/APM> 
@waruqi
Copy link
Member

waruqi commented Aug 21, 2020

if is_plat("x86_64") then
add_defines("TEST")
set_config("sdk","/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0")
end

is_plat 的判断取值 依赖 xmake f -p xxx 的配置结果,而 set_config("sdk") 也是覆盖的 xmake f --sdk 的结果,两个读取的阶段是同一个时间点,都会从 config 取值,不能有相互依赖,否则就会出现鸡生蛋的问题

而取 sdk 配置的时候,is_plat 还不一定有值,因为这个时候 --plat 也在取,还不能判断,所以 这个if前几次加载 会是 false

你只能吧 set_config 设置到全局,或者使用 is_xxx 不依赖 xmake f 的判断接口,例如 is_host

另外,-p x86_64 把 arch 设置到 plat ,这也太。。。。不是有 -a/--arch 配置参数么(不过这个也依赖config)。。

@waruqi
Copy link
Member

waruqi commented Aug 21, 2020

对于新版本,如果你要定制固定自己的 工具链路径和编译器,可以 参考 https://xmake.io/#/zh-cn/manual/custom_toolchain

通过 toolchain("xxx") 在自己的项目自定义自己的工具链,里面有 set_sdk 接口可以直接配置的。

这也是推荐做法,然后通过 https://xmake.io/#/zh-cn/manual/project_target?id=targetset_toolchains 这个就能绑定你的工具链到特定的target上去

@skyfireitdiy
Copy link
Author

明白了,多谢解惑

@skyfireitdiy
Copy link
Author

你好,使用自定义工具链,我看文档说的是在xmake.lua中使用toolchain自定义,然后使用xmake f --toolchain=xxx切换应该就可以了,这是我的工程配置xmake.lua

toolchain("mytool")
    set_kind("standalone")
    set_sdkdir("/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0")
toolchain_end()

add_includedirs("./Utils/include", "./NetBase/include")
add_cxxflags("-Werror")
set_languages("c++14")
if is_mode("debug") then
    add_cxxflags("-g", "-Og")
end

target("APM")
    set_kind("static")
    add_files("./Utils/source/*.cpp", "./NetBase/source/*.cpp")
    
target("TestUDP")
    set_kind("binary")
    add_deps("APM")
    add_files("./Test/Udp/main.cpp")
    add_links("pthread")

我在使用 xmake f --toolchain=mytool切换时报错了,如下:

skyfire@skyfire-pc /m/B/c/c/APM (master)> xmake show -l toolchains
error: the toolchain mytool not found!
skyfire@skyfire-pc /m/B/c/c/APM (master)> xmake f --toolchain=mytool
checking for the architecture ... x86_64
error: attempt to index field '_INFO' (a nil value)
skyfire@skyfire-pc /m/B/c/c/APM (master)>

请问我是不是哪里理解错了?

@skyfireitdiy skyfireitdiy reopened this Aug 22, 2020
@waruqi
Copy link
Member

waruqi commented Aug 22, 2020

set_toolset 没设置,toolchain 是完整的工具链定义和设置,不单纯只是 sdk 路径,还需要设置编译器链接器

请参考

#912 (comment)
https://github.com/xmake-io/xmake/blob/master/xmake/toolchains/cross/xmake.lua

@skyfireitdiy
Copy link
Author

toolchain("x86_64")
    set_description("x86_64 toolchain")
    set_kind("standalone")
    set_sdkdir("/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0")
    on_load(function (toolchain)
        import("core.project.config")
        local cross = "x86_64-pc-linux-gnu-"

        toolchain:set("toolset", "cc", cross .. "gcc")
        toolchain:set("toolset", "cxx", cross .. "gcc")
        toolchain:set("toolset", "cpp", cross .. "gcc -E")
        toolchain:set("toolset", "as", cross .. "gcc")
        toolchain:set("toolset", "ld", cross .. "g++")
        toolchain:set("toolset", "sh", cross .. "g++")
        toolchain:set("toolset", "ar", cross .. "ar")
        -- toolchain:set("toolset", "ex", cross .. "ar")
        -- toolchain:set("toolset", "ranlib", cross .. "ranlib")
        -- toolchain:set("toolset", "strip", cross .. "strip")

        local sdkdir = toolchain:sdkdir()
        if sdkdir then
            local includedir = path.join(sdkdir, "include")
            if os.isdir(includedir) then
                toolchain:add("includedirs", includedir)
            end
            local linkdir = path.join(sdkdir, "lib")
            if os.isdir(linkdir) then
                toolchain:add("linkdirs", linkdir)
            end
        end
    end)
    
toolchain_end()

我将toolchain修改为例子中所示的样子,还是报错:

skyfire@skyfire-pc /m/B/c/c/APM (master)> xmake f --toolchain=x86_64 
checking for the architecture ... x86_64
error: attempt to index field '_INFO' (a nil value)

请问on_check是必需的吗?还是说除了toolset外还要设置其他东西?

@skyfireitdiy
Copy link
Author

我是否应该在on_check中调用find_cross_toolchain返回一个toolchain?

@waruqi
Copy link
Member

waruqi commented Aug 22, 2020

toolchain("x86_64")
    set_description("x86_64 toolchain")
    set_kind("standalone")
    set_sdkdir("/usr/KIDE/host/ide/tools_chain/x86_64/x86_64_gcc6.2.0_glibc2.24.0")
    on_load(function (toolchain)
        import("core.project.config")
        local cross = "x86_64-pc-linux-gnu-"

        toolchain:set("toolset", "cc", cross .. "gcc")
        toolchain:set("toolset", "cxx", cross .. "gcc")
        toolchain:set("toolset", "cpp", cross .. "gcc -E")
        toolchain:set("toolset", "as", cross .. "gcc")
        toolchain:set("toolset", "ld", cross .. "g++")
        toolchain:set("toolset", "sh", cross .. "g++")
        toolchain:set("toolset", "ar", cross .. "ar")
        -- toolchain:set("toolset", "ex", cross .. "ar")
        -- toolchain:set("toolset", "ranlib", cross .. "ranlib")
        -- toolchain:set("toolset", "strip", cross .. "strip")

        local sdkdir = toolchain:sdkdir()
        if sdkdir then
            local includedir = path.join(sdkdir, "include")
            if os.isdir(includedir) then
                toolchain:add("includedirs", includedir)
            end
            local linkdir = path.join(sdkdir, "lib")
            if os.isdir(linkdir) then
                toolchain:add("linkdirs", linkdir)
            end
        end
    end)
    
toolchain_end()

我将toolchain修改为例子中所示的样子,还是报错:

skyfire@skyfire-pc /m/B/c/c/APM (master)> xmake f --toolchain=x86_64 
checking for the architecture ... x86_64
error: attempt to index field '_INFO' (a nil value)

请问on_check是必需的吗?还是说除了toolset外还要设置其他东西?

看下刚发你的 #912 (comment)

用 master dev 版本

@waruqi
Copy link
Member

waruqi commented Aug 22, 2020

我是否应该在on_check中调用find_cross_toolchain返回一个toolchain?

可选的 你都写死路径和工具链了了 加不加无所谓

@skyfireitdiy
Copy link
Author

好的,那#912 这个问题还没有在最新的版本中体现是吗?那么下一个正式版大概什么时候发布呢?

@waruqi
Copy link
Member

waruqi commented Aug 22, 2020

好的,那#912 这个问题还没有在最新的版本中体现是吗?那么下一个正式版大概什么时候发布呢?

是的 具体发版时间待定 估计8 9月份吧

@skyfireitdiy
Copy link
Author

好的,明白了,多谢

@waruqi
Copy link
Member

waruqi commented Aug 22, 2020

可以了么

@waruqi waruqi mentioned this issue Nov 1, 2020
@waruqi
Copy link
Member

waruqi commented Nov 1, 2020

关于这块,我继续改进了下,可以进一步简化配置,例如

toolchain("my_toolchain")
    set_kind("standalone")
    set_cross("arm-linux-musleabi-")
    set_sdkdir("/tmp/arm-linux-musleabi-cross")
toolchain_end()

target("hello")
    set_kind("binary")
    add_files("apps/hello/*.c")
    if is_plat("myplat") then
        set_toolchains("my_toolchain")
    end

常用cc/ld等交叉编译会自动检测,不需要设置全

具体可以到 #1008 跟进

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

No branches or pull requests

2 participants