unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Fabrice Popineau <fabrice.popineau@supelec.fr>
To: Eli Zaretskii <eliz@gnu.org>
Cc: cschol2112@googlemail.com, 9960@debbugs.gnu.org
Subject: bug#9960: Compiling Emacs trunk with MSVC
Date: Sat, 12 Nov 2011 15:34:56 +0100	[thread overview]
Message-ID: <CAFgFV9OECGSAaYr6RuG2d+hHxxQ31PhoPX3E7QPB_BPznUDB=w@mail.gmail.com> (raw)
In-Reply-To: <83hb29fo0k.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 4391 bytes --]

>
> > So, I have rebuilt emacs with the static libc. It is working too,
> > except for nt/cmdproxy that required :
> >
> > === modified file 'nt/cmdproxy.c'
> > --- nt/cmdproxy.c       2011-04-27 04:19:15 +0000
> > +++ nt/cmdproxy.c       2011-11-11 20:41:37 +0000
> > @@ -46,6 +46,8 @@
> >  #define stdout GetStdHandle (STD_OUTPUT_HANDLE)
> >  #define stderr GetStdHandle (STD_ERROR_HANDLE)
> >
> > +#ifndef _MSC_VER
> > +
> >  int
> >  vfprintf (HANDLE hnd, const char * msg, va_list args)
> >  {
> > @@ -81,6 +83,7 @@
> >
> >    return rc;
> >  }
> > +#endif /* _MSC_VER */
> >
> >  void
> >  fail (const char * msg, ...)
> >
> > This patch is ok for both the static libc and the dynamic one.
> > Without it, link complains that printf is redefined in the case of
> > the static libc.  By the way, I don't know how the MingW libraries
> > are organized, but defining printf and co to spare some functions
> > when linking ... it doesn't work with cl and libc/msvcrt because
> > other libc functions are used too : strncpy, strdup etc.  So it is
> > not possible to avoid linking against libc (?).
>
> You will have to bear with me, as I cannot easily grok what you are
> trying to explain.  E.g., what is "the static libc"?


There are two MS C libraries you can link with :
- libc is a static library,
- msvcrt is a dll

http://msdn.microsoft.com/en-us/library/abx4dbyh(v=vs.100).aspx

The main difference between both is that in the event you compile your
program in several modules, and each of these modules need a C library, if
you use msvcrt, then internal variables of the C library are shared amond
the modules, whereas each module gets its own C library internal state if
you use the static libc. (May be relevant for functions like strtok for
example).

Also, to complete what I wrote previously about installation and
redistributables.
It is perfectly possible to compile a foo.exe program and link it with the
current release
of msvcrt (say msvcrt100.dll) and pack this library in the very same
directory
foo.exe is located. You can zip them together and there is nothing to
install.
Your foo.exe program will be dynamically linked with the dll that are
located
in the same directory, before looking anywhere else.



To answer your question about MinGW, here are the default libraries
> that the linker is instructed to scan when linking a program:
>
>  -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32
>  -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt
>
> Out of these, libgcc.a is a static library that comes with GCC,
> libmingw32.a and libmingwex.a are static libraries specific to MinGW
> (the former includes the startup modules like CRTglob, the latter math
> functions and a few MinGW replacements for missing or buggy functions
> from the MS runtime), libmoldname.a is a static library of stubs that
> provide FOO where MS runtime only has _FOO (like _access, _dup2,
> etc.), and all the rest are Windows dynamic libraries; MinGW just
> supplies import libs for them.  I hope this answers your question
> about the organization of the MinGW libraries.  IIUC, the above means
> MinGW does not have any "static libc", so it must link against the
> dynamic libraries that constitute the MS runtime.
>

Ok, thanks for this detailed explanation.
So it seems that MINGW compiled programs are linked with the MS msvcrt.dll ?
But then, you would need to provide msvcrt.dll together with your binaries ?


Anyway, in the case of cmdproxy, the source code states that :

/* We don't want to include stdio.h because we are already duplicating
   lots of it here */
extern int _snprintf (char *buffer, size_t count, const char *format, ...);

/*******  Mock C library routines  *********************************/

/* These routines are used primarily to minimize the executable size.  */

I don't see exactly how to minimze executable size except by not linking
with any C library. It would be possible to replace the other string
functions
used in cmdproxy.c by Win32 functions and remove the C library from the
needed resources.
But that is not currently what's done.
So all in all, it is as easy to use the C library printf functions,
especially given the fact that
they conflict when I link against the static libc.
(Not sure why they don't when linking with msvcrt, I bet it is because of
an underscore again).

Greetings,

-- 
Fabrice

[-- Attachment #2: Type: text/html, Size: 5697 bytes --]

  reply	other threads:[~2011-11-12 14:34 UTC|newest]

Thread overview: 85+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <loom.20101206T214649-301@post.gmane.org>
     [not found] ` <83sjy5279e.fsf@gnu.org>
     [not found]   ` <AANLkTikmhiNmd5gz8wkpqbgHni2LKkjhTtnPizaOEz7T@mail.gmail.com>
2011-11-05 11:19     ` bug#9960: Compiling Emacs trunk with MSVC Eli Zaretskii
2011-11-05 11:39       ` Eli Zaretskii
2011-11-05 12:54         ` Christoph Scholtes
2011-11-05 13:22           ` Eli Zaretskii
2011-11-05 13:58             ` Christoph Scholtes
2011-11-05 14:16               ` Eli Zaretskii
2011-11-05 14:53                 ` Eli Zaretskii
2011-11-05 15:51                   ` Óscar Fuentes
2011-11-05 16:10                     ` Eli Zaretskii
2011-11-05 16:27                 ` Christoph Scholtes
2011-11-05 16:50                   ` Eli Zaretskii
2011-11-05 16:57                     ` Eli Zaretskii
2011-11-05 17:22                     ` Christoph Scholtes
2011-11-05 18:20                       ` Christoph Scholtes
2011-11-05 19:33                         ` Eli Zaretskii
2011-11-05 20:38                           ` Christoph Scholtes
2011-11-05 21:11                             ` Eli Zaretskii
2011-11-05 22:07                               ` Christoph Scholtes
2011-11-05 22:15                                 ` Christoph Scholtes
2011-11-05 22:22                                   ` Christoph Scholtes
2011-11-06  4:03                                     ` Eli Zaretskii
2011-11-05 20:32                         ` Christoph Scholtes
2011-11-05 21:27                           ` Eli Zaretskii
2011-11-05 22:23                             ` Christoph Scholtes
2011-11-06  1:50                               ` Christoph Scholtes
2011-11-06  5:47                                 ` Eli Zaretskii
2011-11-06  5:37                               ` Eli Zaretskii
2011-11-07 16:13                             ` Fabrice Popineau
2011-11-07 16:57                               ` Eli Zaretskii
     [not found]                                 ` <CAFgFV9N4w+wi4J84BhoEZrgAuwJdFZtWzOAkdb_T9+B7L+Ftfg@mail.gmail.com>
2011-11-08 16:51                                   ` Eli Zaretskii
2011-11-07 17:03                               ` Eli Zaretskii
2011-11-10 19:56                                 ` Fabrice Popineau
2011-11-10 20:28                                   ` Lennart Borgman
2011-11-10 20:31                                     ` Juanma Barranquero
2011-11-10 20:29                                   ` Juanma Barranquero
2011-11-20 20:59                                     ` Fabrice Popineau
2011-11-20 21:15                                       ` Juanma Barranquero
2011-11-20 21:35                                         ` Dan Nicolaescu
2011-11-20 21:40                                           ` Juanma Barranquero
2011-11-21  2:30                                         ` Stefan Monnier
2011-11-21  2:45                                           ` Juanma Barranquero
2011-11-21  3:51                                             ` Eli Zaretskii
2011-11-21  8:21                                               ` Andreas Schwab
2011-11-21  9:54                                                 ` Eli Zaretskii
2011-11-21 12:14                                               ` Juanma Barranquero
2011-11-21 13:56                                                 ` Eli Zaretskii
2011-12-04  8:06                                                   ` Fabrice Popineau
2011-12-05  5:11                                                     ` Eli Zaretskii
2011-11-21 15:55                                       ` Richard Stallman
2011-11-11  9:39                                   ` Eli Zaretskii
2011-11-11 19:28                                     ` Fabrice Popineau
2011-11-11 19:53                                       ` Eli Zaretskii
2011-11-11 21:55                                         ` Fabrice Popineau
2011-11-12 13:50                                           ` Eli Zaretskii
2011-11-12 14:34                                             ` Fabrice Popineau [this message]
2011-11-12 15:59                                               ` Óscar Fuentes
2011-11-12 23:32                                                 ` Richard Stallman
2011-11-12 14:27                                       ` Eli Zaretskii
2011-11-12 17:55                                         ` Fabrice Popineau
2011-11-12 20:48                                           ` Eli Zaretskii
2011-11-12 22:27                                             ` Fabrice Popineau
2011-11-12 22:44                                               ` Fabrice Popineau
2011-11-12 23:08                                                 ` Fabrice Popineau
2011-11-13 14:45                                                   ` Christoph Scholtes
2011-11-27 19:05                                       ` Eli Zaretskii
2011-11-28  9:18                                         ` YAMAMOTO Mitsuharu
2011-11-28 11:51                                           ` Eli Zaretskii
2011-11-28 19:07                                         ` Fabrice Popineau
2012-03-24 13:46                                           ` Eli Zaretskii
2012-03-24 16:10                                             ` Fabrice Popineau
2012-03-24 18:42                                               ` Eli Zaretskii
2011-11-12 17:10                                   ` Christoph Scholtes
2011-11-12 20:37                                     ` Eli Zaretskii
2011-11-05 23:44         ` Fabrice Popineau
2011-11-06  3:42           ` Christoph Scholtes
2011-11-06  4:02           ` Eli Zaretskii
2011-11-08  6:43       ` bug#9960: fix for Bug#9772 should also help fix Bug#9960 Paul Eggert
2011-11-28  9:34       ` bug#9960: "emacsclient.c (main) <environ>: Remove declaration, " breaks build on Mac OS X David Caldwell
2011-11-28 17:29       ` bug#9960: : " Leon Zhang
2011-11-30 15:48       ` bug#9960: Compiling Emacs trunk with MSVC Tim Crews
2011-11-30 16:30         ` Tim Crews
2011-11-30 18:04         ` Eli Zaretskii
2011-11-30 18:22           ` Tim Crews
2011-11-30 19:17             ` Eli Zaretskii
2011-11-30 19:42               ` Tim Crews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFgFV9OECGSAaYr6RuG2d+hHxxQ31PhoPX3E7QPB_BPznUDB=w@mail.gmail.com' \
    --to=fabrice.popineau@supelec.fr \
    --cc=9960@debbugs.gnu.org \
    --cc=cschol2112@googlemail.com \
    --cc=eliz@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).