0

I have a problem, after compilation i wan't to link using ld but when i do I get an error lets see what I do:

make i386
gcc -g -c -I. -I/usr/include -o p_test.o.i386 pkcs11test.c
ld -o p_test.i386 p_test.o.i386 -g -ldl     
ld: p_test.o.i386: référence au symbole non défini «fflush@@GLIBC_2.0»
//lib/i386-linux-gnu/libc.so.6: error adding symbols: DSO missing from command line
make: *** [i386_p_test] Erreur 1

So with ld I got this error but when I try with gcc

make i386
gcc -g -c -I. -I/usr/include -o p_test.o.i386 pkcs11test.c
gcc -o p_test.i386 p_test.o.i386 -g -ldl

I got no error and my executable

Do you know how I can make ld work with for linking my program ?

Thanks !

osgx
  • 90,338
  • 53
  • 357
  • 513
Johnvox
  • 52
  • 5

1 Answers1

2

When you start gcc with gcc -o p_test.i386 p_test.o.i386 -g -ldl, it actually adds a lot internal libraries to the ld command. You can see all arguments by adding -v option to gcc. One of "internal library" is the glibc itself (-lc).

For example, here GCC verbose mode output explanation we can see collect2 program which is used to link the executable. There are -lgcc -lgcc_eh -lc -lgcc -lgcc_eh libraries added to the run and several CRT runtime objects are linked too:

/usr/lib/gcc-lib/i686/3.3.1/collect2
 --eh-frame-hdr -m elf_i386 -dynamic-linker
 /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o
 /usr/lib/gcc-lib/i686/3.3.1/crtbegin.o
 -L/usr/lib/gcc-lib/i686/3.3.1
 -L/usr/lib/gcc-lib/i686/3.3.1/../../..
  /tmp/ccQynbTm.o  # << this is input file.
 -lgcc -lgcc_eh -lc -lgcc -lgcc_eh
 /usr/lib/gcc-lib/i686/3.3.1/crtend.o
 /usr/lib/crtn.o

PS: I think it will be better not to change file extensions (suffixes). Your p_test.o.i386 can be renamed into p_test.i386.o

Community
  • 1
  • 1
osgx
  • 90,338
  • 53
  • 357
  • 513