Bug #7960

Ruby fails to build static under mswin linker error: multiple definitions of _Init_ext

Added by Benjamin Powers about 1 year ago. Updated about 1 year ago.

[ruby-core:52894]
Status:Closed
Priority:Normal
Assignee:Nobuyoshi Nakada
Category:build
Target version:2.1.0
ruby -v:1.9.3 Backport:

Description

after the depend errors were fixed I obtained r39490 and attempted to build it

after nearly completing it failed with

ruby200.dll : fatal error LNK1169: one or more multiply defined symbols found

searching through the output found only one line with a "already defined"

ruby200-static.lib(dmyext.obj) : error LNK2005: Initext already defined in ext
init.obj

attached is the full output of the configure.bat and nmake commands run with arguments

ruby-2.0.0-r39490_build_output.txt Magnifier (21.3 KB) Benjamin Powers, 02/26/2013 05:51 AM

Associated revisions

Revision 39552
Added by Nobuyoshi Nakada about 1 year ago

Makefile.sub: static-linked-ext

  • win32/Makefile.sub (EXTOBJS, EXTOBJS, config.h): definitions for static-linked-ext. [Bug #7960]

Revision 39556
Added by Nobuyoshi Nakada about 1 year ago

mswin: static-linked-ext

  • enc/depend (CPPFLAGS), lib/mkmf.rb (MakeMakefile#createmakefile): define RUBYEXPORT for static-linked-ext mswin. [Bug #7960]

History

#1 Updated by Koichi Sasada about 1 year ago

  • Assignee set to Usaku NAKAMURA
  • Target version changed from 2.0.0 to 2.1.0

#2 Updated by Usaku NAKAMURA about 1 year ago

  • Status changed from Open to Assigned
  • Assignee changed from Usaku NAKAMURA to Nobuyoshi Nakada

#3 Updated by Benjamin Powers about 1 year ago

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

#4 Updated by Benjamin Powers about 1 year ago

infact I think I'm right, it's right here in the 2.0 change log

ext/extmk.rb (command_output): dmyext is needed as DLDOBJS if no static linked extensions.

this would seem to imply that if there were statically linked extensions it is not needed

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

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)

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.
as the 2 resulting object are defined in 2 seperate .obj files ans linked separately this is causing the error.
I'm guessing GCC can handle this but MSVC can't

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.

that or there is a way to define the Init_ext in extinit.c function so that the error doesn't happen.

or I could be utterly wrong. that's a possibility too.

#5 Updated by Nobuyoshi Nakada about 1 year ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39552.
Benjamin, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


Makefile.sub: static-linked-ext

  • win32/Makefile.sub (EXTOBJS, EXTOBJS, config.h): definitions for static-linked-ext. [Bug #7960]

Also available in: Atom PDF