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


Alexandre Oliva wrote:
> 
> 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


Thanks a lot! The extern "C" solved the problem.
One has to use gcc, then the problems with read(),
write() and close() disappear. And using extern "C"
in the C++ parts of the program solves the linking 
problems.

The appropriate header files for close(), write() 
and read() don't seem to exist as such.
I haven't found them although I spend half a day 
searching for them in all possible header files.
Standard C also doesn't seem to have a non-system-
dependent name for them. Kernighan and Ritchie 
quote "syscalls.h" but this doesn't exist for
gcc.

But anyway, they don't seem to be needed.

Regards,

Dirk
-- 
----------------------------------------------
Dr. Dirk Petry, Dept. of Physics and Astronomy
    Iowa State University, Ames, IA 50011
mailto:petry@iastate.edu phone:+1-515-294-3873

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