Question

I have created the .o file as follows,

*gcc -I/home/vineeshvs/Dropbox/wel/workspace/Atmel -I /home/vineeshvs/Downloads/libusb-1.0.9 -I /home/vineeshvs/Downloads/libusb-1.0.9/libusb/ usb_comm.c hex2bin.c hex_read.c crc32.c -o vs.o -lusb-1.0*

Then I used the following command to get .so file

*gcc vs.o -shared  -o libhello.so*

Then I am getting error as follows

*vs.o: In function `__i686.get_pc_thunk.bx':

(.text+0xaa6): multiple definition of `__i686.get_pc_thunk.bx'
/usr/lib/gcc/i686-linux-gnu/4.6/crtbeginS.o:crtstuff.c:

(.text.__i686.get_pc_thunk.bx[__i686.get_pc_thunk.bx]+0x0): first defined here
vs.o: In function `_fini':

(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crti.o:(.fini+0x0): first defined here
vs.o: In function `__data_start':

(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i686-linux-gnu/4.6/crtbeginS.o:(.data.rel+0x0): first defined here
vs.o: In function `_init':

(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/i686-linux-gnu/4.6/crtendS.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
vs.o:(.dtors+0x4): first defined here
/usr/bin/ld.bfd.real: error in vs.o(.eh_frame); no .eh_frame_hdr table will be created.

collect2: ld returned 1 exit status

*

What could be the problem? (Thanks for stopping by :))

Was it helpful?

Solution

The problem is that you're linking the object files, not just compiling them.

Make sure that you only compile the files, don't link them! You do that using the -c option. Do not use the -l option, you don't want to link anything at this stage. So:

gcc -c -o usb_comm.o usb_comm.c
gcc -c -o hex2bin.o hex2bin.c
gcc -c -o hex_read.o hex_read.c
gcc -c -o crc32.o crc32.c

(I omitted the -I flags to save space here.)

Then finally link all those object files into a shared library, and link against usb-1.0:

gcc -shared -o libhello.so usb_comm.o hex2bin.o hex_read.o crc32.o -lusb-1.0

You should use a Makefile though for this. Or, even better, use a proper build system, like CMake, which is very easy to use. It's provided by all common Linux distros, so simply install it with the package manager (it it's not installed already), and read a quick tutorial on it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top