Why is clang ++ not compiling on Mac under Mavericks other than with sudo?

After the last software update on my mac, I can not compile and link the global C ++ hello program without sudo.

Program (helloworld.cpp):

#include <iostream> int main(){ std::cout << "hello world\n"; return 0; } 

Call:

 clang++ helloworld.cpp 

Error with error:

ld: cannot write output file: a.out for x86_64 architecture clang: error: linker command did not work with exit code 1 (use -v to call the call)

But if I do it under sudo,

 sudo clang++ helloworld.cpp 

No problems.

What could be the reason for this and how can I resolve this?


EDIT, again . The answer was not to work with directory permissions, as suggested by several people, but permissions related to the output file, a.out, of my worldwide hello program, Thank Petesh for the solution.

+5
source share
3 answers

You must sit in a directory that is not writable by your user. Look at pwd and ls -ld . to find out where you are and what permissions exist. Try also creating an empty touch foo.txt file in the same directory where you started Clang.

+3
source

Most likely, the answer is: you use clang ++ when your current working directory is not the one with which you have write permissions.

Try to make sure that the directory belongs to you / can be written to you by doing, for example:

 sudo chown -R `whoami` . 

(Note that this may not be acceptable depending on which directory you are in).

In some cases, this happens after updating / updating OSX in projects that were not previously needed.

+3
source

You probably used gcc as root (via sudo), and therefore the created a.out file belongs to root. So just delete it and the problem goes away.

Why did you do that? Since it is annoying, xcode forces you to run it in such a way as to agree to the license agreement!

+2
source

Source: https://habr.com/ru/post/1204613/


All Articles