当我运行以下代码时,我得到
collect2: fatal error: cannot find 'ld'
compilation terminated.输出。我的海湾合作委员会版本是gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0. 似乎无法找到ld模块。我不知道如何继续前进。
#define _GNU_SOURCE
#include<unistd.h>
#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
int main(){
char *stderr = "/home/vs/Desktop/test/output.txt";
char *args[] = {"/usr/bin/gcc",
"-Wall",
"-O2",
"-std=gnu11",
"-fomit-frame-pointer",
"/home/vs/Desktop/test/Solution.c",
"-o",
"/home/vs/Desktop/test/Solution",
"-lm",
NULL};
char *env[] = {"LANG=en_US.UTF-8", "LANGUAGE=en_US:en", "LC_ALL=en_US.UTF-8", NULL};
int fd;
if(0 > (fd = open(stderr, O_WRONLY|O_TRUNC))) perror("open");
if(0 > dup2(fd, 2)) perror("dup");
if(fd != 2) close(fd);
int x = execve("/usr/bin/gcc", args, env);
printf("%d\n", x);
return 0;
}
Run Code Online (Sandbox Code Playgroud)