Bram is wise.

Adding a nodefaultlib:msvcrt could potentially break things if you set
USE_MSVCRT=1 to use the CRT DLL instead of statically linking the CRT. The
problem is that you're linking a static-CRT version of Vim with DLL-CRT
versions of ActiveState components. The problem is not with Vim's makefile.

Generally, if you have lib conflicts, it means you've done something wrong.
In this case, you have one OBJ that was compiled for use with the static
CRT, and another OBJ that was compiled for use with the dynamically-linked
CRT. Each of them tell the linker "you should probably link me with this
particular CRT". Luckily, the linker is smart enough to only allow one CRT
at a time.

For a standalone program, statically linking with the CRT is generally the
way to go, so Vim defaults to doing this. Using the CRT DLL saves about 150k
in disk space, but the CRT DLL is 400-800k, depending on which version of
Visual C++ you're using. The CRT is potentially already in memory in another
process, so this may or may not save memory at runtime.

For a program that interacts with other DLLs (such as loading Perl, Python,
Ruby, etc. DLLs at runtime), the CRT DLL starts to make more sense. In
addition to saving disk space (one CRT DLL instead of 150k of static CRT in
each executable), you save memory (one CRT DLL loaded, and all modules share
the same heap) and in some cases you avoid bugs (only one CRT so you don't
have conflicting CRT settings like locale). However, you now have to
redistribute the CRT with your product, and starting with VC 8.0, you have
to get the CRT's manifest correctly embedded into your EXE and DLLs.

-----Original Message-----
From: Yongwei Wu [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, May 15, 2007 7:54 PM
To: Bram Moolenaar
Cc: Vim-dev mailing list
Subject: Re: MSVC build option about default library MSVCRT

Hi Bram,

On 15/05/07, Bram Moolenaar <[EMAIL PROTECTED]> wrote:
>
> [redirecting to vim-dev]
>
> > I am wondering whether l. 705 of Make_mvc.mak in vim-7.1-extra.tar.gz
> > should be change from
> >
> >   LINKARGS1 = $(linkdebug) $(conflags) /nodefaultlib:libc
> >
> > to
> >
> >   LINKARGS1 = $(linkdebug) $(conflags) /nodefaultlib:libc
/nodefaultlib:msvcrt
> >
> > I have been using it for maybe half a year and not found a single
> > problem yet. It will eliminate this message when building vim.exe:
> >
> > libcmt.lib(crt0init.obj) : warning LNK4098: defaultlib 'msvcrt.lib'
> > conflicts with use of other libs; use /NODEFAULTLIB:library
> >
> > Without /nodefaultlib:msvcrt vim.exe will have a dependency on
> > MSVCR71.DLL (I use MSVC 7.1). This added flag will not affect
> > gvim.exe. The command lines I used are:
> >
> > nmake -f Make_mvc.mak GUI=yes OLE=yes MBYTE=yes IME=yes GIME=yes
> > CSCOPE=yes PERL=C:\Perl DYNAMIC_PERL=yes PERL_VER=58
> > PYTHON=C:\Python24 DYNAMIC_PYTHON=yes PYTHON_VER=24 RUBY=C:\ruby
> > DYNAMIC_RUBY=yes RUBY_VER=18 RUBY_VER_LONG=1.8 TCL=C:\Tcl
> > DYNAMIC_TCL=yes TCL_VER=84 TCL_VER_LONG=8.4 XPM=C:\xpm %*
> > nmake -f Make_mvc.mak MBYTE=yes CSCOPE=yes PERL=C:\Perl
> > DYNAMIC_PERL=yes PERL_VER=58 PYTHON=C:\Python24 DYNAMIC_PYTHON=yes
> > PYTHON_VER=24 RUBY=C:\ruby DYNAMIC_RUBY=yes RUBY_VER=18
> > RUBY_VER_LONG=1.8 TCL=C:\Tcl DYNAMIC_TCL=yes TCL_VER=84
> > TCL_VER_LONG=8.4 XPM=C:\xpm %*
>
> I'm very careful with these things.  Make_mvc.mak is used for several
> versions of MSVC, starting at 4.1.  You need to check all versions to
> make sure it doesn't cause any problems.

Er ... I do not have access to such old versions. I work on 7.1, and
can do so on 6.0 too. However, I believe MSVC versions are not
significant here. See below.

> I suppose the error message you get is from some of the languages
> Ruby/Python/Tcl/....  I don't get it, thus you can probably solve it by
> checking your included libraries.  Perhaps one has not been build by
> MSVC?  That usually causes trouble (not just an error message, but a
> crash at runtime).  Try actually using all the languages.

I noticed that you did not build vim.exe with the languages, which
should be the reason you do not see the warning message. I have
verified that removing ActiveTcl 8.4 from my build makes
/nodefaultlib:msvcrt not necessary: in fact, then the option does not
have any effect at all.

I did actually try executing simple commands in Perl, Python, Tcl, and
Ruby, and they all succeeded.

I use the popular ActiveState builds for Perl, Python, and Tcl, and
ruby185-21 from the Ruby web site. I believe they are all MSVC
compatible.

Best regards,

Yongwei

-- 
Wu Yongwei
URL: http://wyw.dcweb.cn/

Reply via email to