Tiny C startup module to build smaller C executables

Started by Vortex, December 25, 2004, 02:36:17 PM

Previous topic - Next topic

rvalois

Vortex,
--------------------
Is there anyone using Borland C++ 5.5? Maybe, I can try creating a startup module for this compiler.
--------------------
I maybe late but if the offer still valid, I would like to have it.
Thank you,
RValois.

Vortex

Hi rvalois,

Welcome to the forum.

Here is an example package for you targetting both GUI and console applications.

Notice that I used the OMF linker from Digital Mars to create smaller executables compared to Borland's ilink32.exe

To get the Digital Mars C/C++ compiler package and tools :

http://www.digitalmars.com

[attachment deleted by admin]

rvalois

Hi Vortex,
-------------
Welcome to the forum.
-------------
Thank you but I have been here before. For some reason I had to re-register.


Unfortunately no luck compiling my code. Your example compiles fine.
This is what I got,
--------------------------------------------------------------------
G:\rvEd>f:\dm\bin\link -NOD -ENTRY:_WinMainCRTStartup -SU:WINDOWS -FIXE start.ob
j rved.obj,rved.exe,,kernel32.lib user32.lib comctl32.lib msvcrt.lib,rved.res
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

OPTLINK : Warning 23: No Stack
OPTLINK : Warning 174: 32-bit Segments Inappropriate for 16-bit Segmented output

start.obj(start)
Error 116: NEAR call to IMPORT at Relative 00003H  from
Segment _TEXT
FRAME  = Frame of Group FLAT 0000
TARGET = External Symbol GetModuleHandleA 00000H
FIXUPP Type = 32-bit Conditional JMP

G:\rvEd>
---------------------------------------------------------------------
This is what I'm trying to compile:http://www.rvalois.com.br/downloads/rvEd.zip
It is a skeleton dialog based windows application.

Another thing, What is necessary to compile VC and BCC DLLs ?

Sorry to bother you...

Thank you.
RValois.

Vortex

Hi RValois,

Here is the rebuilded project with the final executable sized 7Kb.
Run the batch file buildlib.bat to create the import libraries before building the project.

To build small DLLs , have a look at this thread:

Small DLLs without C startup code

http://www.masmforum.com/simple/index.php?topic=1121.0

[attachment deleted by admin]

rvalois

Duh, one comma.
Thank you very much.
Regards,
RValois.

Vortex

Here is a new library coded with POASM for Pelles C. The library should work also with VC++

http://vortex.masmcode.com/files/Wcrt0_5.zip

Vortex

An example with MS VC++ Toolkit 2003

[attachment deleted by admin]

Vortex

The command line parser could not handle tab characters separating command line arguments - bug fixed

http://www.vortex.masmcode.com/files/Wcrt0_6.zip

Ehtyar

Hi all.
Firstly let me apologize for posting this here, as opposed to creating a new thread, but i'm tired of seeing retards running around reminding everyone that this is not a C board. (Hutch, any chance of a C forum? ;))

Anyway, a friend of mine has been trying to teach himself C++ (with no previous programming experience mind, so you can imagine the kind of questions i get ;)). So he has been compiling small examples programs and sending them to me for a while, and I've been making them more standards compliant, and optimizing (if that's possible in cpp) etc.
The last program he sent me was a ~30 line cli program, consisting of a single line prompt, and based on the next typed character, it would reply with one of two answers, then exit.
After applying all the optimizations i could find in dev-cpp (using MinGW) i had an exe that was....wait for it.....FOUR HUNDRED AND SIXTY-THREE KILOBYTES. Needless to say i am less than impressed with this.
To get to the point, i wish to know if:
1) Is this within range of the size of an executable produced by a c++ compiler and
2) Can anyone suggest to me ways of shrinking it's size, or suggest a better compiler.

I have tried to compile said program in vc, but i end up with a blight of errors, which can be found in Errors.txt in the attached zip file none of which seem to make any sense to me. I am using the command line compiler that accompanies visual c express 2005, and the includes from the windows sdk 2003.
Any advice on this topic would be appreciated, as i simply do not find half a megabyte for a program of this caliber acceptable.
The attachment contains the source and compiled executable i refer to above.

Thanks, Ehtyar.

[attachment deleted by admin]

hutch--

I just built your code using the older vctoolkit with this batch file. It builds at 73k.


@echo off

set pth=h:\vctoolkit\
set include=%pth%include\

if exist masm.exe del masm.exe
if exist masm.obj del masm.obj

:: speed
%pth%bin\cl /c /G7 /O2 /Ot /GA /EHsc masm.cpp

:: size
:: %pth%bin\cl /c /O1 /Os /EHsc masm.cpp

%pth%bin\Link /SUBSYSTEM:CONSOLE /libpath:%pth%lib masm.obj

dir masm.*

pause
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Vortex

Ehtyar,

A small note, my startup module is designed to be used with C code not C++

While proceesing C++ code, the compiler inserts some additional subroutines handling expections, streams, memory management etc. Dealing with all of them in C++ is more compicated compared to the C environment.

Ehtyar

Yes Vortex, i am aware, i never tried to link your custom libs with the cpp program for that reason.

Hutch, i don't know what you did to make that work, but i have been trying for the past hour myself, and i still have errors from link.exe from the vctoolkit with ur bat file. Basically i have got it down to 6 unresolved externals:


masm.obj : error LNK2019: unresolved external symbol ___CxxFrameHandler3 referen
ced in function __ehhandler$??0?$ctype@D@std@@QAE@PBF_NI@Z
masm.obj : error LNK2019: unresolved external symbol __EH_epilog3 referenced in
function "public: __thiscall std::ctype<char>::ctype<char>(short const *,bool,un
signed int)" (??0?$ctype@D@std@@QAE@PBF_NI@Z)
masm.obj : error LNK2019: unresolved external symbol __EH_prolog3 referenced in
function "public: __thiscall std::ctype<char>::ctype<char>(short const *,bool,un
signed int)" (??0?$ctype@D@std@@QAE@PBF_NI@Z)
masm.obj : error LNK2019: unresolved external symbol __EH_prolog3_catch referenc
ed in function "public: bool __thiscall std::basic_istream<char,struct std::char
_traits<char> >::_Ipfx(bool)" (?_Ipfx@?$basic_istream@DU?$char_traits@D@std@@@st
d@@QAE_N_N@Z)
masm.obj : error LNK2019: unresolved external symbol __EH_epilog3_GS referenced
in function _main
masm.obj : error LNK2019: unresolved external symbol __EH_prolog3_GS referenced
in function _main
masm.exe : fatal error LNK1120: 6 unresolved externals


No matter what i link against (libcp, libcpd, libcpmt etc), i get all 6 of these, which are apparently error handling functions. Why i am getting them and not yourself i cannot say, but if you have any ideas...I'd be very appreciative.

Thanks, Ehtyar.

sinsi

Light travels faster than sound, that's why some people seem bright until you hear them.

Ehtyar

I believe it was yesterday that someone posted a C question in the workshop, and explicitly asked not to be reminded that this was an assembler board. The first post contained precisely such a reminder. I'd personally call that a little retarded, if not downright rude.

Ehtyar.

sinsi

Well, maybe the  :wink should have been a  :bdg or  :lol - or maybe we need a :sarcastic
(that was my reading of it...)
Light travels faster than sound, that's why some people seem bright until you hear them.