Pelles C forum

C language => Beginner questions => Topic started by: BLT on December 15, 2012, 06:55:12 PM

Title: First program, First Project and first failure
Post by: BLT on December 15, 2012, 06:55:12 PM
First day, First Program, First Project and first failure...
My source code...got it off the internet.  I suspect the problem is in the way I have set up my project. 
#include <stdio.h>

int main(void)
{
    printf("hello, world\n");
}
From Build:

Building HelloMain.obj.
C:\Users\Byron\Documents\Pelles C Projects\Hello\HelloMain.c(4): warning #2203: Function 'main' can't be __stdcall, changed to __cdecl.
Building Hello.exe.
POLINK: error: Unresolved external symbol '_WinMain@16'.
POLINK: fatal error: 1 unresolved external(s).
*** Error code: 1 ***
Done.
Where have I gone wrong? 
Thanks,
BLT

Title: Re: First program, First Project and first failure
Post by: CommonTater on December 15, 2012, 07:48:39 PM
Well... At least you've got the firsts out of the way...

There's a couple of things... 
1) Next time create a new project as a *win32 console program* ...  (File -> New -> Project)

If you look in the AddIns section you will find an addin called Workspace Manager (http://forum.pellesc.de/index.php?topic=4616.msg17675#msg17675) I wrote to make project creation a lot simpler.... Read the AddIns FAQ (http://forum.pellesc.de/index.php?topic=4692.msg18087#msg18087) for instructions on how to install addins. In the manager the defaults are set so that you won't get these problems (of course more advanced users can still change them)

2) Write your program like this...

#include <stdio.h>

int _cdecl main (void)
  {
    puts("Hello World!\n\n");
 
    return 0;
  }


There were two problems in your internet code...
A) The calling convention is not specified
B) The operating system expects a returned value that wasn't there.


3) Open the Pelles C help file; Menu -> Help -> Contents then click your way into...
Contents -> Integrated Environment -> POIDE Integrated Environment -> My first project
and give that a read.

But mostly, you should read.... THIS (http://forum.pellesc.de/index.php?topic=4644.msg17797#msg17797)  ... you're not going to learn programming by taking code snippets off the internet and randomly trying them out.  All that does is frustrate.

Welcome to the forums...
Title: Re: First program, First Project and first failure
Post by: BLT on December 16, 2012, 06:19:22 AM
Thank you for taking the time to save my first project.  Your suggestions worked and I am off an runing (slowly).  BLT
Title: Re: First program, First Project and first failure
Post by: CommonTater on December 16, 2012, 10:09:05 PM
No worries ... I still remember my disasters when just starting out.  (and a few more recent ones too :D )