【发布时间】:2015-07-16 18:29:43
【问题描述】:
我在 Windows 7 上并安装了 MinGW/gcc。我正在使用Eclipse CDT plugin 编译和构建我的第一个简单的 C 程序,并试图了解该插件在幕后所做的究竟是什么。
我创建了一个新的“Hello World!” C项目目录结构如下:
helloworld/
src/
helloworld.c
helloworld.c 在哪里:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
puts("Hello World!");
return EXIT_SUCCESS;
}
所以我在调试模式下创建了一个运行配置(与“发布模式”相反,不是典型 Eclipse 用语中的“调试配置”!)并运行我的应用程序,它运行良好,打印“Hello World!”到 Eclipse 控制台。
现在我正在查看我的文件系统,文件/项目结构如下:
helloworld/
src/
helloworld.c
Debug/
src/
helloworld.d
helloworld.o
subdir.mk
helloworld.exe
makefile
objects.mk
source.mk
我假设在 Eclipse 中运行我的运行配置(因此在 Eclipse 中编译/构建/运行helloworld)在Debug 下创建了所有内容。此外,我假设helloworld.d 和helloworld.o 是已编译的二进制文件,而helloworld.exe 是打包的可执行文件,包含这些二进制文件以及它们链接到的所有内容(stdio 和stdlib)。我还假设 makefile 是实际的 Make 文件(buildscript),并且 *.mk 文件是该 buildscript 的输入。所以,对于初学者,如果这些假设有任何错误,请先纠正我!
当我打开makefile 时,我看到了这个:
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include src/subdir.mk
-include subdir.mk
-include objects.mk
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
# All Target
all: helloworld
# Tool invocations
helloworld: $(OBJS) $(USER_OBJS)
@echo 'Building target: $@'
@echo 'Invoking: Cross GCC Linker'
gcc -o "helloworld" $(OBJS) $(USER_OBJS) $(LIBS)
@echo 'Finished building target: $@'
@echo ' '
# Other Targets
clean:
-$(RM) $(EXECUTABLES)$(OBJS)$(C_DEPS) helloworld
-@echo ' '
.PHONY: all clean dependents
.SECONDARY:
-include ../makefile.targets
请注意:我不是在找人向我解释 Make 的工作原理,我可以为此进行 RTFM ;-)
我只是想了解在 Eclipse 之外从命令行编译、构建和运行 helloworld 需要什么。我需要哪些命令行调用来完成此任务,为什么?一旦我看到这一点,结合阅读 Make 文档,我应该能够填补空白并理解正在发生的一切。
【问题讨论】:
-
从命令行,我会告诉 Eclipse 迷路并直接调用 Mingw。只需配置您的 Windows PATH 以便它在 Mingw 的 bin 目录中查找。
标签: c gcc windows-7 makefile eclipse-cdt