Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm an absolute beginner at writing programs in C, and I'm having difficulty compiling a simple program. Here's my code:

/* This code is a .c file that prints out the words hello, world. */

# include <stdio.h>
int main()
{
    printf("Hello World! \n");
}

Here's the error I get when compiling:

Ubuntu:~/Desktop/cFiles$ gcc -Wall hello.c -o hello.out -lmls 
hello.c:5:1: warning: return type defaults to ‘int’ [-Wreturn-type]
hello.c: In function ‘main’:
hello.c:7:3: warning: implicit declaration of function ‘print’ [-Wimplicit-function-declaration]
hello.c:8:1: warning: control reaches end of non-void function [-Wreturn-type] /usr/bin/ld: cannot find -lmls
collect2: ld returned 1 exit status

I'm not sure what I'm doing wrong. Can anyone help?

share|improve this question
    
I have corrected your code formatting for you. –  saji89 Jan 19 '13 at 5:50
    
Welcome to Ask Ubuntu! Please remember to format your post properly. This assures you have a high quality questions, which will receive the high quality answers it deserves! Thanks and good luck! –  Mochan Jan 19 '13 at 6:07
    
The code is fine, your compile command is the problem, just gcc hello.c will produce no errors, and a working a.out executable. –  ubfan1 Aug 27 '13 at 17:00

2 Answers 2

Seems like you have an unwanted space between # and include:

# include <stdio.h>   

Make that

#include <stdio.h> 

and compile.
That should solve it for you.

share|improve this answer
    
The space is not the problem, it compiles fine with it, and removing it does not solve the problem. –  ubfan1 Aug 27 '13 at 16:59

The reason why your code is not compiling is because of the -lmls at the end of the line. This is looking for a library called "mls". (Perhaps you are going to be coding with libmls for Maximum Length Sequence later?)

Compile with

Ubuntu:~/Desktop/cFiles$ gcc -Wall hello.c -o hello.out

The rest of your output is warnings. Most of them do not match the code which you provided. To remove the compiler warnings:

  1. You have already fixed "return type defaults to ‘int’" in the code that you provided (by adding int as the return type of main).
  2. You have already fixed the "implicit declaration of function ‘print’" by adding the #include.
  3. To remove "control reaches end of non-void function" warning add return(0); to the end of the main function.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.