Jump to content

GCC Compiler Help


Recommended Posts

Few days ago, i have installed Mandriva Linux 2007 on computer. I am a newbie to computer and programming also. Is there any methods to check the software isntalled at my computer ? Besides that, i also have another problem which is GCC compiler problem. When i typed gcc /home/nicholas_tse/C/Welcome.c -o Welcome.c , the konsole return an error message which is no newline at end of the file. I don"t know what happen to my program but i can sure that my program is very simple.

 

Program as below:

 

#include<stdio.h>

main()

{
printf("Welcome to the Linux World");
}

 

 

Your help will greatly appreciated by me any others who have same problem.

 

Thank for your help.

 

 

[moved from Everything Linux by spinynorman]

Link to comment
Share on other sites

I have try your solution but seems the terminal show much more error than before.

 

After modification, my code is as below:

 

#include<stdio.h>

main()

{

printf("Welcome to the Linux World");

}

 

My Error message as below:

 

Welcome.c:10:850: Warning: null character ignored

 

There are many much more error messages that i not showing here but it is almost similiar with the one i post here. The others error messages is no newline at the ned of file.

 

I run out of idea how to fix it. I bag you please help me. I in trouble.

 

 

Your help is greatly appreciated by me.

 

Thanks for your help.

Link to comment
Share on other sites

You should compile c programs with the following syntax

gcc source_file

It will compile source_file and create a binary file called a.out. If you want the output file to have a different name you use the -o switch just like you did.

gcc source_file -o output_file

Source_file and output_file must have a different name. In your command line they have the same name:

gcc /home/nicholas_tse/C/Welcome.c -o Welcome.c
Change the output file name from Welcome.c to something else. Like plain Welcome.

One more thing

#include<stdio.h>

Leave a space after include

#include <stdio.h>

Link to comment
Share on other sites

You usually name output files with the .out extension:

gcc /home/nicholas_tse/C/Welcome.c -o Welcome.out

While this isn't necessary, it's pretty standard and makes identifying the file easier.

 

two other pointers:

  1. Always return something from a function, even if it's zero.
  2. If a function isn't going to be passed any variables, declare it void.

With these two pointers in mind, we get:

#include <stdio.h>

 

main(void)

{

 

printf("Welcome to the Linux World");

return 0;

 

}

differences are marked in red.
Link to comment
Share on other sites

The reason for the new line is because it's part of the ANSI standards. By putting an extra line at the end, you're making your program ANSI standards compliant.

 

This is a good thing ;)

 

Check to see if the program was actually compiled. By default, warnings will be printed out but the program will still compile. If this is not occurring, then we need to look for the setting which causes gcc to run with warnings as errors. Note that, by default, you will not receive any messages that it was successfully compiled from gcc.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...