https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17097754782013-02-26T08:29:27ZRuby Issue Tracking SystemRuby master - Bug #7960: Ruby fails to build static under mswin linker error: multiple definitions of _Init_exthttps://bugs.ruby-lang.org/issues/7960?journal_id=370112013-02-26T08:29:27Zko1 (Koichi Sasada)
<ul><li><strong>Assignee</strong> set to <i>usa (Usaku NAKAMURA)</i></li><li><strong>Target version</strong> changed from <i>2.0.0</i> to <i>2.1.0</i></li></ul> Ruby master - Bug #7960: Ruby fails to build static under mswin linker error: multiple definitions of _Init_exthttps://bugs.ruby-lang.org/issues/7960?journal_id=370142013-02-26T09:32:30Zusa (Usaku NAKAMURA)usa@garbagecollect.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Assigned</i></li><li><strong>Assignee</strong> changed from <i>usa (Usaku NAKAMURA)</i> to <i>nobu (Nobuyoshi Nakada)</i></li></ul> Ruby master - Bug #7960: Ruby fails to build static under mswin linker error: multiple definitions of _Init_exthttps://bugs.ruby-lang.org/issues/7960?journal_id=371762013-02-28T11:50:53ZRyexander (Benjamin Powers)Ryexander@gmail.com
<ul></ul><p>I've been trying to resolve this on my own. is dmyext.c even required when linking exts statically? it semes to be just a prototype for extentions which gets redefined in extinit</p> Ruby master - Bug #7960: Ruby fails to build static under mswin linker error: multiple definitions of _Init_exthttps://bugs.ruby-lang.org/issues/7960?journal_id=372492013-03-02T18:00:10ZRyexander (Benjamin Powers)Ryexander@gmail.com
<ul></ul><p>infact I think I'm right, it's right here in the 2.0 change log</p>
<p>ext/extmk.rb (command_output): dmyext is needed as DLDOBJS if no static linked extensions.</p>
<p>this would seem to imply that if there were statically linked extensions it is not needed</p>
<p>the error happens as it is linking in the shared dll and considering that dmyext is included in both the static lib and the shared lib inside $(DMYEXT) and $(DLDOBJS) respectively</p>
<pre><code>relevant lines from common.mk
$(LIBRUBY_A): $(OBJS) $(MAINOBJ) $(DTRACE_OBJ) $(DTRACE_GLOMMED_OBJ) $(DMYEXT) $(ARCHFILE)
$(LIBRUBY_SO): $(OBJS) $(DLDOBJS) $(LIBRUBY_A) $(PREP) $(LIBRUBY_SO_UPDATE) $(BUILTIN_ENCOBJS)
</code></pre>
<p>i'm pretty sure that the inclusion of dmyext is what is causing the error. It's needed to define the Init_ext function if there are not statically linked extensions but if there are statically linked extensions the function gets defined in the generated extinit.c file.<br>
as the 2 resulting object are defined in 2 seperate .obj files ans linked separately this is causing the error.<br>
I'm guessing GCC can handle this but MSVC can't</p>
<p>not sure how to solve it though. I suspect it needs to be removed as a link somewhere under the condition of there being statically linked extensions.</p>
<p>that or there is a way to define the Init_ext in extinit.c function so that the error doesn't happen.</p>
<p>or I could be utterly wrong. that's a possibility too.</p> Ruby master - Bug #7960: Ruby fails to build static under mswin linker error: multiple definitions of _Init_exthttps://bugs.ruby-lang.org/issues/7960?journal_id=372532013-03-02T22:49:51Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Assigned</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>This issue was solved with changeset r39552.<br>
Benjamin, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<hr>
<p>Makefile.sub: static-linked-ext</p>
<ul>
<li>win32/Makefile.sub (EXTOBJS, EXTOBJS, config.h): definitions for<br>
static-linked-ext. [Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Ruby fails to build static under mswin linker error: multiple definitions of _Init_ext (Closed)" href="https://bugs.ruby-lang.org/issues/7960">#7960</a>]</li>
</ul>