user1733326
user1733326

Reputation: 21

g++ compiling errors in ubuntu

Everytime I try to compile in ubuntu using g++ I get the following errors

g++ test.cpp -o test
/usr/bin/ld: 1: /usr/bin/ld: /bin: Permission denied
/usr/bin/ld: 2: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 3: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 4: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 5: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 6: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 7: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 8: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 9: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 10: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 11: /usr/bin/ld: test.cpp: not found
/usr/bin/ld: 12: /usr/bin/ld: Syntax error: "(" unexpected

I have removed and re-installed g++ numerous times. The chmod for /usr/bin and /usr/bin/ld is 755 and the weird thing is I can run it g++ -c test.cpp however then I can't run the .o file. I am not entirely sure what is the issue.

Upvotes: 2

Views: 1618

Answers (2)

Alan
Alan

Reputation: 489

First of all,g++ -c test.cpp only compile or assemble the source code, but do not link. The ultimate output is an object file. which is .o file in you case. You can't run the .o file.

As mentioned above g++ -c test.cpp just ignore the linking part so ld won't be used, that's why the g++ -c test.cpp works for you.

You can switch to root user and run g++ test.cpp -o test again. If it works, you may have a permission problem on /usr/bin or /usr/bin/ld

Upvotes: 0

CrazyCasta
CrazyCasta

Reputation: 28302

First, a .o file is not meant to be run, it's meant to be linked together with other object files (.o) and libraries (in particular the C++ and C standard libraries). However, I would guess from your error messages that this would probably not work.

From your error message it sounds like perhaps you are running this command in the /bin directory. This is improper. You should be running it in some directory you have write access to (like your home directory). Furthermore it's telling you that it can't find your test.cpp file, are you sure you have cd'ed into the proper directory?

Upvotes: 5

Related Questions