Gcc 从TCL执行cpp/exe
我会从TCL调用call_c_代码cpp/exe。 我尝试了以下代码:Gcc 从TCL执行cpp/exe,gcc,tcl,Gcc,Tcl,我会从TCL调用call_c_代码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 linkin
#!/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;
}
#包括
int main(){
printf(“你好,世界!”);
返回0;
}
这是从TCL调用“.exe”的正确方法吗
是吗
gcc -c call_c_code.exe
这是错误的,您需要指出编译它的源文件
所以可能是这样的
gcc -c call_c_code.c
然后
但是使用选项-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
,要求编译器发出更多执行操作的信号
是吗
gcc -c call_c_code.exe
这是错误的,您需要指出编译它的源文件
所以可能是这样的
gcc -c call_c_code.c
然后
但是使用选项-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
,要求编译器发出更多的信号调用C编译器要比您习惯的稍微复杂一些。您需要将源代码放入扩展名为.c
的文件中,然后将其编译为可执行文件(Windows上的扩展名为.exe
;其他平台有不同的规则!),然后才能运行它。当您开始使用库时,还有很多其他的复杂性。但是首先
call_c_code.exe
重命名为call_c_code.c
set Compiler "gcc"; # Can override this to be clang if you have it?
proc compile {sourceFile} {
global Compiler
# Make sure we use the full name of the executable when running it
set executable [file normalize [file rootname $sourceFile].exe]
# Only run the compiler if file not executable or source file is newer
if {
![file isfile $executable]
|| ![file executable $executable]
|| [file mtime $sourceFile] > [file mtime $executable]
} then { # <<< I like to use 'then' after a multi-line condition!
exec $Compiler -c -o $executable $sourceFile >@stdout 2>@stderr
}
return $executable
}
set exe [compile call_c_code.c]
set output [exec $exe]
puts "The output was: $output"
设置编译器“gcc”;#如果您有,可以将其覆盖为叮当声吗?
proc compile{sourceFile}{
全局编译器
#确保在运行可执行文件时使用其全名
设置可执行文件[file normalize[file rootname$sourceFile].exe]
#仅当文件不可执行或源文件较新时才运行编译器
如果{
![文件isfile$可执行文件]
||![文件可执行文件$可执行文件]
||[文件mtime$sourceFile]>[文件mtime$executable]
}然后{#@stderr
}
返回$executable
}
set exe[compile call_c_code.c]
设置输出[exec$exe]
放置“输出为:$output”
调用C编译器比您习惯的要复杂一些。您需要将源代码放入扩展名为
.c
的文件中,然后将其编译为可执行文件(Windows上的扩展名为.exe
;其他平台有不同的规则!),然后才能运行它。当您开始使用库时,还有很多其他的复杂性。但是首先
call_c_code.exe
重命名为call_c_code.c
set Compiler "gcc"; # Can override this to be clang if you have it?
proc compile {sourceFile} {
global Compiler
# Make sure we use the full name of the executable when running it
set executable [file normalize [file rootname $sourceFile].exe]
# Only run the compiler if file not executable or source file is newer
if {
![file isfile $executable]
|| ![file executable $executable]
|| [file mtime $sourceFile] > [file mtime $executable]
} then { # <<< I like to use 'then' after a multi-line condition!
exec $Compiler -c -o $executable $sourceFile >@stdout 2>@stderr
}
return $executable
}
set exe [compile call_c_code.c]
set output [exec $exe]
puts "The output was: $output"
设置编译器“gcc”;#如果您有,可以将其覆盖为叮当声吗?
proc compile{sourceFile}{
全局编译器
#确保在运行可执行文件时使用其全名
设置可执行文件[file normalize[file rootname$sourceFile].exe]
#仅当文件不可执行或源文件较新时才运行编译器
如果{
![文件isfile$可执行文件]
||![文件可执行文件$可执行文件]
||[文件mtime$sourceFile]>[文件mtime$executable]
}然后{#@stderr
}
返回$executable
}
set exe[compile call_c_code.c]
设置输出[exec$exe]
放置“输出为:$output”
这很奇怪。您通常将gcc称为传递源代码文件(例如something.cpp),从中创建可执行文件(例如something.exe)。您似乎正在传递一个扩展名为.exe的源代码文件,这向gcc表明它已经编译了代码,所以gcc认为它没有工作要做。这相当奇怪。您通常将gcc称为传递源代码文件(例如something.cpp),从中创建可执行文件(例如something.exe)。您似乎正在传递一个扩展名为.exe的源代码文件,这表明gcc已经编译了代码,因此gcc认为它没有工作要做。也可以使用MSVC进行构建,但是您传递的标志不同,我不太了解它们,无法编写代码。;)也可以使用MSVC进行构建,但是您传递的标志是不同的,我不太了解它们,因此无法编写代码编译器在决定如何处理文件时会查看扩展名。编译器在决定如何处理文件时会考虑扩展名。你必须把它们弄对。