在 Windows 上使用 Tiny C Compiler 编译并运行 file.c

标签 c windows compiler-construction tcc

我可以逐步了解如何使用 Tiny C 编译器和 Windows 提示编译我的 file.c 吗?

一些我已经有的问题:

  1. 将下载的所有 TCC 文件粘贴到哪里?
  2. 是否必须编译 stdio.h 才能使用 printf 函数? (我想做一个“Hello World”)。

这是我的 file.c 的样子:

// #include <stdio.h> // for printf 

int main(void){
printf("Hello Eric. You've compiled and run the program!  \n");
}

谢谢,


编辑 1

到目前为止,我正在运行它并收到错误:未找到包含文件“stdio.h”。

最佳答案

  1. 您可以将文件放在任何您喜欢的地方。

  2. 不,您不需要编译 stdio.h 即可使用 printf() 函数。

tcc-distribution (tcc-0.9.25-win32-bin\tcc) 包含以下内容:

 tcc.exe
 tiny_impdef.exe
 tiny_libmaker.exe
 include\
   stdio.h ...
 lib\
   libtcc1.a ...
 doc\
 examples\  

如果你不撕开那个命令,tcc 应该开箱即用(我在几秒钟前编译了一个 hello.c)。如果您将文件分开或其他方法不起作用:

% tcc.exe -Ipath/to/include/folder/of/tcc input.c -L/path/to/lib/folder/of/

通过查看tcc 的源代码,我发现了这个:

/* on win32, we suppose the lib and includes are at the location
   of 'tcc.exe' */

char path[1024], *p;
GetModuleFileNameA(NULL, path, sizeof path);
p = tcc_basename(normalize_slashes(strlwr(path)));

因此,默认情况下,它假定库和 header 位于 tcc.exe 旁边的位置。

关于在 Windows 上使用 Tiny C Compiler 编译并运行 file.c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5031529/

相关文章:

c - 编译器是否在创建目标代码之前生成隐式转换的代码?

c++ - 在 C++ 中制作基于文本的 RPG 游戏/模板的问题

c - 带有结构数组的函数段错误

c - 何时在 C 中将局部变量声明为静态变量?

c++ - 操作系统开发。如何开始?

c# - 在 Visual Studio 中运行命令的 DTE2 问题

c++ - NVidia NVML nvmlDeviceGetMemoryInfo() 立即加载和卸载 nvapi64.dll

c# - 为什么我必须在 C# 中指定 "out"关键字?

python - Python 如何区分 Int 和 Double

c - 当我们有 poll() 和 epoll() 时,为什么要使用 select()