public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Linker: Bug or Feature?
@ 1998-11-05  6:50 mvoss
  1998-11-06  9:01 ` Lassi A. Tuura
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: mvoss @ 1998-11-05  6:50 UTC (permalink / raw)
  To: gnu-win32

Hello everyobody!

I recently discoverad an undocumented "feature" in  GCC from the
EGCS-1.1-MinGW32-Package accessible at Mumit Khan's HP.

As a small introduction: I recently started to name my C++ files *.cpp, and
my C-files *.c. Before, I used the same extension for both.


When trying this

gcc -o fooexe.exe source.cpp asm.o -lfoo -lbar -lfoobar -mwindows

with asm.o being - nomen est omen - a previously assembled file (VERY
SMALL, 12 lines / one func / NASM 097)), I get an "undefined reference to
asmfunctionfoo...", the function in the .asm / .o file. I tried for 45
minutes to compile it (I always compared my source with the coff-examples
in NASM, only to realize the there was NO programming error!)

The I tried, as a last resort, renaming the .cpp to .c -------and
magically, IT WORKED!

gcc -o fooexe.exe source.c   asm.o -lfoo -lbar -lfoobar -mwindows
                                              ####

Why that? This sucks, as far as I'm concerned!

What does GCC have to doecide about my extensions???!?


Angrily, :-)
 Moritz


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Linker: Bug or Feature?
  1998-11-05  6:50 Linker: Bug or Feature? mvoss
@ 1998-11-06  9:01 ` Lassi A. Tuura
  1998-11-06 11:01 ` Benjamin Riefenstahl
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Lassi A. Tuura @ 1998-11-06  9:01 UTC (permalink / raw)
  To: mvoss; +Cc: gnu-win32

|> I get an "undefined reference to asmfunctionfoo...", the function in
|> the .asm / .o file.  [renaming .cpp to .c works]

The C file probably says `extern int asmfunctionfoo (...)'?  If the file
extension is `.cpp', GCC compiles the file as C++ and function names
will be mangled, e.g. `int asmfunctionfoo (void)' would become something
like `asmfunctionfoo__Fv'.  If it is compiled as C, the name is not
mangled and the link succeeds.  If you want to compile it as C++, use
`extern "C"' instead of `extern'. 

Hope this helps,
//lat
--
With sufficient thrust, pigs fly just fine.  However, this is not
necessarily a good idea.  It is hard to be sure where they are going
to land, and it could be dangerous sitting under them as they fly
overhead.  --RFC1925, "The Twelve Networking Truths"

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Linker: Bug or Feature?
  1998-11-05  6:50 Linker: Bug or Feature? mvoss
  1998-11-06  9:01 ` Lassi A. Tuura
@ 1998-11-06 11:01 ` Benjamin Riefenstahl
  1998-11-06 20:36 ` Mumit Khan
  1998-11-07  7:00 ` tjoen
  3 siblings, 0 replies; 5+ messages in thread
From: Benjamin Riefenstahl @ 1998-11-06 11:01 UTC (permalink / raw)
  To: gnu-win32

Hi Moritz,


mvoss@kuttig.com wrote:
> As a small introduction: I recently started to name my C++ files *.cpp, and
> my C-files *.c. Before, I used the same extension for both.
> 
> ...
>
> The I tried, as a last resort, renaming the .cpp to .c -------and
> magically, IT WORKED!

?? Renaming the file doesn't convert the contents, so I suppose the file
containes plain C code. While C code can be compiled as C++ fine, the
C++ compiler will generate different symbols for import and export, so
that would explain your linker problems. To have the C++ compiler
generate the same symbols as the C compiler, you need to declare the
names with a linkage specification in the code. This looks like this

  extern "C" void asmfunctionfoo( /*parameters*/ );

instead of

  extern void asmfunctionfoo( /*parameters*/ );

like the C code would do it. NB: C doesn't know linkage specifications,
so this change makes your code C++ only.


so long, benny
======================================
Benjamin Riefenstahl (benny@crocodial.de)
Crocodial Communications EntwicklungsGmbH
Ruhrstr. 61, D-22761 Hamburg, Germany
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Linker: Bug or Feature?
  1998-11-05  6:50 Linker: Bug or Feature? mvoss
  1998-11-06  9:01 ` Lassi A. Tuura
  1998-11-06 11:01 ` Benjamin Riefenstahl
@ 1998-11-06 20:36 ` Mumit Khan
  1998-11-07  7:00 ` tjoen
  3 siblings, 0 replies; 5+ messages in thread
From: Mumit Khan @ 1998-11-06 20:36 UTC (permalink / raw)
  To: mvoss; +Cc: gnu-win32

mvoss@kuttig.com writes:
> As a small introduction: I recently started to name my C++ files *.cpp, and
> my C-files *.c. Before, I used the same extension for both.

Using the same extension for two different languages, C and C++ in this 
case, is asking for trouble (lack of maintainability is just one issue), 
and in most cases, just plain wrong.

As for your problem, could you possibly send me the code so I can see
what's going on? I hate to guess when I see these reports as to what
the problem may be (name mangling/decoration is usually the top of my
list however).

Regards,
Mumit

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Linker: Bug or Feature?
  1998-11-05  6:50 Linker: Bug or Feature? mvoss
                   ` (2 preceding siblings ...)
  1998-11-06 20:36 ` Mumit Khan
@ 1998-11-07  7:00 ` tjoen
  3 siblings, 0 replies; 5+ messages in thread
From: tjoen @ 1998-11-07  7:00 UTC (permalink / raw)
  To: gnu-win32

> From:          mvoss@kuttig.com
> Date:          Thu, 5 Nov 1998 14:48:44 +0100

> The I tried, as a last resort, renaming the .cpp to .c -------and
> magically, IT WORKED!

Missing "extern C" in .cpp-file I guess
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1998-11-07  7:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-05  6:50 Linker: Bug or Feature? mvoss
1998-11-06  9:01 ` Lassi A. Tuura
1998-11-06 11:01 ` Benjamin Riefenstahl
1998-11-06 20:36 ` Mumit Khan
1998-11-07  7:00 ` tjoen

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).