🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #556

HELP: problem linking Gcc-compiled C code containing varargs (stdarg)

#556
From: John Methot
Date: Mon, 05 Oct 1992 19:43
107 lines
3407 bytes
I am converting some C code from "traditional" (Sun C compiler) to ANSI.
Two of the routines I converted utilize variable argument lists.  The
original code was:

/*************************************************************************/
#include <varargs.h>

int fcn1( va_alist )
  va_dcl
  {
  va_list ap;
  char    *KeyName;
  int     TypeFlag;

  va_start( ap );
  KeyName = va_arg( ap, char* );
  TypeFlag = va_arg( ap, int );
  ...

and

int fcn2( slotkey, method, va_alist )
  int slotkey;
  int method;
  va_dcl
  {
  va_list args;

  va_start( args );
  data = va_arg( args, int* );
  ...
/*************************************************************************/

I changed these routines to:

/*************************************************************************/
#include <stdarg.h>

int fcn1( char *KeyName, ... )
  {
  va_list ap;
  char    *KeyName;
  int     TypeFlag;

  va_start( ap, KeyName );
  TypeFlag = va_arg( ap, int );
  ...

and

int fcn2( int slotkey, int method, ... )
  int slotkey;
  int method;
  {
  va_list args;

  va_start( args, method );
  data = va_arg( args, int* );
  ...

/*************************************************************************/

This module compiles fine (with gcc), using:

gcc -c -g -I(include dirs) -DDEBUG  badmodule.c

(-DDEBUG is used in the code in badmodule.c)

but when I go to link an executable against the library containing this
module, I get:

/*************************************************************************/
gcc -g test.o libApp.a -lm -y___builtin_saveregs -o test.x
ld: Undefined symbol
   ___builtin_saveregs
(badmodule.o): reference to external undefined ___builtin_saveregs
*** Error code 2
make: Fatal error: Command failed for target `test.x'
/*************************************************************************/

badmodule.o is the object file containing the compiled source (listed above).

libApp.a is an archive containing badmodule.o (and other stuff).

If you're not familiar with the -y flag, it is passed to ld to get it to
tell you which object file invoked the unresolved symbol.  It produces the

(badmodule.o): reference to external undefined ___builtin_saveregs

line.

The few ANSI C books I've been able to scrounge up have been no help.  In the
Emacs info nodes for gcc (specifically, File: gcc.info,  Node: Varargs) there
is a discussion of "Implementing the Varargs Macros," but this appears to
be aimed at people porting the Gcc compiler itself?  I don't want to 
*implement* the macros, I just want them to work.

This is happening on Sparc running SunOS 4.1.1.  Gcc is not our *normal*
compiler (that would be the Sun C Compiler), so perhaps I need to do some
environment magic to get Gcc to the right include directory or libs?  I'm
at a dead end, any help would be appreciated.

John Methot
jmethot@vicorp.com

Please respond via e-mail (Reply-To: line has been explicitly set to
ensure correctness).
Technical Details
Message-ID: <1992Oct5.194329.3647@vicorp.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!vicorp!jmethot

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!sparky!uunet!vicorp!jmethot
From: jmethot@vicorp.com (John Methot)
Subject: HELP: problem linking Gcc-compiled C code containing varargs (stdarg)
Message-ID: <1992Oct5.194329.3647@vicorp.com>
Reply-To: jmethot@vicorp.com
Organization: V. I. Corporation, Northampton, Massachusetts
Date: Mon, 5 Oct 1992 19:43:29 GMT
Lines: 108