我对 C 非常陌生,习惯了 Java 和 Python。
在我的一项练习中,我必须确保我的程序使用以下命令正确编译:
gcc -std=c17 -Wall -Wextra -pedantic file file.c
不幸的是,我遇到了这些错误:
/usr/bin/ld: file: stdout: invalid version 2 (max 0)
/usr/bin/ld: file: error adding symbols: bad value
collect2: error: ld returned 1 exit status
我的问题是我对这些错误的含义知之甚少(以及添加的错误。我的代码工作得很好。这是代码:
#include <stdio.h>
#include <unistd.h>
void child_A_proc()
{
while (1) {
fprintf(stdout, "%s", "A");
fflush(stdout);
}
}
void child_C_proc()
{
while (1) {
fprintf(stdout, "%s", "C");
fflush(stdout);
}
}
void parent_proc()
{
while (1) {
fprintf(stdout, "%s", "B");
fflush(stdout);
}
}
int main(void)
{
int child_A;
int child_C;
child_A = fork(); /* neuen Prozess starten */
if (child_A == 0){ /* Bin ich der erste Kindprozess? */
child_A_proc(); /* ... dann child-Funktion ausfuehren */
}else{
child_C = fork(); /* neuen Prozess starten */
if (child_C ==0){ /* Bin ich der zweite Kindprozess? */
child_C_proc(); /* ... dann child-Funktion ausfuehren */
}else{
parent_proc(); /* ... sonst parent-Funktion ausfuehren */
}
}
return 0;
}
我试图在互联网上找到一些解释,但我无法将找到的解决方案复制到我的代码中。好吧,至少它没有帮助我理解这个问题。
gcc 是一个 C 语言编译器。
std
-std=c17
是 g++ 编译器的一个选项。如果删除它,您的代码应该可以编译。你也忘记了 -o 标志。gcc -Wall -Wextra -pedantic tmpMain.c -o file