使用 g++ 编译生成文件时出现问题
Trouble compiling a Makefile using g++
我有一个Makefile的文本,我正在尝试编译它并生成一个.e可执行文件。我正在尝试用 g++ 编译它,但我遇到了一些困难。请注意,我有一台运行小牛队的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.
我做错了什么?生成文件不能在我的机器上运行,还是与我的命令有关?
哇,牛仔!你告诉g++
Makefile.cpp
是一个C++
源文件,而不是生成文件。 mv Makefile.cpp Makefile
,然后运行make
。这应该会有所帮助。
混淆的根本原因是你认为你应该编译一个生成文件,但生成文件是一组编译源文件的规则。一旦你掌握了窍门,命令g++ Makefile
对你来说会很可怕,因为你会知道make
调用g++
。
相关文章:
- 使用mongocxx驱动程序时包含头文件问题
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 编译要在英特尔Hyperscan中使用的.cc文件时出现问题
- 使用 seekg() 读取C++中的文件时出现问题
- sqlite3 和生成文件中的链接出现问题
- C++头文件和类实现出现问题
- 用户输入字符串的文件附加问题..C++
- node-gyp 的先有鸡还是先有蛋的问题:指向依赖项中的头文件
- 读取文件并将其存储在unordered_map中时出现问题
- 编译 llvm 插件时出现问题:llvm/Config/llvm-config.h:没有这样的文件或目录
- 我在使用C++文件时遇到了一些问题
- 在Linux上使用Clang / OLLVM交叉编译helloworld Windows可执行文件时的问题
- 将文件复制到自定义位置,存在字符串转换问题
- DirectX12 的问题:"d3dApp.h":没有这样的文件或目录
- (ODR 使用问题)在不同文件中priority_queue名称相同的结构
- C++模板编程设计问题 - 根据输入文件返回不同的类型
- 读取制表符分隔的文件时出现问题 C++
- 当我在 CLion 中读取数组中的 txt 文件时C++编码问题
- 使用 RapidXML 解析大型 XML(大小大于 65 KB)文件时出现问题
- C++:读取.BMP文件时出现问题;文件结束时间早于预期