so I'm completely new to Ubuntu. I've set up a shared folder with a few c programs and when I go to compile in Ubuntu, such as:

gcc file.c -o fileTest

I get the following error:

/usr/bin/ld: cannot open output file fileTest: Permission denied
collect2: error: ld returned 1 exit status

I'm sure that my permissions for the C files are correct, all files have 'rwx' permissions.

Do I have to change the permission of the fileTest as well?

I'm a complete newb, so apologies.

有帮助吗?

解决方案 2

Try with sudo rm fileTest and re-run the command. This will work if the problem is that fileTest exists and you don't have permission to overwrite it.

It won't help if you don't have write permission for the directory. It will delete the file but the gcc command will still fail.

其他提示

Maybe the directory itself has not the write permission. To change it, get to the parent directory and type

chmod a+w directory_name

This will give to all people write permission. You could use also u+w (if directory belongs to your user) or g+w if your user belongs to the group the directory belongs to.

Installed mongoose on Ubuntu 18.04 but ran into cannot open output file unit_test: Permission denied error which contains conflicting changes to the same degraded array, even within the make install write intent. Both ways # and $ try to compile - root mode wins, $ fails, interrupts the move job with a fake, useless implementation, and invokes a dialog to broadcast a message to a banned user. And it says that a fatal error: open output file, when executed, received a non-zero return code 1! Make requested an impossible situation. I have output when typing as from normal user:

:~$ make

/usr/bin/ld: cannot open output file unit_test: Permission denied
collect2: error: ld returned 1 exit status
Makefile:51: recipe for target 'unamalgamated' failed
make: *** [unamalgamated] Error 1

Your need to run in root mode:

:~$ sudo su
  # make

Removing "exit status" status:

cc mongoose.c -O3 -g3 -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wundef -Isrc -I. -DMG_MAX_HTTP_HEADERS=7 -DMG_ENABLE_LINES -DMG_ENABLE_PACKED_FS=1 -fsanitize=address,undefined -DMG_ENABLE_IPV6=1   -DMG_ENABLE_MBEDTLS=1 -I/usr/local/include -I/usr/include -c -o /tmp/x.o && nm /tmp/x.o | grep ' T' | grep -v 'mg_' ; test $? = 1
cc src/*.c test/packed_fs.c test/unit_test.c -O3 -g3 -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wundef -Isrc -I. -DMG_MAX_HTTP_HEADERS=7 -DMG_ENABLE_LINES -DMG_ENABLE_PACKED_FS=1 -fsanitize=address,undefined -DMG_ENABLE_IPV6=1   -DMG_ENABLE_MBEDTLS=1 -I/usr/local/include -I/usr/include -L/usr/local/lib -lmbedtls -lmbedcrypto -lmbedx509 -g -o unit_test
cc -I. mongoose.c test/unit_test.c -o unit_test
cc mongoose.c test/unit_test.c test/packed_fs.c -O3 -g3 -W -Wall -Werror -Wshadow -Wdouble-promotion -fno-common -Wconversion -Wundef -Isrc -I. -DMG_MAX_HTTP_HEADERS=7 -DMG_ENABLE_LINES -DMG_ENABLE_PACKED_FS=1 -fsanitize=address,undefined -DMG_ENABLE_IPV6=1   -DMG_ENABLE_MBEDTLS=1 -I/usr/local/include -I/usr/include -coverage -L/usr/local/lib -lmbedtls -lmbedcrypto -lmbedx509 -g -o unit_test
ASAN_OPTIONS=detect_leaks=1  ./unit_test
d07b6 3 sock.c:521:mg_listen           1 accepting on http://LOCALHOST:12358 (port 12358)
d07b6 3 sock.c:387:mg_connect          2 -> http://LOCALHOST:12358
d07b7 3 sock.c:419:accept_conn         3 accepted 127.0.0.1:42382
d07c3 3 sock.c:305:close_conn          2 closed
d07c3 3 sock.c:122:iolog                 3 00100000000010 0:0 -1 err 115 (Operation now in progress)
d07c3 3 sock.c:305:close_conn          3 closed
d07c3 3 sock.c:387:mg_connect          4 -> http://LOCALHOST:12358
d07c4 3 sock.c:419:accept_conn         5 accepted 127.0.0.1:42384
d07c4 3 sock.c:305:close_conn          4 closed
d07c4 3 sock.c:122:iolog                 5 00100000000010 0:0 -1 err 115 (Operation now in progress)
d07c4 3 sock.c:305:close_conn          5 closed
d07c4 3 sock.c:387:mg_connect          6 -> http://LOCALHOST:12358
d07c5 3 sock.c:419:accept_conn         7 accepted 127.0.0.1:42386
d07c5 3 sock.c:305:close_conn          6 closed
d07c5 3 sock.c:122:iolog                 7 00100000000010 0:0 -1 err 115 (Operation now in progress)
d07c6 3 sock.c:305:close_conn          7 closed
d07c6 3 sock.c:387:mg_connect          8 -> http://LOCALHOST:12358
d07c6 3 sock.c:419:accept_conn         9 accepted 127.0.0.1:42388
...

I had time to grub, after a long pause from $, which is related to unsuccessful traps, and i see that ./unit_test is trying to perform an incremental build "..." of already running parts. That's why i'm marking this bug as "fixed".

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top