Thread View: comp.sys.next.programmer
2 messages
2 total messages
Started by Hayward Lam
Fri, 09 Oct 1992 00:38
C++ compiler question
Author: Hayward Lam
Date: Fri, 09 Oct 1992 00:38
Date: Fri, 09 Oct 1992 00:38
19 lines
856 bytes
856 bytes
Hi there, I'm pretty new in the NeXT world. This might be a stupid question but I have to ask: I try to compile and link a c++ program. I type "cc++ program.c" the linker returns the following: /bin/ld: Undefined symbols: _printf_FPCce When I compile the with -c option, everything is fine. The object file is created. But when I do a ld, it returns the same thing described above. I'm not sure what's going on. Help! Thanks in advance. Regards, Hayward email to hlam@bnr.ca
Re: C++ compiler question
Author: Jim Large
Date: Mon, 12 Oct 1992 17:14
Date: Mon, 12 Oct 1992 17:14
54 lines
2364 bytes
2364 bytes
In article <1992Oct9.003819.3434@bmers95.bnr.ca> hlam@bmerh136.bnr.ca (Hayward
Lam) writes:
> I try to compile and link a c++ program. I type "cc++ program.c"
First of all, if you name your program "program.cc", then you can compile it
with the command, "cc program.cc". This will not fix your problem (which was)
> the linker returns the following:
> /bin/ld: Undefined symbols:
> _printf_FPCce
You are trying to call a C function (printf()) from a C++ module. To do this,
you must surround the declaration of printf() with 'extern "C" { }'.
Since all of the NeXT libraries were compiled as C, or Objective-C, you
probably want to wrap the extern construct around all of your includes as
shown:
extern "C"
{
#include <stdio.h> /*contains declaration of printf()*/
#include <
.
.
.>
}
Why? Because C and C++ translate function names ==> symbol names differently.
In C, names are translated by prefixing an underscore, so that
printf(const char *, ...)
becomes
_printf
In C++, the translated names encode the argument types, and
printf(const char *, ...)
becomes
_printf_FPCce
This is what makes overloading possible. If you declare
printf(int, int);
C++ assumes that you are defining a DIFFERENT FUNCTION from the printf() that
we all know and love. Therefore it outputs a different symbol name, namely
_printf_Fii
----------------+------------------+------------------------------------
|\ /| | Jim Large | Visual Understanding Systems, Inc.
| V | | jml@visus.com | 2100 Wharton St.
\_| |__ | (412)488-3600 | Pittsburgh, PA 15203
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads