gpt4 book ai didi

c - "can’ t open/tmp/ccRBTake.s for writing”, while compiling with gcc

转载 作者:太空宇宙 更新时间:2023-11-04 02:09:54 24 4
gpt4 key购买 nike

我在编译以下代码时遇到异常的编译时错误:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
if (open("b.txt", O_CREAT | O_RDWR | O_TRUNC, 0777) < 0) {
perror("open error:");
exit(1);
}
return 0;
}

在一个不包含b.txt的目录中。
错误如下:

test.c:1:0: fatal error: can’t open /tmp/ccrlx6NY.s for writing: Permission denied
compilation terminated.
The bug is not reproducible, so it is likely a hardware or OS problem.

我正在使用 GNU/Linux (3.2.0-39-generic) 操作系统和 gcc 编译器版本 4.6.3。

$df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda5 44240004 10753148 31239588 26% /
udev 1004132 4 1004128 1% /dev
tmpfs 406548 1228 405320 1% /run
none 5120 0 5120 0% /run/lock
none 1016364 236 1016128 1% /run/shm
/dev/sda7 80731936 47718056 28912916 63% /home

我收到此消息的确切原因是什么?

PS:我现在实际上在编译的每个文件上都会收到此错误。

最佳答案

尝试使用 TMPDIR 环境变量强制使用另一个 tmp-dir:

mkdir ~/tmp
export TMPDIR=~/tmp
gcc test.c -o mytest

并检查您的 umask 值。尝试

umask 022

并再次调用您的编译调用。

关于c - "can’ t open/tmp/ccRBTake.s for writing”, while compiling with gcc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15564752/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com