How to solve 'collect2: ld returned 1 exit status '?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to solve 'collect2: ld returned 1 exit status '?
Hi guys, today I wanted to start learning about programming, so I wanted to do that Hello World crap thinking it would be really easy, so I wrote the program:
Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
printf("\nHello World!");
return(0);
}
And for compiling it I wrote the command:
Code:
gcc -Wall -W -Werror helloworld.c -o helloworld
But it didn't work and I got:
Code:
collect2: ld returned 1 exit status
I googled for a solution but I didn't found anything, help me please, thx.
Excuse me for being confused, because I am not getting the same error. in any of the three, BASH will not return that error, I just thought I'd add that for you benefit to show you BASH too.
where is it exacly? on your home/user why are you changing permissions?
755 read write execute user
Code:
Frequently used numeric parameters for chmod
755 The general preferred permissions for almost all the files on your disk
775 General files used when working as a Group (Others can only view/execute your files)
770 Important files used when working as a Group (Others cannot do anything with your files)
using -R changes every thing
Code:
echo $USER: <---- that colon is not suppose to be there
userx@slackwhere101:~
$ touch permissions700
$ chmod 700 permissions700
$ ls -la permissions700
-rwx------ 1 userx users 23 Feb 21 10:22 permissions700
$ echo "in file permissions700" >> permissions700
$ cat permissions700
in file permissions700
when changing owner I usually add user group, but for whatever reasons you're just making it so no one but you can do anything to that dir and whats in it.
Well, I tried to change the permissions, I mean I wrote the command:
sudo chmod 777 /path/to/my/folder
but when I put:
ls -l path/to/my/folder
I got
-rwx------ 1 root rooot 100
Quote:
What distribution/version are you running?
How did you create helloworld.c? What were the exact commands used. What directory is helloworld.c located.
I've got Debian.
I first wrote
Code:
sudo nano helloworld.c
Then the program I told you above, and then I tried to compilated it.
Well, I tried to change the permissions, I mean I wrote the command:
sudo chmod 777 /path/to/my/folder
but when I put:
ls -l path/to/my/folder
I got
-rwx------ 1 root rooot 100
I've got Debian.
I first wrote
Code:
sudo nano helloworld.c
Then the program I told you above, and then I tried to compilated it.
mmm why are you root?
programming is not system admin. Nonetheless, if you are logged in as root, which I don't think you'd be because Debain hides root account.
and you are an user and want to use that dir
Code:
sudo chown user:group /path/to/dir -R
#to fix it so you can use it as a user,
the group is a group you belong to, mostly your main group.
then,
as I am in root account at the moment.
Code:
root@slackwhere101:~
# login userx
Password:
Linux 4.4.14.
No mail.
The problem with the gene pool is that there is no lifeguard.
userx@slackwhere101:~$ mkdir ~/testdir
userx@slackwhere101:~$ ls -la ~/testdir
total 8
drwxr-xr-x 2 userx users 4096 Feb 21 11:35 ./
drwx--x--x 34 userx users 4096 Feb 21 11:35 ../
userx@slackwhere101:~$ sudo mkdir ~/testdir2
userx@slackwhere101:~$ ls -la ~/testdir2
total 8
drwxr-xr-x 2 root root 4096 Feb 21 11:35 ./
drwx--x--x 35 userx users 4096 Feb 21 11:35 ../
userx@slackwhere101:~$ sudo chown userx:users ~/testdir2 -R
userx@slackwhere101:~$ ls -la ~/testdir2
total 8
drwxr-xr-x 2 userx users 4096 Feb 21 11:35 ./
drwx--x--x 35 userx users 4096 Feb 21 11:35 ../
userx@slackwhere101:~$ chmod 700 ~/testdir2
userx@slackwhere101:~$ ls -la ~/testdir2
total 8
drwx------ 2 userx users 4096 Feb 21 11:35 ./
drwx--x--x 35 userx users 4096 Feb 21 11:35 ../
if you look at the command sudo and creating a dir who gets ownership of it, and whoever has ownership of the dir or file can do whatever they want to it. even changes permissions on it, no need to use sudo if user owns the dir.
I am coming in here a little late in the game, so let me recap and offer my own suggestions in addition to the excellent comments already posted.
First, when posting error messages, especially compiler messages, always include any lines which indicate error, failure, missing files or permission problems, etc. Very often the final error message is the result of something already reported, such as the file permission problem in this case. That will save time and effort and help others to more quickly understand what is happening.
I will defer to others to help with fixing the bad file permissions if they like, but please note that this is a separate, self-inflicted problem not actually part of your initial interest in building the hello world program. That resulted from unnecessary use of sudo and chmod, not from any normal code or compile problem - so knowing that I might suggest that you simply start over, without sudo, write, compile and run your hello world program. Then try to learn about file permissions, sudo, etc. as a separate and better focused task.
And as I am sure you will hear from others - often - never, ever try to fix a problem like this...
Quote:
Originally Posted by velvetmist
Well, I tried to change the permissions, I mean I wrote the command:
sudo chmod 777 /path/to/my/folder...
Doing so is always wrong, will mask other problems and dig yourself deeper into whatever hole you are stuck in at the moment!
Try to develop a reflexive "STOP!" response when told to chmod 777, and don't form that very bad habit! Instead, spend just a little time trying to understand the basic why and how of Unix/Linux file permissions. It is really pretty simple and well founded, and you will have to learn your way around it sooner or later - make it sooner!
I might suggest that you simply start over, without sudo, write, compile and run your hello world program. Then try to learn about file permissions, sudo, etc. as a separate and better focused task.
@OP Go back to square 1 (delete the previous files), but this time forget su, sudo, chmod and alike. All you need is text-editor and gcc. And if you get some error messages quote all of them, not only the last line.
[Edit: I see it has been suggested again and again. You should actually do it.]
Bored at work so replying just for clarity. You should do as following:
Delete everything you have done.
As normal user, create a new directory.
In that directory, create helloworld.c. Beware of the spaces after #include: spaces aren't normaly an issue in code, but #include is a preprocessor directive and is not exatcly code...
Compile, link and execute.
Get yourself a copy of the Kernighan & Ritchie, the Bible for C programming.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.