This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


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

Re: system calls in gcc-2.96 under RedHat Linux 7.0


On Jan 19, 2001, Dirk Petry <petry@iastate.edu> wrote:

> I have an awkward problem with gcc-2.96 under RedHat 7.0
> when trying to compile C code containing the system calls
> "read", "write" and "close" to be linked to a C++ main
> programm:

These are not system calls, in a strict sense.  They're functions
defined in the C library, and C++ requires any functions to be
declared before they're used.  Recent releases of GCC have been
stricter about requiring the declaration.  Just #include the
appropriate header files and all will be fine.

>  serial.c:62: warning: implicit declaration of function `int close(...)'
>  serial.c:86: warning: implicit declaration of function `int write(...)'
>  serial.c:101: warning: implicit declaration of function `int read(...)'

This was a hint that you should have fixed your program before the
construct started to be deemed as invalid :-)

> And even more interesting: If I compile under RedHat 7.0 using "gcc"
> instead of "g++", the program compiles, but it doesn't link  
> with the rest of the program:

> vdcmon.o: In function `sercom::~sercom(void)':
> vdcmon.o(.text+0x3995): undefined reference to `terminate_serial(int *)'
> ...

> and similar error messages from ld.

It's likely that terminate_serial was compiled as C, and the call was
compiled as C++, but the function was not declared as extern "C", so
the call ended up using a mangled name.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

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