3

I was compiling a c program as a shared library to be imported using Ctypes into python. These are the steps that I follow :

cc -c -fPIC simplepbc.c -lcrypto -lpbc -lgmp -o ibc.o
cc -shared ibc.o -lcrypto -lpbc -lgmp -Wl,-soname,libibc.so.1 -o libibc.so.1.0.1

It is advised not to use -c when making a shared library, because it will not link after compile(I saw it on some posts here, I'll post the links when I get them). But I have noticed that when I remove the -c, these errors pop up :

ibc.o: In function `_fini':(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.fini+0x0): first defined here
ibc.o: In function `__data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtbeginS.o:(.data.rel+0x0): first defined here
ibc.o: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/x86_64-linux-gnu/4.6/crtendS.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
ibc.o:(.dtors+0x8): first defined here
/usr/bin/ld: error in ibc.o(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status

So I added -c and the errors were gone. Also, I am able to import the library from ctypes as well, without any problems. Will this cause trouble later on?

What are the problems that could arise on compilation with or without -c?

Ajoy
  • 1,838
  • 3
  • 30
  • 57

0 Answers0