Help on -nodefaultlibs

Yong Jiang yjiang@cisco.com
Mon Aug 26 17:42:00 GMT 2002


Hi,

We are planning to write some drivers that are independent from both OS and
hardware platforms, since these drivers will be written by many people and will
be shared by multiple platforms in source level, it is good that if some kind
of 'generic' code checking can be done at the time these drivers are put in
place. Specificly, one of the things i would like to check is that these
drivers can only use data types and functions that are defined in the driver
code, no OS or platform specific data or functions can be used. I would like to
run the gcc in SunUnix environment in a way that no library is provided and
it will complain if not every function is fully defined in the source. So it
looks like the -nodefaultlibs link option serves what I need, but it gave me
lots of errors when I tried it. Can any one give me a help on this? Thanks.

Example:

a simple program:
int main()
{
  int x;
  x = 1;
  return(0);
}

compiled:
gcc -nodefaultlibs -lgcc main.c

got the errors attached in the end of this email...

* and I would want this:
if I compile the following program it should complain 'printf', 'malloc' and
sprintf not defined(and no other errors beside these):
int main()
{
  char *ptr;

  ptr = (char *)malloc(10);
  sprintf(ptr, "hello");
  printf("%s\n", ptr);

  return(0);
}



======== attached compilation errors for the first example program ============
yjiang-u5:/users/yjiang/yjiang/temp_c/chk> gcc -nodefaultlibs -lgcc main.c
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o: In function `_start':
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o(.text+0x1c): undefined reference to
 `atexit'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o(.text+0x2c): undefined reference to
 `atexit'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o(.text+0x50): undefined reference to
 `_environ'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o(.text+0x54): undefined reference to
 `_environ'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o(.text+0x64): undefined reference to
 `exit'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/crt1.o(.text+0x6c): undefined reference to
 `_exit'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `frame_init
':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x230):
undefined reference to `malloc'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `extract_ci
e_info':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x450):
undefined reference to `strcmp'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x470):
undefined reference to `strcmp'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x4a4):
undefined reference to `strlen'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x4c0):
undefined reference to `strcmp'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `execute_cf
a_insn':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x56c):
undefined reference to `umul'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c(.text+0x5ac):
undefined reference to `umul'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:436: undefined
 reference to `umul'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:477: undefined
 reference to `malloc'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:480: undefined
 reference to `memcpy'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:487: undefined
 reference to `memcpy'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:488: undefined
 reference to `free'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:507: undefined
 reference to `abort'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `__register
_frame':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:534: undefined
 reference to `malloc'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `__register
_frame_table':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:562: undefined
 reference to `malloc'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `__deregist
er_frame_info':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:585: undefined
 reference to `free'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:594: undefined
 reference to `abort'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `__deregist
er_frame':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:600: undefined
 reference to `free'
/sw/packages/cygnus/progressive-98r1-v0/H-sparc-sun-solaris2.6/bin/../lib/gcc-li
b/sparc-sun-solaris2.6/2.9-cisco-98r1/libgcc.a(frame.o): In function `__frame_st
ate_for':
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:623: undefined
 reference to `memset'
/mrhankey/danger/build/cisco/sparc-sun-solaris2.6/src/gcc/frame.c:647: undefined
 reference to `memcpy'
collect2: ld returned 1 exit status





More information about the Gcc-help mailing list