【问题标题】:undefined reference to '__atomic_*' in SCons but similar questions' solution won't work在 SCons 中未定义对 \'__atomic_*\' 的引用,但类似的问题\' 解决方案将不起作用
【发布时间】:2022-09-28 03:05:10
【问题描述】:

我正在尝试使用 SCons 构建 Godot。一切正常,直到我在我的自定义模块使用的库中使用了std::atomic(该库与我为测试它而创建的 Qt 应用程序一起正常工作)。然后发生了这个错误:

[100%] Linking Program        ==> bin/godot.x11.tools.64
/usr/bin/ld: /home/sms/Code/_BUILDS/build-PyWally-Desktop-Release/libPyWally.so: undefined reference to `__atomic_store_16\'
/usr/bin/ld: /home/sms/Code/_BUILDS/build-PyWally-Desktop-Release/libPyWally.so: undefined reference to `__atomic_load_16\'
collect2: error: ld returned 1 exit status
scons: *** [bin/godot.x11.tools.64] Error 1
scons: building terminated because of errors.

我在谷歌上搜索并发现了原子/架构问题,所以我添加了-march=native-mtune=native-latomic,因为我有现代 x64 PC/系统,这不应该是一个问题......所以我的 SCsub 看起来像这样(wallycontroller 是我的自定义模块,pywally - 我的库):

Import(\'env\')

sources = [
    \"wallycontroller.cpp\",
    \"wallycontroller.cpp\",
    \"register_types.cpp\"
]

env.Append(CPPPATH=[\"/usr/include/python3.10\"])
env.Append(LIBS=[\'python3.10\'])
env.Append(CCFLAGS=[\'-march=native\', \'-mtune=native\', \'-latomic\'])

env.Append(CPPPATH=[\"#bin/../../PyWallie\"])
env.Append(LIBPATH=[\"#bin/../../../_BUILDS/build-PyWally-Desktop-Release\"])
env.Append(LIBS=[\'PyWally\'])

envw = env.Clone()
envw.Append(CCFLAGS=[\'-O2\'])

if ARGUMENTS.get(\'wallycontroller_shared\', \'no\') == \'yes\':
    envw.Append(CCFLAGS=[\'-fPIC\'])
    envw[\'LIBS\'] = []
    envw.Append(LIBS=[\'python3.10\'])
    envw.Append(LIBS=[\'PyWally\'])
    shared_lib = envw.SharedLibrary(target=\'#bin/../../godot_modules/wallycontroller\', source=sources)
    shared_lib_shim = shared_lib[0].name.rsplit(\'.\', 1)[0]
    env.Append(LIBS=[shared_lib_shim])
    env.Append(LIBPATH=[\'#bin\'])
else:
    envw.add_source_files(env.modules_sources, sources)

这些是我关于构建的 SCons 论点:

platform = \"x11\"
tools = \"yes\"
target = \"debug\"
bits = 64
custom_modules = \"../godot_modules\"
use_lto = \"yes\"
walliecontroller_shared = \"yes\"
udev = \"no\"

在我添加 std::atomic 之前,此配置不会发生任何问题,但它真的很方便,我不想删除它.​​.....任何帮助将不胜感激。

  • 哪个平台?哪个编译器(gcc、clang、other)?哪个编译器版本?您是否尝试将“原子”添加到您链接的库列表中? (或用谷歌搜索丢失的符号 __atomic_store_16?)
  • @bdbaddog Fedora x86_64,GCC 11.3.1。关于提议的解决方案,就像我在帖子中所说的那样,正如您在我的 SCsub 中看到的那样,我正在添加 -latomic、-march=native 和 -mtune=native,这些是我为 __atomic_store_16 搜索的解决方案:( libatomic.so 在我的 /usr/lib 中
  • 将“原子”添加到 LIBS,而不是 CCFLAGS

标签: c++ g++ scons godot stdatomic


【解决方案1】:

为了帮助您调试,请尝试暂时注释掉 LINKCOMSTR 的设置(应该在 methods.py 中),以便 SCons 可以向您显示整个链接行 - 通常 Godot 会尝试“提供帮助”并发出较短的消息,但它不会当您遇到诸如链接故障之类的事情时无济于事。你会大概请注意,它毕竟没有与 libatomic 链接。在 SCons 中,您实际上需要将该库添加到 LIBS(没有 -l)以将其传递给链接器。


一个单独的问题是为什么它认为它需要它 - 我假设您正在构建的架构具有原子支持?

在禁用优化的情况下,GCC 经常调用辅助函数来进行原子操作而不是内联。

对于 x86-64、GCC7 和更高版本 always calls a helper function 用于 16 字节原子,而不是内联 lock cmpxchg16b。 (现在它可以在带有 AVX 的 CPU 上使用 movaps,这可以保证 16 字节纯加载和纯存储的原子性。)所以在为 x86-64 编译时总是需要 gcc -latomic,如果你使用 16-字节原子对象。

【讨论】:

  • 好吧,它起作用了...这个库在这台 PC 上进行了测试,只是在 Qt 应用程序上,而不是用 SCons 构建...所以我想我有支持。谢谢!
猜你喜欢
  • 2020-11-17
  • 2018-03-31
  • 1970-01-01
  • 2015-11-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-10
相关资源
最近更新 更多