Pelles C forum

C language => Beginner questions => Topic started by: Prodelos on May 21, 2012, 12:32:11 AM

Title: CRT Startup Function and Dependencies
Post by: Prodelos on May 21, 2012, 12:32:11 AM
Maybe this is answered elsewhere, but I haven't been able to locate it.

I need to write my own startup functions. In MSVC 6, the startup function is called mainCRTStartup() for console apps, WinMainCRTStartup() for Windows programs, and _DllMainCRTStartup() for DLL's.

I need to know what to call the startup functions in Pelles C,  and what the Pelles C Runtime Library requires in the way of initialization in the startup to function properly.

Any information, or links to information regarding this would be greatly appreciated.

Thanks!
Title: Re: CRT Startup Function and Dependencies
Post by: CommonTater on May 21, 2012, 02:14:50 AM
Take a look in the help file... it's all detailed in the appendix under "Program Startup".

With Pelles C... "When in doubt press F1 on your keyboard"

Title: Re: CRT Startup Function and Dependencies
Post by: Vortex on May 21, 2012, 07:08:50 PM
Hi Prodelos,

You can check this thread :

http://forum.pellesc.de/index.php?topic=88.0
Title: Re: CRT Startup Function and Dependencies
Post by: Prodelos on May 24, 2012, 07:17:39 AM
Thanks Vortex. That was very helpful.

I get the  following error whenever I try to create the MSVCRT.LIB to be able to compile your Wcrt0 projects:

C:\Program Files\PellesC\Bin>polink c:\windows\system32\msvcrt.dll /OUT:d:\PellesC\msvcrt.lib
POLINK: fatal error: Invalid machine type in object 'c:\windows\system32\msvcrt.dll'.


Whenever I add windows.h to a project and 'build' from the IDE, I get this error:

"C:\Program Files\PellesC\Include\Win\winnt.h(558): fatal error #1014: #error: "No target architecture"."


The Project Options | Compiler tab has X86 selected. I've even tried setting the _M_IA86=600 preprocessor symbol, to no avail.

I'm sure I have something set wrong somewhere, but I have no clue what it could be.

Any ideas?
Title: Re: CRT Startup Function and Dependencies
Post by: TimoVJL on May 24, 2012, 01:14:22 PM
Wrong program, try this:
Code: [Select]
polib.exe c:\windows\system32\msvcrt.dll /OUT:d:\PellesC\msvcrt.lib
Title: Re: CRT Startup Function and Dependencies
Post by: AlexN on May 24, 2012, 03:41:44 PM
Wrong program, try this:
Code: [Select]
polib.exe c:\windows\system32\msvcrt.dll /OUT:d:\PellesC\msvcrt.lib
Hi Timo

I know this line (or similar) exist many times in this forum. Perhaps it would be a good idea, if you write a little chapter in the Wiki of Pelles C how to do this with some knowledge around. :)
Title: Re: CRT Startup Function and Dependencies
Post by: Vortex on May 24, 2012, 07:35:10 PM
Hi Prodelos,

You can create the import library with def2lib.exe  The attachment contains an example. Don't forget to run BuildLib.bat before building the project.

def2lib needs only a module definition file to create an import library :

Code: [Select]
def2lib msvcrt.def
Title: Re: CRT Startup Function and Dependencies
Post by: Prodelos on May 24, 2012, 11:48:35 PM
Thanks guys!

I feel like such a 'newbie' now. :-[ POLIB to make a LIB, not POLINK. DUH! Learning how to use new tools sux! :)

I was able to create msvcrt.lib/.def using tools from my other compilers, no problem. I still can't figure out why PellecC spews errors about machine target/archetecture whenever I add windows.h. I reinstalled it to make sure nothing was corrupt, but the errors persist.

Also, PellesC doesn't seem to merge duplicate strings, which made my 86K app grow to 141K.  :o

I never had problems like this with Turbo C 2.0. Maybe it's time to retire.  ;)

TGIF!
Title: Re: CRT Startup Function and Dependencies
Post by: CommonTater on May 25, 2012, 04:53:54 AM
First off... Turbo C is an antique, deserving of a museum display nest to the triceritops and steigosaurus.  It is non-standard in all kinds of ways, 2.0 produces 16 bit code that won't even run on a 64 bit operating system and it allows a great number of non-standard behaviours.

One reason not to merge duplicate strings is that you end up with crosslinked variables giving rise to magic values... changing one changes both.

If you have string constants you are using in multiple places, you can #define them like this...
Code: [Select]
#define FILE_PATH "C:\\testfiles\\test7\\fred.xyz"
#define PAGE_TITLE "This Title Appears On All Pages"
and refer to them by name as often as you like.

This also has the advantage that if you need to change it for some reason... changing the #define will effectively change it everywhere it's referenced.

 
Title: Re: CRT Startup Function and Dependencies
Post by: TimoVJL on May 25, 2012, 05:31:28 AM
Quote
I still can't figure out why PellecC spews errors about machine target/archetecture whenever I add windows.h.
Remember to set Project -> Project options -> Compiler -> Enable Microsoft extensions
or -Ze in compiler commandline when you use Windows.h headers.
Title: Re: CRT Startup Function and Dependencies
Post by: Prodelos on June 02, 2012, 09:11:40 AM
timovjl... you're a genius!

The -Ze switch fixed it. Thank you so much for your patience and your valuable assistance.
Title: Re: CRT Startup Function and Dependencies
Post by: Vortex on June 02, 2012, 10:43:36 AM
Hi Prodelos,

FYI, you can turn-off completely the CRT startup module if you wish.