首页 > 解决方案 > 从 TCL 执行 cpp/exe

问题描述

我会从 TCL 调用 call_c_code cpp/exe。我尝试了以下代码:

#!/usr/bin/tclsh
set scripts_path call_c_code.exe
exec gcc -c $scripts_path >@stdout 2>@stderr

但我有以下错误:

% source "tcl_to_call_C.tcl"
gcc.exe: warning: call_c_code.exe: linker input file unused because linking not done

call_c_code.exe 是一个基本的 HelloWorld:

#include <stdio.h>

int main() {
   printf("Hello World!");
   return 0;
}

这是从 TCL 调用“.exe”的正确方法吗?

标签: gcctcl

解决方案


正在做

 set scripts_path call_c_code.exe
 exec gcc -c $scripts_path >@stdout 2>@stderr

你做

gcc -c call_c_code.exe 

哪个不对,需要指明源文件编译

所以可能是这样的

gcc -c call_c_code.c 

然后

 set scripts_path call_c_code.c
 exec gcc -c $scripts_path >@stdout 2>@stderr

但是使用-c您只生成对象而不是可执行文件的选项,可能是您想要的

 set scripts_path call_c_code.c
 exec gcc  $scripts_path >@stdout 2>@stderr

如果你真的想要扩展exe甚至在 Windows 之外添加选项-o

 set scripts_path call_c_code
 exec gcc -o $scripts_path.exe $scripts_path.c >@stdout 2>@stderr

无论如何隐藏编译器产生的可能消息不是一个好主意,最好删除重定向,相反添加选项-Wall以要求编译器发出更多信号


推荐阅读