xmake-io / xmake

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

设置工具链为clang遇到的问题 #576

Closed owllyi closed 4 years ago

owllyi commented 4 years ago

使用命令行配置: xmake f -v --cc=clang --cxx=clang++ --ld=clang++ -m debug 可以正确保存工具链为clang,正确编译代码

但是我希望能在xmake.lua里直接设置工具链,不用再执行配置指令,这么写的: set_tools("cc", "/usr/bin/clang") set_tools("cxx", "/usr/bin/clang++") set_tools("ld", "/usr/bin/clang++")

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

-- add target target("hello") -- 之前set_tools放在这里,也不能生效

-- set kind
set_kind("binary")

-- add files
add_files("src/*.cpp") 

直接执行xmake,会默认使用gcc编译,clang++来链接。为什么不是使用clang++编译呢?

请问是不是我设置错了,要如何设置才能在不用调用xmake f配置的情况下,直接可以编译呢?

输出结果: checking for the architecture ... x86_64 configure { plat = linux arch = x86_64 ccache = true kind = static buildir = build host = linux mode = release ndk_stdcxx = true } checking for the gcc ... /usr/bin/gcc checking for the c++ compiler (cxx) ... gcc checking for the /usr/bin/gcc ... ok checking for the flags (-O3) ... ok checking for the ccache ... no [ 0%]: compiling.release src/main.cpp /usr/bin/gcc -c -fvisibility=hidden -O3 -m64 -I/usr/local/include -I/usr/include -o build/.objs/hello/linux/x86_64/release/src/main.cpp.o src/main.cpp checking for the flags (-MMD -MF) ... ok [100%]: linking.release hello clang++ -o build/linux/x86_64/release/hello build/.objs/hello/linux/x86_64/release/src/main.cpp.o -s -fvisibility=hidden -m64 -L/usr/local/lib -L/usr/lib

waruqi commented 4 years ago

如果你要去掉-target armv7-none-linux-androideabi,可以到 xmake的脚本安装目录。临时改下 platforms/android/load.lua

waruqi commented 4 years ago

你可以直接改下这个 https://github.com/xmake-io/xmake/blob/860f2ddcfee2546ec9feeb8749fc5e5acd2a5b43/xmake/platforms/android/load.lua#L52

owllyi commented 4 years ago

xmake f -p android --ndk_sdkver=16 --ndk_cxxstl=gnustl_static 改成这个编译失败,找不到map头文件。 去掉--ndk_cxxstl=gnustl_static,编译失败,提示:error: no member named 'at_quick_exit' in the global namespace

我看xmake还是在用这里的头文件:F:\Android\android-sdk\ndk-bundle\sources\cxx-stl\llvm-libc++/include\

还没看明白cmake怎么在16平台编译通过的。

owllyi commented 4 years ago

你可以直接改下这个

https://github.com/xmake-io/xmake/blob/860f2ddcfee2546ec9feeb8749fc5e5acd2a5b43/xmake/platforms/android/load.lua#L52

lua不是明文,luajit编译过了吧。是不是要下个lua明文的替换进去呢?

waruqi commented 4 years ago

额 我这不会啊 头文件也切到gnu了 你xmake f 配置的时候加个-c清下cache强制重新检测下环境配置

xmake f -p android --ndk_sdkver=16 --ndk_cxxstl=gnustl_static -c

owllyi commented 4 years ago

--ndk_sdkver=21 改成这个,终于可以在模拟器上运行了。昨天我试了23,试了22,就是没试21。 真艰难啊。我继续编译arm64和x86的库

waruqi commented 4 years ago

就是说还是 sdk version问题,必须要 <= 21 以下才行,而cmake默认用了16 所以没问题?

xmake目前的策略 是检测ndk提供的所有 sdk version list中选取最新的版本 作为默认版本来使用,所以默认生成的so有可能对于低版本的android环境有不兼容的问题。。

owllyi commented 4 years ago

嗯,cmake应该有一整套的判断选择机制,32位选的16,64位选的21。

xmake也可以研究下是什么机制,希望功能越来越强大。

再次感谢大大的支持,我继续使用,有什么问题再沟通哈。

waruqi commented 4 years ago

我改进了下dev版本,默认检测的sdkver,32位默认使用16,64位默认使用21,如果存在的话。。提高生产的so的兼容性。

你可以更新到dev试试。。xmake update -s dev

owllyi commented 4 years ago

好的,我更新下看看。希望能提供一种更新方式,能把lua文件在源码和编译文件间切换,方便大家学习理解xmake工作方式,也方便临时调试。

OpportunityLiu commented 4 years ago

xmake update -s dev 不就切过去了,不带-s又回来了

waruqi commented 4 years ago

好的,我更新下看看。希望能提供一种更新方式,能把lua文件在源码和编译文件间切换,方便大家学习理解xmake工作方式,也方便临时调试。

xmake update -s dev 就是仅更新lua脚本,不更新编译文件。 去掉 -s 就是完整更新

owllyi commented 4 years ago

看到了,dev里的lua都是源码了。

waruqi commented 4 years ago

看到了,dev里的lua都是源码了。

lua字节目前就首次安装才会启用,xmake update 里面我还没时间加上,即使后期加上,也会提供参数控制,只拉取lua源码的。。