Jos*_*nan 7 c gcc compiler-errors
我使用时,我的代码无法正确编译:
system("gcc -o filename temp.c");
我正进入(状态:
implicit declaration of function system
我不确定缺少什么,因为它只会在gcc调用上抛出系统错误.
这是我的代码:
#include <stdio.h>
int main() {
        ...
        system("gcc -o filename temp.c");
        return 0;
}
gsa*_*ras 10
添加#include <stdlib.h>在顶部main().
提示:当您看到内置函数的隐式声明时,您必须搜索该函数(使用google,例如现在您应该搜索"system()C"),以便找到相应的标题,即声明函数的位置.然后其中一个结果应该是函数的ref.
在我们的例子中这个链接.在那里你可以看到:
概要
#include <stdlib.h>
int system(const char *command);
它告诉您必须包含stdlib要使用的标头system().
正如布莱特先生所注意到的那样,如果您使用类似inux的操作系统,man 3 system那么也应该这样做.
例:
samaras@samaras-A15:~$ man 3 system
SYSTEM(3)                  Linux Programmer's Manual                 SYSTEM(3)
NAME
       system - execute a shell command
SYNOPSIS
       #include <stdlib.h>  <-- this is what we are looking for!
       int system(const char *command);
...