Reputation: 451
In my makefile I have
readline: readline.h readline.c
gcc -c -o readline readline.c
car: car.c car.h readline.h
gcc -c -o car car.c
dealer.o: dealer.c car.h
gcc -c -o dealer dealer.c
dealer: car.o dealer.o readline.o
gcc car.o dealer.o readline.o
readline.h contains a function prototype that reads in strings that my professor gave us, readline.c is the function,car.c contains a struct with car information, and the various functions for operating on a linked list, dealer.c is where the main function is.
This is my first time with makefiles but I have been getting various errors that are hard to understand saying something about multiple definition of certain functions (some actually in my code and some I guess deep in my code for the system) I don't know why I'm getting these errors.
My goal is to make the main program by linking all the components together.
Errors:
gcc car.o dealer.o readline.o
dealer.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o:(.text+0x0): first defined here
dealer.o: In function `printList':
(.text+0x4ee): multiple definition of `printList'
car.o:car.c:(.text+0x33a): first defined here
dealer.o: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crti.o:(.fini+0x0): first defined here
dealer.o:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o:(.rodata.cst4+0x0): first defined here
dealer.o: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o:(.data+0x0): first defined here
dealer.o:(.rodata+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtbegin.o:(.rodata+0x0): first defined here
dealer.o: In function `clearList':
(.text+0x5e2): multiple definition of `clearList'
car.o:car.c:(.text+0x42e): first defined here
dealer.o: In function `append_to_list':
(.text+0x1b4): multiple definition of `append_to_list'
car.o:car.c:(.text+0x0): first defined here
dealer.o: In function `find_car':
(.text+0x3db): multiple definition of `find_car'
car.o:car.c:(.text+0x227): first defined here
dealer.o: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crti.o:(.init+0x0): first defined here
readline.o: In function `readLine':
readline.c:(.text+0x0): multiple definition of `readLine'
dealer.o:(.text+0x620): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
dealer.o:(.dtors+0x8): first defined here
/usr/bin/ld: error in dealer.o(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status
make: *** [dealer] Error 1
I understand what makefiles are for and what they are suppose to do but I cant seem to get this working.
Upvotes: 1
Views: 1534
Reputation: 29266
Your makefile makes no sense.
readline: readline.h readline.c
gcc -c -o readline readline.c
So your target is "readline", but you use -c, so really it is just "readline.o" - very non standard naming convention. Specifically designed to confuse? This will produce an object file (not an exe) called "readline"
car: car.c car.h readline.h
gcc -c -o car car.c
Same as "readline". This will produce an object file (not an exe) called "car"
dealer.o: dealer.c car.h
gcc -c -o dealer dealer.c
Not even close: the gcc is creating and object file (not an exe) called "dealer" but the target is "dealer.o". At least this time the -c is used properly - you are trying to make a ".o", it's just that the -o is wrong. Since the target is dealer.o (which is not produced) this will always run trying in vain to make dealer.o
dealer: car.o dealer.o readline.o
gcc car.o dealer.o readline.o
No -o, so you don't create "dealer", you create "a.out". Nothing even builds car.o, dealer.o or readline.o and so it will never create anything useful. At least there is no -c so this is perhaps closer to correct...
Upvotes: 1