This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
cdecl linking
- To: gcc-help at gcc dot gnu dot org
- Subject: cdecl linking
- From: "Petter Wahlman" <pwa at norman dot no>
- Date: Wed, 15 Aug 2001 09:06:56 +0200
'lo
i need to link cdecl functions with gcc, but can't modify the precompiled
library containing the respective functions. (The library is originaly
compiled under windows, and converted from pe-coff to i386-elf (linux)).
when linking (GNU ld 2.11.90.0.24) i get e.g "undefined reference to `_sprintf'"
the PE linker has the command line option '--enable-stdcall-fixup' which
might solve the above problem, but i have'nt yet had any success.
[100](petter):linking>gcc precompiledlib.c -c; gcc foo.c precompiledlib.o
-> OK
[100](petter):linking>gcc precompiledlib.c -c -DCDECL; gcc foo.c
precompiledlib.o
precompiledlib.o: In function `func':
precompiledlib.o(.text+0x77): undefined reference to `_sprintf'
collect2: ld returned 1 exit status
example code:
---[ foo.c ]---
#include <stdio.h>
extern char *func(char *);
int main(int argc, char **argv)
{
if (argc < 2) exit(1);
printf("%s\n", func(argv[1]));
return 0;
}
#define PREFIX "Recived argument: "
---[ precompiledlib.c ]---
char *func(char *ptr)
{
char *buf = (char *)malloc(strlen(PREFIX)+strlen(ptr)+1);
if (!buf) {
perror("malloc()");
exit(1);
}
#ifdef CDECL /* does not work */
_sprintf(buf,"%s%s",PREFIX,ptr);
#else /* works */
sprintf(buf,"%s%s",PREFIX,ptr);
#endif
return buf;
}
Thanks
Petter Wahlman