views:

352

answers:

3

I have this project that that I compile with the following command:

g++ ALE.cpp -lncurses

This gives me a.out file. I have the following Makefile but it seems to not be edited correctly.

HEADERS = LinkedListNode.h LinkedList.h Classes.h GUI.h Functions.h

default: ale

ale.o: ALE.cpp $(HEADERS)
    g++ -c ALE.cpp -o ale.o -lncurses

ale: ale.o
    g++ ale.o -o ale

clean:
    -rm -f ale.o
    -rm -f ale

Errors I get:

g++ ale.o -o ale
ale.o: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o:(.text+0x0): first defined here
ale.o:(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o:(.rodata+0x0): first defined here
ale.o: In function `_fini':
/build/buildd/glibc-2.8~20080505/build-tree/glibc-20080505/csu/../sysdeps/generic/initfini.c:109: multiple definition of `_fini'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crti.o:/build/buildd/glibc-2.8~20080505/build-tree/glibc-20080505/csu/../sysdeps/generic/initfini.c:109: first defined here
ale.o:(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o:(.rodata.cst4+0x0): first defined here
ale.o: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crt1.o:(.data+0x0): first defined here
ale.o: In function `__data_start':
(.data+0x4): multiple definition of `__dso_handle'
/usr/lib/gcc/i486-linux-gnu/4.3.2/crtbegin.o:(.data+0x0): first defined here
ale.o: In function `_init':
/build/buildd/glibc-2.8~20080505/build-tree/i386-libc/csu/crti.S:15: multiple definition of `_init'
/usr/lib/gcc/i486-linux-gnu/4.3.2/../../../../lib/crti.o:/build/buildd/glibc-2.8~20080505/build-tree/i386-libc/csu/crti.S:15: first defined here
/usr/lib/gcc/i486-linux-gnu/4.3.2/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
ale.o:(.dtors+0x4): first defined here
/usr/bin/ld: warning: Cannot create .eh_frame_hdr section, --eh-frame-hdr ignored.
/usr/bin/ld: error in ale.o(.eh_frame); no .eh_frame_hdr table will be created.
collect2: ld returned 1 exit status
make: *** [ale] Error 1
+3  A: 

What happens if you move -lncurses into the ale: rule, i.e.

ale.o: ALE.cpp $(HEADERS)
    g++ -c ALE.cpp -o ale.o

ale: ale.o
    g++ ale.o -o ale -lncurses
foxcub
hmmm no didn't work.
be sure to make clean before trying the suggested changes.
Emil
+1  A: 

Like foxcub said you are providing a linker option to a compile only command (not needed) and no linker option (-lncurses) to generate executable command where it is actually needed.

Murali VP
+2  A: 

It's make no sense to use -l during object file compilation. Use it only when you link your application.

So, you have to move -lncurses from line 6 to line 9.

Elalfer