xmake-io / xmake-vscode

🍩 A XMake integration in Visual Studio Code
https://xmake.io
Apache License 2.0
228 stars 55 forks source link

基于 VSCODE 不能进行 debug 查看变量信息 #171

Closed davidxiaozhi closed 1 year ago

davidxiaozhi commented 1 year ago

Xmake 版本

xmake v2.7.6+20230202, A cross-platform build utility based on Lua

操作系统版本和架构

Linux algserver 5.4.0-128-generic xmake-io/xmake#144-Ubuntu SMP Tue Sep 20 11:00:04 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

描述问题

1.VSCODE debug 时选择 xmake 无法 debug

image image image

依赖code lldb 已安装

image

另外我通过xmake 的工作栏 debug 执行代码时 会出现 /usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by release 模式下没问题,命令行的解决方案是通过把旧的删除掉 ,软连接到conda 的动态库

xmake.lua 已配置 add_includedirs("/App/conda/include")

add_linkdirs("/App/conda/lib")

conda 当中是已经安装 conda install -c conda-forge gxx_linux-64==12.2.0 -y

strings /App/conda/bin/../lib/libstdc++.so.6 | grep GLIBCXX_3.4.29

image

期待的结果

基于 vscode 能够完成 debug

工程配置

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

-- If you want to known more usage about xmake, please see https://xmake.io
--
-- ## FAQ
--
-- You can enter the project directory firstly before building project.
--
--   $ cd projectdir
--
-- 1. How to build project? 如何构建工程
--
--   $ xmake
--
-- 2. How to configure project? 如何配置工程,例如 debug 模式
--
--   $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release]
--
-- 3. Where is the build output directory? 构建产生的输出目录在那里
--
--   The default output directory is `./build` and you can configure the output directory.
--
--   $ xmake f -o outputdir
--   $ xmake
--
-- 4. How to run and debug target after building project?
--
--   $ xmake run [targetname]
--   $ xmake run -d [targetname]
--
-- 5. How to install target to the system directory or other output directory?
--
--   $ xmake install
--   $ xmake install -o installdir
--
-- 6. Add some frequently-used compilation flags in xmake.lua
--
-- @code
--    -- add debug and release modes
--    add_rules("mode.debug", "mode.release")
--
--    -- add macro defination
--    add_defines("NDEBUG", "_GNU_SOURCE=1")
--
--    -- set warning all as error
--    set_warnings("all", "error")
--
--    -- set language: c99, c++11
set_languages("c++17")
--
--    -- set optimization: none, faster, fastest, smallest
-- set_optimize("fastest")
--
--    -- add include search directories
-- add_includedirs("/App/conda/include","/usr/include", "/usr/local/include")
add_includedirs("/App/conda/include")
--
--    -- add link libraries and search directories
--    add_links("tbox")
-- add_linkdirs("/App/conda/lib","/usr/local/lib", "/usr/lib")
add_linkdirs("/App/conda/lib")
--
--    -- add system link libraries
add_syslinks("z", "pthread")
--
--    -- add compilation and link flags
--   add_cxflags("-stdnolib", "-fno-strict-aliasing")
--    add_ldflags("-L/usr/local/lib", "-lpthread", {force = true})
--
-- @endcode
--

-- https://xmake.io/#/zh-cn/guide/configuration?id=%e8%ae%be%e7%bd%aecc%e9%93%be%e6%8e%a5%e5%99%a8
set_config("ld", "clang++")

target("magic-hello")
    set_kind("binary") -- 编译类型 可以是 二进制 binary,动态库 shared,静态库 static
    add_files("src/*.cpp")

target("magic-01")
    set_kind("binary")
    add_files("src/01/*.cpp")

target("magic-04")
    set_kind("shared")
    add_files("src/04/*.cpp")
--     --configvar_check_features("HAS_CONSEXPR_AND_STATIC_ASSERT",{"cxx_aggregate_bases", "cxx_aligned_new", "cxx_capture_star_this", "cxx_constexpr", "cxx_deduction_guides", "cxx_enumerator_attributes", "cxx_fold_expressions", "cxx_guaranteed_copy_elision", "cxx_hex_float", "cxx_if_constexpr", "cxx_inheriting_constructors", "cxx_inline_variables", "cxx_namespace_attributes", "cxx_noexcept_function_type", "cxx_nontype_template_args", "cxx_nontype_template_parameter_auto", "cxx_range_based_for", "cxx_static_assert", "cxx_structured_bindings", "cxx_template_template_args", "cxx_variadic_using"}, {languages = "c++17"})

target("magic-05")
    set_kind("binary")
    add_files("src/05/*.cpp")    

附加信息和错误日志

/usr/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found ,命令行debug已解决,请问是否通过配置使用 conda 里的动态可以解决 vscode debug 未解决

waruqi commented 1 year ago

这个好像跟 xmake 也没啥关系,要么 conda 的问题,要么 codelldb 和 cpptools 插件的问题,xmake-vscode 也仅仅只是透传给它们 直接加载调试

另外 conda 库,直接包集成干嘛不用 add_requires("conda::xxx")/add_packages("conda::xxx")

davidxiaozhi commented 1 year ago

@waruqi 这里还没有使用 conda 内部的其他库,当前只是 gcc,未来打算使用, 另外 要么 conda 的问题,要么 codelldb 和 cpptools 插件的问题,这个是只我的配置文件有问题么, 结合 xmake 配置 debug 有什么建议,还是直接依据 codelldb 或者 cpptools 的官方要求配置 就可以了

waruqi commented 1 year ago

推荐走官方仓库包,插件调试运行,会内置每个包动态加载需要的环境变量信息。比如 LD_LIBRARY_PATH,然后透传给调试器,以及级联依赖支持。。

用 conda 等第三方库,里面的 so 加载,目前没 LD_LIBRARY_PATH 自动设置支持,你得自己外面配置加载环境

调试器 走 cpptools/codelldb 都可以,但不管走哪个,xmake 只能送 可执行文件路径给它们加载,依赖的 so 库,需要它们去找。。

先确认 xmake run 运行是否正常,xmake run 里面会对 xmake-repo 仓库包自动加载对应环境变量,如果正常,就是 so 的加载路径问题,如果也不正常,自己 ldd 调下。

编译器不用改,走默认 gcc clang 都可以

davidxiaozhi commented 1 year ago

好的, xmake run 运行是没问题的, 基于 conda 的动态库 LD_LIBRARY_PATH 未来确实需要基于环境变量设置一下,提前学到了,我重新 review 以下插件,我怀疑是cpp插件的问题,好了这里同步,也希望其他的小白们可以借鉴

waruqi commented 1 year ago

那就是 LD_LIBRARY_PATH 没设置,目前仅仅 xmake-repo 仓库包,我内部会配置各种 LD_LIBRARY_PATH PATH 等变量,确保运行正常,也会传给调试器,不用额外配置。。

但是第三方包仓库,提供的包信息有限,xmake 并不知道哪些路径需要设置 LD_LIBRARY_PATH 的,所以只能用户自己外面配置。

所以建议尽量用 xmake-repo 里面包

davidxiaozhi commented 1 year ago

使用 xmake 的时候 请教一下通过vscode debug 的时候 launch.json 如何正确配置

image image image

下面的如何正确配置

image
davidxiaozhi commented 1 year ago

看到知乎的录制视频了,借鉴一下 https://www.zhihu.com/question/353722203

davidxiaozhi commented 1 year ago
image

视频当中,单击 xmake 下方的 debug, 自动就可以 debug ,但是我的 demo 当中不行,是不是多个 target 的原因, 如何调整配置,有一些建议么 另外视频当中下面的文件生成, image提示信息如下

image
waruqi commented 1 year ago

不需要设置 launch.json,装下 codelldb 和 cpptools 插件,然后点下面的调试

davidxiaozhi commented 1 year ago

codelldb 和 cpptools 已安装,并同步到容器内了 codelldb 插件在容器内已同步安装

image

cpptools 插件

image

点击下面的调试

image

弹出设置窗口 提示b不能决定 debugger path 需要指定 MIDebuggerPath

image

@waruqi

waruqi commented 1 year ago

你 gdb 装了么,它提示找不到 调试器

https://github.com/xmake-io/xmake-vscode/blob/06a258318c2d32f2f7871130a806a6f889a0eed9/src/debugger.ts#L137

也就是加载调试的时候,vscode 会去调用 gdb 调试的,但是 vscode 没找到 gdb 。。就报错了。。

如果是在容器里面跑,先看下是否装了 gdb,如果装了,再确认下是否具有调试权限。。我记得容器里调试,需要开些权限的,否则 gdb 里面没法断点调试。。

davidxiaozhi commented 1 year ago

之前插件没有同步的时候,xmake 点击debug 启动的是命令行调试,当时我基于命令行是可以的,所以应该是安装过的,我重新安装一下lldb 和 gdb 试试,我也发现是调试器找不到,估计容器被人 kill 过的原因,我重新安装一下看看

waruqi commented 1 year ago

https://github.com/xmake-io/xmake-vscode/blob/06a258318c2d32f2f7871130a806a6f889a0eed9/src/debugger.ts#L28

目前是调用 xmake l find_gdb.lua 去找 gdb 的。。

你可以调下插件里面这个脚本 https://github.com/xmake-io/xmake-vscode/blob/06a258318c2d32f2f7871130a806a6f889a0eed9/assets/find_gdb.lua

也可以清下项目的缓存,强制重新找下。。xmake f -c

davidxiaozhi commented 1 year ago

我 debug 发现是 conda 在借鉴依赖冲突时导致之前的 lldb 和 gdb 消失了导致的,我重新初始化容器后 xmake 编译出现


error: /App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/Main.cpp.o: in function `main':
/home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:13: undefined reference to `std::cout'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:13: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:13: undefined reference to `std::ostream::operator<<(int)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:13: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:13: undefined reference to `std::ostream::operator<<(int)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:13: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:14: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:14: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:14: undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:19: undefined reference to `std::cout'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:19: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:19: undefined reference to `std::ostream::operator<<(int)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:19: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:19: undefined reference to `std::ostream::operator<<(int)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:19: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:20: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:20: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:20: undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/Main.cpp.o: in function `__cxx_global_var_init':
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/include/c++/12.2.0/iostream:74: undefined reference to `std::ios_base::Init::Init()'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/Main.cpp.o: in function `__cxx_global_var_init':
/home/z.li/develop/project/git_projects/magic-cplus17/build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/__cpp_Main.cpp.cpp:(.text.startup+0x13): undefined reference to `std::ios_base::Init::~Init()'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/Stack.cpp.o: in function `Stack::push(int)':
/home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Stack.cpp:11: undefined reference to `operator new(unsigned long)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Stack.cpp:11: undefined reference to `operator delete(void*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/Stack.cpp.o: in function `Stack::pop()':
/home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Stack.cpp:25: undefined reference to `operator delete(void*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/Stack.cpp.o:(.data.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /App/conda/lib/libz.so: undefined reference to `memcpy@GLIBC_2.14'
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)```
davidxiaozhi commented 1 year ago

@waruqi ld: /App/conda/lib/libz.so: undefined reference to `memcpy@GLIBC_2.14' 确实是libz 使用的 glibc 版本为 2.14

objdump -T  /App/conda/lib/libz.so |grep memcp
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.14  memcpy

下面是xmake.conf { __toolchains_linux_x86_64 = { "clang-15" }, arch = "x86_64", buildir = "build", ccache = true, host = "linux", kind = "static", mode = "debug", ndk_stdcxx = true, plat = "linux", toolchain = "clang-15" } 我尝试升级试试

waruqi commented 1 year ago

我 debug 发现是 conda 在借鉴依赖冲突时导致之前的 lldb 和 gdb 消失了导致的,我重新初始化容器后 xmake 编译出现

error: /App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/Main.cpp.o: in function `main':
/home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:13: undefined reference to `std::cout'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:13: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:13: undefined reference to `std::ostream::operator<<(int)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:13: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:13: undefined reference to `std::ostream::operator<<(int)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:13: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:14: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:14: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:14: undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:19: undefined reference to `std::cout'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:19: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:19: undefined reference to `std::ostream::operator<<(int)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:19: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:19: undefined reference to `std::ostream::operator<<(int)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:19: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:20: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:20: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Main.cpp:20: undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/Main.cpp.o: in function `__cxx_global_var_init':
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/include/c++/12.2.0/iostream:74: undefined reference to `std::ios_base::Init::Init()'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/Main.cpp.o: in function `__cxx_global_var_init':
/home/z.li/develop/project/git_projects/magic-cplus17/build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/__cpp_Main.cpp.cpp:(.text.startup+0x13): undefined reference to `std::ios_base::Init::~Init()'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/Stack.cpp.o: in function `Stack::push(int)':
/home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Stack.cpp:11: undefined reference to `operator new(unsigned long)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Stack.cpp:11: undefined reference to `operator delete(void*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/Stack.cpp.o: in function `Stack::pop()':
/home/z.li/develop/project/git_projects/magic-cplus17/src/example/01/stack/Stack.cpp:25: undefined reference to `operator delete(void*)'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/.objs/magic-stack/linux/x86_64/debug/src/example/01/stack/Stack.cpp.o:(.data.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /App/conda/lib/libz.so: undefined reference to `memcpy@GLIBC_2.14'
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)```

装下 libstdc++ 或者 libc++ ,linker 确保使用 clang++/g++

davidxiaozhi commented 1 year ago

@waruqi conda install -n conda_xmake gcc==12.2.0 gxx==12.2.0 clang==15.0.6 clangdev clangxx clang-format==15.0.6 llvm python-clang pip gxx_linux-64==12.2.0 gdb -y conda install -c conda-forge libgcc-ng==12.2.0 lldb -y 这个已经安装 linker 已经配置为 clang++

image image

下面是 log,

/App/conda/envs/conda_xmake/bin/../lib/gcc/x86_64-conda-linux-gnu/12.2.0/../../../../x86_64-conda-linux-gnu/bin/ld: /App/conda/lib/libz.so: undefined reference to `memcpy@GLIBC_2.14

我怀疑是 zlib 的问题,但我 conda 升级 zlib 到最新的版本还是这样

objdump -T  /App/conda/lib/libz.so |grep memcp
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.14  memcpy

执行 xmake f -c 后 @waruqi log 变更为

[ 60%]: linking.release libmagic-04.so
[ 60%]: linking.release magic-05
[ 60%]: linking.release magic-01
[ 60%]: linking.release magic-lib2
error: /App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-ld: unrecognised emulation mode: 64
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu

@waruqi xmake.lua

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

-- If you want to known more usage about xmake, please see https://xmake.io
--
-- ## FAQ
--
-- You can enter the project directory firstly before building project.
--
--   $ cd projectdir
--
-- 1. How to build project? 如何构建工程
--
--   $ xmake
--
-- 2. How to configure project? 如何配置工程,例如 debug 模式
--
--   $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release]
--
-- 3. Where is the build output directory? 构建产生的输出目录在那里
--
--   The default output directory is `./build` and you can configure the output directory.
--
--   $ xmake f -o outputdir
--   $ xmake
--
-- 4. How to run and debug target after building project?
--
--   $ xmake run [targetname]
--   $ xmake run -d [targetname]
--
-- 5. How to install target to the system directory or other output directory?
--
--   $ xmake install
--   $ xmake install -o installdir
--
-- 6. Add some frequently-used compilation flags in xmake.lua
--
-- @code
--    -- add debug and release modes
--    add_rules("mode.debug", "mode.release")
--
--    -- add macro defination
--    add_defines("NDEBUG", "_GNU_SOURCE=1")
--
--    -- set warning all as error
--    set_warnings("all", "error")
--
--    -- set language: c99, c++11
set_languages("c++17")
--
--    -- set optimization: none, faster, fastest, smallest
-- set_optimize("fastest")
--
--    -- add include search directories
-- add_includedirs("/App/conda/include","/usr/include", "/usr/local/include")
-- add_includedirs("/App/conda/include")
--
--    -- add link libraries and search directories
--    add_links("tbox")
-- add_linkdirs("/App/conda/lib","/usr/local/lib", "/usr/lib")
-- add_linkdirs("/App/conda/lib")
--
--    -- add system link libraries
add_syslinks("z", "pthread")
--
--    -- add compilation and link flags
--   add_cxflags("-stdnolib", "-fno-strict-aliasing")
--    add_ldflags("-L/usr/local/lib", "-lpthread", {force = true})
--
-- @endcode
--

-- https://xmake.io/#/zh-cn/guide/configuration?id=%e8%ae%be%e7%bd%aecc%e9%93%be%e6%8e%a5%e5%99%a8
--set_config("ld", "clang++")

 set_config("ld", "clang++")

target("magic-hello")
    set_kind("binary") -- 编译类型 可以是 二进制 binary,动态库 shared,静态库 static
    add_files("src/*.cpp")

target("magic-01")
    set_kind("binary")
    add_files("src/stl/01/*.cpp")

target("magic-04")
    set_kind("shared")
    add_files("src/stl/04/*.cpp")

target("magic-05")
    set_kind("binary")
    add_files("src/stl/05/*.cpp")    

target("magic-car")
    set_kind("binary")
    --add_files("src/example/01/car/*.h")
    add_files("src/example/01/car/*.cpp")

target("magic-person")
    set_kind("binary")
    --add_files("src/example/01/car/*.h")
    add_files("src/example/01/person/*.cpp")

target("magic-stack")
    set_kind("binary")
    add_files("src/example/01/stack/*.cpp")
target("magic-lib2")
    set_kind("binary")
    add_files("src/example/03/*.cpp")
waruqi commented 1 year ago

set_config("ld", "clang++")

你只要不改 ld,默认就是 g++/clang++

没必要设置,想切 clang ,只需要整体切 --toolchain=clang

waruqi log 变更为

带 -v 的 link logs

davidxiaozhi commented 1 year ago

@waruqi 现在是任何一个xmake工程,都不能编译,比如之前基于xmake 创建 c++的默认工程,xmake f -c 后,执行 xmake 编译会出现

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

set_languages("c++17")

--set_optimize("fastest")

add_includedirs("/App/conda/include")

target("hello")
    set_kind("binary")
    add_files("src/*.cpp")

--
-- If you want to known more usage about xmake, please see https://xmake.io
--
-- ## FAQ
--
-- You can enter the project directory firstly before building project.
--
--   $ cd projectdir
--
-- 1. How to build project?
--
--   $ xmake
--
-- 2. How to configure project?
--
--   $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release]
--
-- 3. Where is the build output directory?
--
--   The default output directory is `./build` and you can configure the output directory.
--
--   $ xmake f -o outputdir
--   $ xmake
--
-- 4. How to run and debug target after building project?
--
--   $ xmake run [targetname]
--   $ xmake run -d [targetname]
--
-- 5. How to install target to the system directory or other output directory?
--
--   $ xmake install
--   $ xmake install -o installdir
--
-- 6. Add some frequently-used compilation flags in xmake.lua
--
-- @code
--    -- add debug and release modes
--    add_rules("mode.debug", "mode.release")
--
--    -- add macro defination
--    add_defines("NDEBUG", "_GNU_SOURCE=1")
--
--    -- set warning all as error
--    set_warnings("all", "error")
--
--    -- set language: c99, c++11
--    set_languages("c99", "c++11")
--
--    -- set optimization: none, faster, fastest, smallest
--    set_optimize("fastest")
--
--    -- add include search directories
--    add_includedirs("/usr/include", "/usr/local/include")
--
--    -- add link libraries and search directories
--    add_links("tbox")
--    add_linkdirs("/usr/local/lib", "/usr/lib")
--
--    -- add system link libraries
--    add_syslinks("z", "pthread")
--
--    -- add compilation and link flags
--    add_cxflags("-stdnolib", "-fno-strict-aliasing")
--    add_ldflags("-L/usr/local/lib", "-lpthread", {force = true})
--
-- @endcode
--

这个工程之前是能够运行,最新的环境内不知道是缺了什么

davidxiaozhi commented 1 year ago

@waruqi /App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-ld: unrecognised emulation mode: 64 Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu 升级了 cuda 的镜像版本,现在镜像构建好后,基于 xmake 好像 ld 就不可用了,各种问题

waruqi commented 1 year ago

我要 logs -v 刚说了

davidxiaozhi commented 1 year ago

set_config("ld", "clang++")

你只要不改 ld,默认就是 g++/clang++

没必要设置,想切 clang ,只需要整体切 --toolchain=clang

waruqi log 变更为

带 -v 的 link logs

@waruqi 不好意思,上面刚开始没看懂,下面是xmake 生成的 hello c++工程 -v 后输出的 log xmake build -v

checking for /App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ ... ok
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for /App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ ... ok
checking for flags (-fPIC) ... no
checking for flags (-fvisibility-inlines-hidden) ... no
checking for flags (-O3) ... no
checking for flags (-DNDEBUG) ... no
checking for /App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-ld ... ok
checking for the linker (ld) ... x86_64-conda-linux-gnu-ld
[ 50%]: linking.release hello
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-ld -o build/linux/x86_64/release/hello build/.objs/hello/linux/x86_64/release/src/main.cpp.o -m64 -s
error: /App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-ld: unrecognised emulation mode: 64
Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu

warning: add_cxflags("-DNDEBUG") is ignored, please pass `{force = true}` or call `set_policy("check.auto_ignore_flags", false)` if you want to set it.

这个是 magic 工程 xmake build -v 输出的 log

make build -v
checking for /App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ ... ok
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for the c++ compiler (cxx) ... x86_64-conda-linux-gnu-c++
checking for /App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ ... ok
checking for flags (-fPIC) ... no
checking for flags (-fvisibility-inlines-hidden) ... no
checking for flags (-O3) ... no
checking for flags (-fvisibility-inlines-hidden) ... no
checking for flags (-DNDEBUG) ... no
[ 19%]: cache compiling.release src/stl/04/template.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -std=c++17 -o build/.objs/magic-04/linux/x86_64/release/src/stl/04/template.cpp.o src/stl/04/template.cpp
[ 19%]: cache compiling.release src/main.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-hello/linux/x86_64/release/src/main.cpp.o src/main.cpp
[ 19%]: cache compiling.release src/example/01/stack/Cell.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-stack/linux/x86_64/release/src/example/01/stack/Cell.cpp.o src/example/01/stack/Cell.cpp
[ 19%]: cache compiling.release src/stl/05/main.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-05/linux/x86_64/release/src/stl/05/main.cpp.o src/stl/05/main.cpp
[ 19%]: cache compiling.release src/example/01/stack/Stack.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-stack/linux/x86_64/release/src/example/01/stack/Stack.cpp.o src/example/01/stack/Stack.cpp
[ 19%]: cache compiling.release src/example/03/Book.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-lib2/linux/x86_64/release/src/example/03/Book.cpp.o src/example/03/Book.cpp
[ 19%]: cache compiling.release src/example/01/car/Car.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-car/linux/x86_64/release/src/example/01/car/Car.cpp.o src/example/01/car/Car.cpp
[ 19%]: cache compiling.release src/example/03/Customer.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-lib2/linux/x86_64/release/src/example/03/Customer.cpp.o src/example/03/Customer.cpp
[ 19%]: cache compiling.release src/example/01/person/Person.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-person/linux/x86_64/release/src/example/01/person/Person.cpp.o src/example/01/person/Person.cpp
[ 19%]: cache compiling.release src/example/01/stack/Main.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-stack/linux/x86_64/release/src/example/01/stack/Main.cpp.o src/example/01/stack/Main.cpp
[ 19%]: cache compiling.release src/example/01/person/Student.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-person/linux/x86_64/release/src/example/01/person/Student.cpp.o src/example/01/person/Student.cpp
[ 19%]: cache compiling.release src/example/03/Main.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-lib2/linux/x86_64/release/src/example/03/Main.cpp.o src/example/03/Main.cpp
[ 19%]: cache compiling.release src/example/01/person/Main.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-person/linux/x86_64/release/src/example/01/person/Main.cpp.o src/example/01/person/Main.cpp
[ 19%]: cache compiling.release src/example/01/person/Employee.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-person/linux/x86_64/release/src/example/01/person/Employee.cpp.o src/example/01/person/Employee.cpp
[ 19%]: cache compiling.release src/example/01/car/Main.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-car/linux/x86_64/release/src/example/01/car/Main.cpp.o src/example/01/car/Main.cpp
[ 19%]: cache compiling.release src/example/03/Library.cpp
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-c++ -c -m64 -fvisibility=hidden -std=c++17 -o build/.objs/magic-lib2/linux/x86_64/release/src/example/03/Library.cpp.o src/example/03/Library.cpp
checking for flags (-MMD -MF) ... no
checking for flags (-fdiagnostics-color=always) ... no
checking for flags (-fcolor-diagnostics) ... no
checking for /App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-ld ... ok
checking for the linker (ld) ... x86_64-conda-linux-gnu-ld
[ 60%]: linking.release magic-person
/App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-ld -o build/linux/x86_64/release/magic-person build/.objs/magic-person/linux/x86_64/release/src/example/01/person/Person.cpp.o build/.objs/magic-person/linux/x86_64/release/src/example/01/person/Student.cpp.o build/.objs/magic-person/linux/x86_64/release/src/example/01/person/Employee.cpp.o build/.objs/magic-person/linux/x86_64/release/src/example/01/person/Main.cpp.o -m64 -s -lz -lpthread
error: /App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-ld: unrecognised emulation mode: 64
waruqi commented 1 year ago

[ 60%]: linking.release magic-person /App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-ld -o buil

为什么你会去用 x86_64-conda-linux-gnu-ld ?

刚说了 linker 走 g++ 或者 clang++

如果自己没配置修改,就检查下 $LD 什么的环境变量,看是否有设置。

davidxiaozhi commented 1 year ago

[ 60%]: linking.release magic-person /App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-ld -o buil

为什么你会去用 x86_64-conda-linux-gnu-ld ?

刚说了 linker 走 g++ 或者 clang++

如果自己没配置修改,就检查下 $LD 什么的环境变量,看是否有设置。 好的 ,我这里没有修改配置,我看看环境变量,xmake 可以 debug 出来从哪里找到的 /App/conda/envs/conda_xmake/bin/x86_64-conda-linux-gnu-ld 么

waruqi commented 1 year ago

看下 $LD $CC 环境变量设置,有的话,去掉。。或者走 --toolchain=gcc 或者 --toolchain=clang 切下。

davidxiaozhi commented 1 year ago

定位是 conda 的虚拟环境激活设置的 LD

waruqi commented 1 year ago

看下 $LD $CC 环境变量设置,有的话,去掉。。或者走 --toolchain=gcc 或者 --toolchain=clang 切下。

那就按上面的方式处理下

davidxiaozhi commented 1 year ago

@waruqi 嗯 已处理 xmake f --toolchain=clang 比较好使, 但是更新 xmake.lua 后, vscode xmake 插件菜单就会恢复默认,再次基于 vscode切换clang-15 通过 xmake 插件 和 命令行 build 都会出现 /usr/bin/ld: build/.objs/magic-car/linux/x86_64/release/src/example/01/car/Main.cpp.o:(.data.DW.ref.gxx_personality_v0[DW.ref.gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0' clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

ld 由 conda 当中的 ld 变成了系统的 ld (/usr/bin/ld),这里$LD 依然为空, 但是通过命令行再次执行 xmake f --toolchain=clang 就会恢复正常,默认 xmake 选择的并不是 clang

waruqi commented 1 year ago

@waruqi 嗯 已处理 xmake f --toolchain=clang 比较好使, 但是更新 xmake.lua 后, vscode xmake 插件菜单就会恢复默认,再次基于 vscode切换clang-15 通过 xmake 插件 和 命令行 build 都会出现 /usr/bin/ld: build/.objs/magic-car/linux/x86_64/release/src/example/01/car/Main.cpp.o:(.data.DW.ref.gxx_personality_v0[DW.ref.gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0' clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

ld 由 conda 当中的 ld 变成了系统的 ld (/usr/bin/ld),这里$LD 依然为空, 但是通过命令行再次执行 xmake f --toolchain=clang 就会恢复正常,默认 xmake 选择的并不是 clang

set_toolchains 可以配置到 xmake.lua,或者插件配置里面有个 additionalConfigs 配置参数,可以配到那里

davidxiaozhi commented 1 year ago

重新打开 vscode xmake插件菜单就会恢复默认, xmake 插件重新选择 clang-15 的时候,通过 xmake 插件编译仍然会出现上面的问题,我看日志还是 ld 切换为了非 clang

davidxiaozhi commented 1 year ago

set_toolchains 可以配置到 xmake.lua

set_toolchains 可以配置到 xmake.lua 这个是只针对单个 target 的,针对全局是不是还是上面的命令行更保险

davidxiaozhi commented 1 year ago

@waruqi 其实只要设置成功了就能成功 debug 了,现在,LD 目前没有环境变量,默认死系统的 LD 非 g++ 或者 clang++ 看样需要 debug 一下 xmake ,到时可能还得请教

waruqi commented 1 year ago

set_toolchains 可以配置到 xmake.lua

set_toolchains 可以配置到 xmake.lua 这个是只针对单个 target 的,针对全局是不是还是上面的命令行更保险

你在 root scope 设置,不就全局生效了么,而且插件底下也有专门的 tool bar 可以切 toolchain

davidxiaozhi commented 1 year ago

@waruqi 而且插件底专门的 tool bar 切 toolchain 为 clang15 不好使, ld 没有切换 其他的切换过来了, xmake f --toolchain=clang 这个是最好使的

waruqi commented 1 year ago

@waruqi 而且插件底专门的 tool bar 切 toolchain 为 clang15 不好使, ld 没有切换 其他的切换过来了, xmake f --toolchain=clang 这个是最好使的

toolbar 里可以选 clang 的,干嘛要用 clang15呢,就是自动传 --toolchain=clang 一样的效果,跟你命令行设置有啥区别?

image

而且 set_toolchains 全局切也可以,刚说了。

xmake f --toolchain=clang

之前也说了,插件配置里,可以写死配置的,不用命令敲

或者插件配置里面有个 additionalConfigs 配置参数,可以配到那里

davidxiaozhi commented 1 year ago

@waruqi 我理解错了,我以为 clang15 和 clang 是一样的效果,我测试一下

waruqi commented 1 year ago

clang-15 指的是 一些系统上走 apt install clang-15 安装的特定版本 clang 。。编译器 bin 本身文件名就是 /usr/bin/clang-15 这种。。

davidxiaozhi commented 1 year ago

@waruqi 好的总结问题产生的背景基于c++17 编译器 clang 15.0.6 ,clang 15.0.6 是依赖 gcc-12.2.0 ,c++标准库 gxx_linux-64==12.2.0

  1. debug 依赖 codelldb 插件, 基于 conda 升级 clang 会导致 gdb lldb 安装失败不可用,影响debug
  2. 默认 ld 问题,xmake 推荐 linker 使用 g++ 或者 clang++ 如果默认获取linker 非 以上两个,需要切换整个 toolchain 2.1 xmake f --toolchain=clang 2.2 xmake.lua 内 set_toolchains 全局配置切 2.3 xmake 菜单切换 toolchains 这里需要注意的是选择 clang 非其他的类似 clang-15 的 toolchains,特殊场景除外

新手小白,都可以参考

conda 初始化环境 可以借鉴

RUN conda create -n conda_xmake python=3.9 -y

RUN conda update -n conda_xmake -c defaults conda

RUN conda install -n conda_xmake pytorch torchvision torchaudio cudatoolkit=11.8 -c pytorch -c conda-forge -y RUN conda install -n conda_xmake gcc==12.2.0 gxx==12.2.0 clang==15.0.6 clangdev clangxx clang-format==15.0.6 llvm python-clang pip gxx_linux-64==12.2.0 gdb -y Run conda install -c conda-forge libgcc-ng==12.2.0 lldb -y