Im getting this error while trying to run my code using my makefile:
find_bits.o: In function `__x86.get_pc_thunk.bx':
(.text 0x30): multiple definition of `__x86.get_pc_thunk.bx'
/usr/lib/gcc/i686-linux-gnu/5/../../../i386-linux-gnu/crti.o:(.gnu.linkonce.t.__x86.get_pc_thunk.bx 0x0): first defined here
find_bits.o: In function `_fini':
(.fini 0x0): multiple definition of `_fini'
/usr/lib/gcc/i686-linux-gnu/5/../../../i386-linux-gnu/crti.o:(.fini 0x0): first defined here
find_bits.o: In function `data_start':
(.data 0x0): multiple definition of `__data_start'
/usr/lib/gcc/i686-linux-gnu/5/../../../i386-linux-gnu/crt1.o:(.data 0x0): first defined here
find_bits.o: In function `data_start':
(.data 0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i686-linux-gnu/5/crtbegin.o:(.data 0x0): first defined here
find_bits.o:(.rodata 0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i686-linux-gnu/5/../../../i386-linux-gnu/crt1.o:(.rodata.cst4 0x0): first defined here
find_bits.o: In function `_start':
(.text 0x0): multiple definition of `_start'
/usr/lib/gcc/i686-linux-gnu/5/../../../i386-linux-gnu/crt1.o:(.text 0x0): first defined here
find_bits.o:(.rodata 0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i686-linux-gnu/5/../../../i386-linux-gnu/crt1.o:(.rodata 0x0): first defined here
find_bits.o: In function `_init':
(.init 0x0): multiple definition of `_init'
/usr/lib/gcc/i686-linux-gnu/5/../../../i386-linux-gnu/crti.o:(.init 0x0): first defined here
/usr/lib/gcc/i686-linux-gnu/5/crtend.o:(.tm_clone_table 0x0): multiple definition of `__TMC_END__'
find_bits.o:(.data 0x8): first defined here
/usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored.
/usr/bin/ld: error in find_bits.o(.eh_frame); no .eh_frame_hdr table will be created.
collect2: error: ld returned 1 exit status
makefile:2: recipe for target 'open_bits' failed
make: *** [open_bits] Error 1
My makefile code:
open_bits: find_bits.o
gcc -g -ansi -pedantic -Wall find_bits.o -o open_bits
find_bits.o: find_bits.c
gcc -g -ansi -pedantic -Wall find_bits.c -o find_bits.o
My actual code:
#include <stdio.h>
int main()
{/*main*/
/*Creating the 2 long numbers that will get compared
also creating the count variable to store the amount of equal activated bits in the numbers
and another one that will have the decimal value of x&y*/
unsigned long x,y;
int count, decimal_outcome;
count = 0;
printf("\n Enter 2 numbers in the form of 1, 2: ");/*get the numbers from the user*/
scanf("%lu,%lu",&x,&y);
printf("\n You have entered the numbers: %lu, %lu",x,y);
decimal_outcome = x&y;
/*The while loop will convert the decimal outcome of x&y to binary
while checking the open bits and adding to count*/
while(decimal_outcome!=0){/*while*/
if(decimal_outcome%2&1)
count ;
decimal_outcome = decimal_outcome/2;
}/*while*/
printf("\n x and y have %d activated bits in the same spots \n", count);/*printing the amount of equal activated bits*/
return 0;
}/*main*/
I searched for solutions for this problem but nothing seemed to have the exact problem I am having. I am also very new to coding with C so if my mistake is a one which I shouldn't have got with some common knowledge in the language I am sorry for bothering you with my question.
CodePudding user response:
You should add -c
option to create an object file instead of executable binary.
find_bits.o: find_bits.c
gcc -c -g -ansi -pedantic -Wall find_bits.c -o find_bits.o
CodePudding user response:
This make
rule ...
find_bits.o: find_bits.c gcc -g -ansi -pedantic -Wall find_bits.c -o find_bits.o
... builds and links a program named find_bits.o
. Then this rule ...
open_bits: find_bits.o gcc -g -ansi -pedantic -Wall find_bits.o -o open_bits
... asks that program find_bits.o
be linked as if it were an object file, to form program open_bits
.
Use the -c
option to compile to an object file without going on to link the result:
CFLAGS = -g -ansi -pedantic -Wall
open_bits: find_bits.o
gcc $(CFLAGS) $^ -o $@
find_bits.o: find_bits.c
gcc $(CFLAGS) -c $< -o $@