This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Make, TMP=tmpnam => coredump


Larry wrote:

> I get the exact same results when I run those commands.
> 
> Perhaps I had an error in my Makefile. Can you please try the following
> Makefile that still generates the same error for me?

Okay, I realized that I'd named one of the source files "tmpname.c" and
not "tmpnam.c" in which case I get what you get.

The reason is as I suspected the poor choice of the variable named TMP. 
Under windows this variable designates the directory in which programs
are to create temporary files.  gcc is one of these programs that needs
to create temporary files.  When you set TMP in the Makefile to "tmpnam"
that tells gcc to try to store its temporary files in a directory
"tmpnam" under the current directory.  If there is an executable with
the same name in the current directory it faults.  You can reproduce
this without 'make' as follows:

$ ls -l
total 16K
-rw-r--r--  1 brian None  53 Apr  8 21:18 Makefile
-rw-r--r--  1 brian None  67 Apr  8 17:12 program.c
-rw-r--r--  1 brian None  67 Apr  8 17:12 tmpnam.c
-rwxr-xr-x  1 brian None 13K Apr  8 21:29 tmpnam.exe

$ export TMP=tmpnam

$ gcc program.c -o program
Aborted (core dumped)

This is arguably a gcc bug, but in reality you can't expect to use a
variable named TMP like that under Windows because it has special
meaning.  The author of that book just demonstrated a good lesson in how
not to write portable makefiles.

Just a couple of pieces of advice about your makefile: CC and CFLAGS are
for compiling C code, CXX and CXXFLAGS are for C++ code.  Don't put g++
into CC unless you know what you're doing.  Call gcc as gcc when
compiling C code, call it as g++ when compiling C++.  Oh and case
matters, so no "cc".

Also, under Cygwin "-lm" is not necessary, nor are -lsocket, -lpthread,
and probably a couple of others.  They are all provided by -lcygwin
which is automatically added by the compiler.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]