【发布时间】:2015-01-04 18:55:05
【问题描述】:
我有一个 Makefile 的文本,我正在尝试编译它并生成一个 .e 可执行文件。我正在尝试用 g++ 编译它,但我遇到了一些困难。请注意,我有一台运行 Mavericks 的 MacBook Pro。
我尝试了两种方法——第一种是打开 Xcode 并创建一个新的 .cpp 文件。然后我将 Makefile 文本复制到空的 .cpp 文件中,并将其保存为 Makefile.g++。然后在Mac终端执行
g++ Makefile.g++
返回错误
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)
然后我尝试将其保存为 Makefile.cpp,然后执行
g++ Makefile.cpp
然后我得到错误
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.
我做错了什么? Makefile 不能在我的机器上运行,还是和我的命令有关?
【问题讨论】:
标签: c++ macos makefile g++ clang