sách gpt4 ai đã đi

Lập trình C - Viết các tập tin văn bản tự biên dịch

In lại 作者:行者123 更新时间:2023-12-04 09:41:52 30 4
mua khóa gpt4 Nike

我正在尝试将文件写入磁盘,然后自动重新编译。不幸的是,某事似乎不起作用,我收到一条我还不明白的错误消息(我是 C 初学者 :-)。如果我手动编译生成的 hello.c,一切正常吗?!

#include 
#include

int chính()
{
FILE *myFile;
myFile = fopen("hello.c", "w");
char * text =
"#include \n"
"int main()\n{\n"
"printf(\"Hello World!\\n\");\n"
"return 0;\n}";
system("cc hello.c -o hello");
fwrite(text, 1, strlen(text), myFile);
fclose(myFile);
trả về 0;
}

这是我得到的错误:

/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crt1.o: 在函数 _start':
(.text+0x20): 对
main' 的 undefined reference collect2: ld 返回 1 个退出状态

1 Câu trả lời

这是因为您在编写程序源代码之前调用hệ thống 来编译文件。并且因为此时您的 hello.c 是一个空文件,链接器正确地提示它不包含 chủ yếu chức năng.

尝试改变:

system("cc hello.c -o hello");
fwrite(text, 1, strlen(text), myFile);
fclose(myFile);

到:

fwrite(text, 1, strlen(text), myFile);  
fclose(myFile);
system("cc hello.c -o hello");

关于C 编程 - 编写可自行编译的文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5686816/

30 4 0
Bài viết được đề xuất: 替换 Corrplot 中的 "?"图 block
Bài viết được đề xuất: javascript - 在tensorflow js中左右翻转图像
Bài viết được đề xuất: indexing - RavenDB:如何从 MultiMapIndex 正确查询/过滤嵌套值?
Bài viết được đề xuất: r - 如何绘制和保存 tableGrob 对象
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com