Reputation: 673
I have the text of a Makefile, and I am trying to compile it and produce a .e executable file. I am trying to compile it in g++, but I am having some difficulty. Please note I have a MacBook Pro running Mavericks.
I have tried two methods--the first was to open up Xcode and make a new .cpp file. I then copied the Makefile text into the empty .cpp file and saved it as Makefile.g++. In the Mac terminal, I then executed
g++ Makefile.g++
It returns the error
d: warning: ignoring file Makefile.g++, file was built for unsupported file format (
0x23 0x20 0x47 0x65 0x6E 0x65 0x72 0x69 0x63 0x20 0x70 0x69 0x6D 0x63 0x20 0x67 ) which
is not the architecture being linked (x86_64): Makefile.g++
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I then tried saving it as Makefile.cpp, and executing
g++ Makefile.cpp
I then get the error
Makefile.cpp:11:3: error: invalid preprocessing directive
# Generic pimc g++ makefile
^
Makefile.cpp:13:1: error: C++ requires a type specifier for all declarations
CC = g++
^~
Makefile.cpp:13:11: error: use of undeclared identifier 'g'
CC = g++
^
Makefile.cpp:16:2: error: invalid preprocessing directive
#CC = /opt/local/bin/g++-mp-4.7
^
Makefile.cpp:17:2: error: invalid preprocessing directive
#LD = /opt/local/bin/g++-mp-4.7
^
Makefile.cpp:33:3: error: invalid preprocessing directive
# Edit below to include details on your specific host
^
Makefile.cpp:116:3: error: invalid preprocessing directive
# -------------------------------------------------------------------------------
^
Makefile.cpp:119:3: error: invalid preprocessing directive
# Link
^
Makefile.cpp:123:3: error: invalid preprocessing directive
# Compile
^
Makefile.cpp:127:3: error: invalid preprocessing directive
# -------------------------------------------------------------------------------
^
Makefile.cpp:130:22: error: expected ';' after top level declarator
$(RM) $(PROG) $(OBJS)
^
;
11 errors generated.
What am I doing incorrect? Can the Makefile not run on my machine, or is it something to do with my commands?
Upvotes: 1
Views: 972
Reputation: 5151
Whoa there cowboy! You've told g++
that Makefile.cpp
is a C++
source file, not a makefile. mv Makefile.cpp Makefile
, then run make
. That should help out.
Your fundamental source of confusion is that you are under the impression that you should compile a makefile, but makefiles are a set of rules for compiling source files. Once you get the hang of things, the command g++ Makefile
will look horrifying to you, because you'll know that make
invokes g++
.
Upvotes: 5