I am coding in OS X
Here is my Makefile:
#makefile for stack_5_1
# Yitong Zhou
stack_5 : main.o Stack.o LIFO_Stack.o Peekback_Stack.o
g++ -o stack_5 main.o Stack.o LIFO_Stack.o Peekback_Stack.o
main.o: main.cpp Stack.h LIFO_Stack.h Peekback_Stack.h
g++ -c main.cpp
Stack.o: Stack.cpp Stack.h
g++ -c Stack.cpp
LIFO_Stack.o: LIFO_Stack.cpp LIFO_Stack.h
g++ -c LIFO_Stack.cpp
Peekback_Stack.o: Peekback_Stack.cpp Peekback_Stack.h
g++ -c Peekback_Stack.cpp
clean:
rm -rf *.o stack_5
The error:
..... // very very long
Dwarf Exception Unwind Info (__eh_frame) in Stack.o
Dwarf Exception Unwind Info (__eh_frame) in LIFO_Stack.o
Dwarf Exception Unwind Info (__eh_frame) in Peekback_Stack.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [stack_5] Error 1
What is the difference between gcc and g++? Why does my compile fail when I replace g++ with gcc?
By the way, how could I ensure that my makefile could be run correctly in Cygwin, linux, OS X and maybe other environment.
gcc is for compiling C by default
g++ is for compiling C++ by default
The primary difference is that g++ transparently adds the options
-x c++(use C++) and-lstdc++(use C++ standard library).Try this Makefile:
make will automatically fill in the sensible rules based on the file extensions.
Also take a look at the
-MMgcc option. It will automatically generate the correct make dependencies (which header files) so you don’t need to maintain this list manually. There is more in the make manual and gcc manual about how to use it.