Hi everyone!
So can someone explain me how to compile a file with gcc?
I'm using kubuntu, and I've written my source code in Kate(the text editor), and I saved it in documents like file1, and now how to compile it from the terminal?
I've tried with the command:

gcc -o file1 file1.c

but it says:
gcc: file1.c: no such file or directory
gcc: no imput files.
What's the problem?
I'm very new in Linux.

didi00> I saved it in documents like file1
Save c source code as *.c (i.e. file1.c) then

gcc file1.c -o file1

Where file1 will be the output.

Nope, the same thing.
Maybe the problem is that before the ~$, there should be defined the path to the documents (like in windows), or it doesn't matter?
my line currently is

unknown@unknown:~$ gcc file1.c -o file1

Help?

Are you running gcc in the same directory where file1.c is?

Yes, now I've checked with pwd and I'm in the documents directory, but still the same thing. I don't know what else is the problem...
I also tried with g++ (with C++ code), only there it says:

The program 'g++' can be found in the following packages:
*g++
*pentium-builder
Try sudo-apt get install <selected package>

It wants to install g++? And when I try to install it it requests some kind of [sudo] password. What's the sudo password. I don't get it.

I get it. sudo is some kind of root password (which in my case I don't know it). I guess I'll re-install kubuntu and I'll see where to set my root password. I think that I didn't set any password when I installed kubuntu. Oh well...

I get it. sudo is some kind of root password (which in my case I don't know it). I guess I'll re-install kubuntu and I'll see where to set my root password. I think that I didn't set any password when I installed kubuntu. Oh well...

Kubuntu doesn't have a root account set up by default. The first user account installed becomes a vicarious root user by entering the command sudo every time it requires root privilege. When you enter sudo, the password is asking for, is your password as a user.

didi00> Try sudo-apt get install <selected package>
The proper command is:

sudo apt-get install g++

goodlord, do NOT reinstall your OS. and you're wasting your time with g++ unless you want to compile C++ (.cpp) files. the simple fact is just that your gcc is obviously not able to see your file1.c, and there has to be a simple explanation.

do this:

first type " pwd " and <enter>
then type " ls -l *.c " and <enter>
then type " gcc -o file1 file1.c " and <enter>

one after another, in teh same window, without doing anything else, and cut and paste the entire results (command and response) here.

goodlord, do NOT reinstall your OS. and you're wasting your time with g++ unless you want to compile C++ (.cpp) files. the simple fact is just that your gcc is obviously not able to see your file1.c, and there has to be a simple explanation.

As a side note, I found somehow insightful the comment of her willingness to re-install the OS just because it is easier to do so than to create a password, given current knowledge. It came to my mind that some GNU/Linux distribution has come a long way.

Yeah I've tried the code above and it says that directory or file *.c doesn't exist.
My kubuntu is in a VirtualBox, does that has to do someting with why it isn't working properly?

Yeah I've tried the code above and it says that directory or file *.c doesn't exist.
My kubuntu is in a VirtualBox, does that has to do someting with why it isn't working properly?

The fact that it is running in a VirtualBox does not have a bearing in your problem.
Then file1.c did not get saved or did not get saved in the current directory you are trying to compile or list, whichever you are referring to by "tried the code above".
Write your source code again and make sure where you save it as a *.c file
Navigate to that directory using a terminal. Then give it the gcc command.

Look. here's your first hint. you do NOT reinstall your OS every time something difficult or confusing occurs.

i mean, seriously, just THINK about that.

now did you write the file1.c to the directory in the first place? what happens when you try to do it again? any warnings?

is your directory write-protected? find a file in that directory and "touch" it. any warnings?

do an "ls -l" command on the directory itself to see the owner and group permissions. use "chown" or "chmod", respectively, to change them if they're not what they should be. use the "su" or "sudo" command if you need to increase your own permission to do so.

.

Yeah sorry, my virtual box was making some problems but I've solved it.
Now about the task: Well first I saved the file as file1.c into the documents directory. But then I just placed it into the home directory because it's easer to manage it from the terminal. So from the terminal I gave the path to the home directory (i checked with pwd), and with ls -l I saw that I have all the necessary permissions. But it just doesn't find the file. Now I need the g++ because I have some project which have to be in c++. But in order to install it it requires some kind of sudo password (which I have no idea what it is). And now I'm stuck, and it bothers me that I can't fix it.

Do you have a current user password? Is this a virtual appliance that you downloaded already made?


didi00> But it just doesn't find the file.
Which doesn't find the file, ls -ll or gcc command?

Yes, yes I made it!
Guys, sorry for the trouble. Now only to install the g++ and everything will be just fine :-)

Everyone thank you so much, everything is solved. The problem was that something was wrong with the virtual box.
Thank you! Now let's see what to do with the errors in the project.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.