【问题标题】:Compile and run a file.c using Tiny C Compiler on Windows在 Windows 上使用 Tiny C 编译器编译和运行 file.c
【发布时间】:2011-06-29 05:26:46
【问题描述】:

我能否逐步了解如何使用 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”。

【问题讨论】:

    标签: c windows compiler-construction tcc


    【解决方案1】:
    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)));
    

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

    【讨论】:

    • 你能解释一下你在第一段代码中做了什么吗?这些命令是我在运行代码之前输入到提示符中的吗?
    • @Eric Brotto:第一个块是 tcc 发行版中的文件列表。第二个块是您可以在提示中输入的内容。
    • 感谢并原谅我的无知。所以我基本上只是运行第二个代码块(一个衬里),我应该没问题?
    • @Eric Brotto:如果您保持 tcc 发行版的文件完整,那么您只需运行 tcc.exe file.c
    • 这成功了!你摇滚!感谢您回到我的 cmets :)
    猜你喜欢
    • 2013-07-07
    • 1970-01-01
    • 2011-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 1970-01-01
    • 2011-11-23
    相关资源
    最近更新 更多