由于“多重定义”构建失败本地依赖项中的链接器错误 [英] Build fails because of "multiple definition" linker errors in native dependencies

查看:299
本文介绍了由于“多重定义”构建失败本地依赖项中的链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我维护一个使用 CircleCI 进行持续集成的开源框架。我最近遇到了一堵墙,项目突然拒绝在相当奇怪的情况下建造。

Build 27 是成功的最后一个。之后,我对依赖关系做了一些小改动,并注意到构建失败。我试图解决它没有成功,所以我恢复了上次工作配置 ,它仍然失败

失败的原因是两个依赖关系,它们都绑定到本地C库:OpenGL( OpenGLRaw )和GLFW( bindings-glfw )。他们错误地在链接阶段与许多行:

  /tmp/ghc18975_0/ghc18975_6.o :(。data + 0x0) :`__stginit_bindizu0Qm7f8FzzUN32WFlos7AKUm_BindingsziGLFW'
/tmp/ghc18975_0/ghc18975_6.o:(.data+0x0)的多重定义:首先在此定义

我完全不知道为什么会发生这种情况。这些库的完全相同版本是在原始构建通过时构建的,并且在CI上每次都使用新的容器(我试图清除缓存)。但是构建涉及 apt-get update cabal update ,所以有可能某些外部资源发生了变化。

如果有人遇到过这样或那样的问题,它可能对诊断和解决问题有很大的帮助。谷歌搜索这个特定的多重定义这个比例的问题不会产生任何结果。
$ b




我尝试更新cabal版本(因为互联网上的一些提示指出了它),但是:

  cabal-使用Cabal库的版本1.22.4.0安装版本1.22.6.0 

问题依然存在。




我忘记提及的一件重要事情是,这看起来不像一些简单的包装混合。我通过SSH连接到该框,在那里创建了一个空文件夹和一个沙箱,甚至简单的 cabal install OpenGLRaw 也出现了同样的问题(所以它本身不太可能会拉在同一模块的两个版本中可能导致这些冲突)。






我也提取了详细的cabal安装日志




又是SSH,克隆了OpenGLRaw的原始资源,仍然是一样的。尝试7.6.3,仍然是一样的。

解决方案

这似乎是 gcc-4.9的一个问题0.2 。我分叉你的项目,开始构建高度冗长,连接到circleci容器并运行确切的链接命令。它以同样的方式失败:

  ubuntu @ box1305:〜$ / usr / bin / gcc -fno-stack-protector -DTABLES_NEXT_TO_CODE '-W1, - 散列大小= 31'-W1, - 减少内存开销-W1, - 不需要-nostdlib -Wl,-r -nodefaultlibs'-W1, - 构建ID = none'-o Types.o /tmp/ghc17998_0/ghc_15.ldscript 
/tmp/ghc17998_0/ghc_14.o:函数`r2vy_closure':
(.data + 0x0):多重定义` __stginit_OpenGzu8rT20eO9AxEKIONeYf57cS_GraphicsziRenderingziOpenGLziRawziTypes'
/tmp/ghc17998_0/ghc_14.o:(.data+0x0):首先在这里定义
/tmp/ghc17998_0/ghc_14.o:函数`r2vy_closure':
(。数据+ 0x8):多重定义`OpenGzu8rT20eO9AxEKIONeYf57cS_GraphicsziRenderingziOpenGLziRawziTypes_makeGLDEBUGPROC_closure'
/tmp/ghc17998_0/ghc_14.o:(.data+0x8):首先在这里定义
/tmp/ghc17998_0/ghc_14.o:在函数` c2y7_info':
(.text + 0xc0):多重定义`OpenGzu8rT20eO9AxEKIONeYf57cS_GraphicsziRenderingziOpenGLziRawziTypes_makeGLDEBUGPROC_info '
/tmp/ghc17998_0/ghc_14.o:(.text+0xc0):首先在此处定义

但使用 gcc-4.8 它可以工作:

  ubuntu @ box1305:〜$ /usr/bin/gcc-4.8 -fno-stack-protector -DTABLES_NEXT_TO_CODE'-W1, -  hash-size = 31'-W1, - 减少内存开销-W1, -  no-as -neded -nostdlib -Wl,-r -nodefaultlibs'-Wl, -  build-id = none'-o Types.o /tmp/ghc17998_0/ghc_15.ldscript 
ubuntu @ box1305:〜$

因此,您应该切换到较旧的 gcc ,并可能报告错误至 gcc 开发者。



ADDED: 这里是一个如何切换 gcc 版本的例子。 这里是一个成功的构建。


I maintain an open-source framework that uses CircleCI for continuous integration. I've recently hit a wall where the project suddenly refused to build in rather strange circumstances.

Build 27 was the last one that succeeded. After that, I made some minor changes to dependencies and noticed that the build fails. I've tried to fix it without success, so I reverted back to last working configuration and it still failed.

The reason for failure are two dependencies, both being bindings to native C libraries: OpenGL (OpenGLRaw) and GLFW (bindings-glfw). They error out in link stage with numerous lines of:

/tmp/ghc18975_0/ghc18975_6.o:(.data+0x0): multiple definition of `__stginit_bindizu0Qm7f8FzzUN32WFlos7AKUm_BindingsziGLFW'
/tmp/ghc18975_0/ghc18975_6.o:(.data+0x0): first defined here

I am totally stumped as for why that might happen. The exact same versions of those libraries were built back when the original build passed, and being on CI it uses a fresh container each time (I've tried cleaning the cache obviously). The build involves both apt-get update and cabal update though, so there's a possibility that some external resource was changed.

If anyone has ever encountered such or similar problem, it might vastly help in diagnosing and removing the issue. Google search for this specific multiple definition problem of that scale yields nothing.


I tried to update cabal version (since some hints over the internet pointed at it), but with:

cabal-install version 1.22.6.0
using version 1.22.4.0 of the Cabal library

The problem persists.


One important thing I forgot to mention is that this doesn't look strictly like some simple package mixup. I connected over SSH to that box, created an empty folder and a sandbox there, and even simple cabal install OpenGLRaw failed with the same problem (so it's unlikely that that itself would pull in two versions of the same module that could cause those conflicts).


I've also extracted a verbose cabal installation log.


Did SSH again, cloned raw sources of OpenGLRaw, still the same. Tried 7.6.3, still the same.

解决方案

It seems to be an issue with gcc-4.9.2. I forked your project, started a build with high verbosity level, connected to the circleci container and run the exact linking command. It fails the same way:

ubuntu@box1305:~$ /usr/bin/gcc -fno-stack-protector -DTABLES_NEXT_TO_CODE '-Wl,--hash-size=31' -Wl,--reduce-memory-overheads -Wl,--no-as-needed -nostdlib -Wl,-r -nodefaultlibs '-Wl,--build-id=none' -o Types.o /tmp/ghc17998_0/ghc_15.ldscript
/tmp/ghc17998_0/ghc_14.o: In function `r2vy_closure':
(.data+0x0): multiple definition of `__stginit_OpenGzu8rT20eO9AxEKIONeYf57cS_GraphicsziRenderingziOpenGLziRawziTypes'
/tmp/ghc17998_0/ghc_14.o:(.data+0x0): first defined here
/tmp/ghc17998_0/ghc_14.o: In function `r2vy_closure':
(.data+0x8): multiple definition of `OpenGzu8rT20eO9AxEKIONeYf57cS_GraphicsziRenderingziOpenGLziRawziTypes_makeGLDEBUGPROC_closure'
/tmp/ghc17998_0/ghc_14.o:(.data+0x8): first defined here
/tmp/ghc17998_0/ghc_14.o: In function `c2y7_info':
(.text+0xc0): multiple definition of `OpenGzu8rT20eO9AxEKIONeYf57cS_GraphicsziRenderingziOpenGLziRawziTypes_makeGLDEBUGPROC_info'
/tmp/ghc17998_0/ghc_14.o:(.text+0xc0): first defined here

But with gcc-4.8 it works:

ubuntu@box1305:~$ /usr/bin/gcc-4.8 -fno-stack-protector -DTABLES_NEXT_TO_CODE '-Wl,--hash-size=31' -Wl,--reduce-memory-overheads -Wl,--no-as-needed -nostdlib -Wl,-r -nodefaultlibs '-Wl,--build-id=none' -o Types.o /tmp/ghc17998_0/ghc_15.ldscript
ubuntu@box1305:~$ 

So you should switch to older gcc and probably report a bug to gcc devs.

ADDED: Here is an example how to switch gcc version. And here is a successful build.

这篇关于由于“多重定义”构建失败本地依赖项中的链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆