Static link with libmsvcrt.a

810 views
Skip to first unread message

Jose

unread,
Jul 20, 2012, 2:47:09 PM7/20/12
to RubyInstaller, jo...@zeroc.com

I have build an executable with MinGW that comes with Ruby Dev Kit
DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe.

The produced executable is dynamic linked to MSVCRT.dll, and it
doesn't work on XP SP3 because it could not located
_get_output_format procedure in the MSVCRT.dll

When i do the same back in February, the produced executable was by
default static linked with libmsvcrt.a and it was
working fine in XP Sp3.

There was any change in DevKit that could explain this?

I have not changed my compiler or linker flags, just do a clean
install of XP and Ruby dev kit.

I have try to pass -static-libstdc++ to the linker, but the linker
complains about this being an unrecognized argument

Luis Lavena

unread,
Jul 20, 2012, 2:55:55 PM7/20/12
to rubyin...@googlegroups.com
On Fri, Jul 20, 2012 at 3:47 PM, Jose <pepone...@gmail.com> wrote:

Hello,

>
> I have build an executable with MinGW that comes with Ruby Dev Kit
> DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe.
>
> The produced executable is dynamic linked to MSVCRT.dll, and it
> doesn't work on XP SP3 because it could not located
> _get_output_format procedure in the MSVCRT.dll
>

What version of Ruby? which branch in case of working from the source?

> When i do the same back in February, the produced executable was by
> default static linked with libmsvcrt.a and it was
> working fine in XP Sp3.
>

MinGW did never provide a static linked version of msvcrt, perhaps
you're confused with Visual Studio which did allow linking to one or
the other.

Even that MinGW provides libmsvcrt.a, is not a static library, it
links to msvcrt.dll

> There was any change in DevKit that could explain this?
>

DevKit has been the same and this is the first complain about it.

The usage of _get_output_format is caused by Ruby and not the DevKit.

> I have not changed my compiler or linker flags, just do a clean
> install of XP and Ruby dev kit.
>

Did you change your compiler?

> I have try to pass -static-libstdc++ to the linker, but the linker
> complains about this being an unrecognized argument
>

Ruby is C, not C++, adding -static-libstdc++ has no effect because is
not C++ and is not linking against libstdc++

Please provide more information about what version of Ruby are you
talking about, where you built it (if so or used provided binaries,
etc).

--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry

Jose

unread,
Jul 20, 2012, 3:11:32 PM7/20/12
to rubyin...@googlegroups.com


El viernes, 20 de julio de 2012 20:55:55 UTC+2, Luis Lavena escribió:
On Fri, Jul 20, 2012 at 3:47 PM, Jose <pepone...@gmail.com> wrote:

Hello,

>
> I have build an executable with MinGW that comes with Ruby  Dev Kit
> DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe.
>
> The produced executable is dynamic linked to MSVCRT.dll, and it
> doesn't work on XP SP3 because it could not located
> _get_output_format procedure in the MSVCRT.dll
>

What version of Ruby? which branch in case of working from the source?

I using ruby-1.9.3-p194 from rubyinstaller.org 

> When i do the same back in February, the produced executable was by
> default static linked with libmsvcrt.a and it was
> working fine in XP Sp3.
>

MinGW did never provide a static linked version of msvcrt, perhaps
you're confused with Visual Studio which did allow linking to one or
the other.

Even that MinGW provides libmsvcrt.a, is not a static library, it
links to msvcrt.dll

> There was any change in DevKit that could explain this?
>

DevKit has been the same and this is the first complain about it.

The usage of _get_output_format is caused by Ruby and not the DevKit.

> I have not changed my compiler or linker flags, just do a clean
> install of XP and Ruby dev kit.
>

Did you change your compiler?

I using g++ that comes with DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe 

> I have try to pass -static-libstdc++ to the linker, but the linker
> complains about this being an unrecognized argument
>

Ruby is C, not C++, adding -static-libstdc++ has no effect because is
not C++ and is not linking against libstdc++

Please provide more information about what version of Ruby are you
talking about, where you built it (if so or used provided binaries,
etc).

The problem is not building ruby itself, but when i try to build a ruby extension,
the extension is C++, i use g++ from dev kit.

My ruby module is a DLL and and code generator that is written in C++, and used
from the ruby module. 

But the code generator now fails to run because the missing _get_output_format.

Luis Lavena

unread,
Jul 20, 2012, 3:20:16 PM7/20/12
to rubyin...@googlegroups.com
On Fri, Jul 20, 2012 at 4:11 PM, Jose <pepone...@gmail.com> wrote:
>>
>> What version of Ruby? which branch in case of working from the source?
>
>
> I using ruby-1.9.3-p194 from rubyinstaller.org
>>
>>
>> > I have try to pass -static-libstdc++ to the linker, but the linker
>> > complains about this being an unrecognized argument
>> >
>>
>> Ruby is C, not C++, adding -static-libstdc++ has no effect because is
>> not C++ and is not linking against libstdc++
>>
>> Please provide more information about what version of Ruby are you
>> talking about, where you built it (if so or used provided binaries,
>> etc).
>>
> The problem is not building ruby itself, but when i try to build a ruby
> extension,
> the extension is C++, i use g++ from dev kit.
>
> My ruby module is a DLL and and code generator that is written in C++, and
> used
> from the ruby module.
>
> But the code generator now fails to run because the missing
> _get_output_format.
>

Are you defining the minimum version of WINNT?

Ruby is compiled with _WIN32_WINNT=0x0501

https://github.com/ruby/ruby/blob/trunk/configure.in#L1075-1081

This trigger certain functions be exposed by MinGW in both headers and
the linking library. If you don't compile with -D_WIN32_WINNT=0x0501
most likely GCC will fail finding symbols.

Does Ruby works under your Windows XP installation? If so, that means
the problem is when you link and not Ruby itself.

If Ruby doesn't work, that is other problem and needs investigation.

One recommendation is that when you link with Ruby, you use
RbConfig::CONFIG information to use the same flags and avoid any
possible segmentation caused by that.

Other thing, you mentioned compiling an extension, but AFAIK mkmf/Rice
will be smart enough to use RbConfig::CONFIG.

Are you manually defining the compilation flags?

Jose

unread,
Jul 20, 2012, 6:24:27 PM7/20/12
to rubyin...@googlegroups.com
I added this definition but still get the same problem, what i don't understand 
is that _get_output_format require MSVCRT > 0x8000

from stdio.h

#if __MSVCRT_VERSION__ >= 0x800
_CRTIMP unsigned int __cdecl __MINGW_NOTHROW _get_output_format (void);
_CRTIMP unsigned int __cdecl __MINGW_NOTHROW _set_output_format (unsigned int);

#define _TWO_DIGIT_EXPONENT  1

_CRTIMP int __cdecl __MINGW_NOTHROW _get_printf_count_output (void);
_CRTIMP int __cdecl __MINGW_NOTHROW _set_printf_count_output (int);
#endif

In my system MSVCRT.dll is loaded from C:\windows\system32 and the current version
is 7.0.2600.5512


Does Ruby works under your Windows XP installation? If so, that means
the problem is when you link and not Ruby itself.
Yes ruby works fine, the problem sees when i link this executable, that executable
is not my ruby extension, but a separate exe that is used by the extension.
 

If Ruby doesn't work, that is other problem and needs investigation.

One recommendation is that when you link with Ruby, you use
RbConfig::CONFIG information to use the same flags and avoid any
possible segmentation caused by that.

Other thing, you mentioned compiling an extension, but AFAIK mkmf/Rice
will be smart enough to use RbConfig::CONFIG.

Are you manually defining the compilation flags?
I manually define the build flags for the separate executable, and RbConfig to
build the extension it self. 

Also all works fine when i use Windows 7 instead of XP, so seems like a problem 
with MSVCRT version.

Luis Lavena

unread,
Jul 20, 2012, 6:30:15 PM7/20/12
to rubyin...@googlegroups.com
On Fri, Jul 20, 2012 at 7:24 PM, Jose <pepone...@gmail.com> wrote:
>
>>
>> This trigger certain functions be exposed by MinGW in both headers and
>> the linking library. If you don't compile with -D_WIN32_WINNT=0x0501
>> most likely GCC will fail finding symbols.
>
> I added this definition but still get the same problem, what i don't
> understand
> is that _get_output_format require MSVCRT > 0x8000
>

Perhaps there is something else triggering the dependency.

If you can provide us a sample code for us to replicate will be able
to help you.


>>
>> Does Ruby works under your Windows XP installation? If so, that means
>> the problem is when you link and not Ruby itself.
>
> Yes ruby works fine, the problem sees when i link this executable, that
> executable
> is not my ruby extension, but a separate exe that is used by the extension.
>

Ruby was compiled with that version of GCC and the same tools, so if
it works, then the problem is something else.

Please show to us at least the compilation error indicating that
_get_output_format is missing or what, so we can work towards
replicate and help you out.

>>
>> Are you manually defining the compilation flags?
>
> I manually define the build flags for the separate executable, and RbConfig
> to
> build the extension it self.
>

What flags are you using? how the command line looks like?

The more data we have to replicate it the better.

If you don't want to share the code of your project, at least create a
minimal sample that exposes this issue and we would be able to take a
look

Until then, everything I say is just guessing.

Jose

unread,
Jul 20, 2012, 8:48:37 PM7/20/12
to rubyin...@googlegroups.com
I finally found the problem, there was a old version of msvcrt.dll in my library path
seem that was from old VC6 builds. Once removed every thing starts working fine.

Not sure why this doesn't affect Windows7

Thanks for the help, and sorry for wasting your time
Reply all
Reply to author
Forward
0 new messages