Getting rid of C Run-Time Library. How?

Hi:

I am developing a DLL for system hook, so I'm trying to minimize its size. I am using just C++/Win32, no MFC (IDE is Visual C++ 5.0).

Is it possible to link the DLL so that the C Run-Time Library code will not be loaded when my DLL gets loaded?

I am aware of linking with DLL form of CRTL, but in this case the whole CRTL is also loaded which I want to prevent.

Is it possible to get rid of CRTL code?

Regards,
Asker.
askerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fochtCommented:
Get rid of the CRT:
- In the linker options there is an "ignore libraries" edit box. Enter Libcmt.lib into it, and build. You get several unresolved externals. This list is everything that you are using from the CRT. Look for things that you think may be pulling in the startup code and remove them if you can.

Another method to determine if you need the startup code:
- Don't ignore Libcmt.lib, but turn on the verbose flag for the linker. From this, you can see what is triggering CRT startup code to get pulled in.

You can use some C-Runtime functions without requiring the CRT startup code. Examples include the mem* functions. Other functions require the CRT startup code. CRT string comparisons for example require the startup code as the CRT initializes some tables used for comparing. Global objects that have constructors also require the startup code. In Visual C++ 5.0, statically linking the startup code adds about 25K to your image(In Visual C++ 4.2 it is about 20K).
If you use functions or code in your project that require the use of the C-Runtime library startup code, you may experience LNK2001 - unresolved external errors when you try to build the release version of your project.
 
0
askerAuthor Commented:
To Focht:

Here are the references I've got:

error LNK2001: unresolved external symbol __chkstk
error LNK2001: unresolved external symbol _atexit
error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" (??3@YAXPAX@Z)
error LNK2001: unresolved external symbol __fltused
error LNK2001: unresolved external symbol __ftol
error LNK2001: unresolved external symbol ___CxxFrameHandler
error LNK2001: unresolved external symbol __except_list
error LNK2001: unresolved external symbol __DllMainCRTStartup@12

How can this help me to get rid of CRTL? I am even ready to rewrite my DLL on a plain C (instead C++).

Regards,
Asker.
0
Tommy HuiEngineerCommented:
In order to get rid of the runtime library, you have to stop using it. That means you cannot make any calls to the runtime library, such as delete. You must also turn off exception handling. Take a look at an article by Matt Pietrek on www.microsoft.com/msj and search for tinylib for a runtime library replacement.


0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

askerAuthor Commented:
To Thui:

I did not use any of those unresolved externals in my DLL (there are no explicit calls to delete also). The comment for DllMainCRTStartup in CRT source code tells that it does (among other things) classes' constructor calling. Does it mean that it is impossible to get rid of CRTL in C++ completely?
Would it be better in C? Or it is enough to stop using classes? Or the problem is in something else?

I could not find the article you mentioned on www.microsoft.com/msj.

Regards,
Asker.

0
Tommy HuiEngineerCommented:
Yes, you cannot use C++ without the runtime library. You will have to use C for that. Then on top of that, you cannot make any calls into the runtime library too.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
askerAuthor Commented:
To Thui:

Thank you for the answer. I'm going to convert all my sources to C.

:-(

Regards,
Asker.
0
askerAuthor Commented:
To Thui:

After converting my DLL to C, I still have these:

error LNK2001: unresolved external symbol __chkstk
error LNK2001: unresolved external symbol __fltused
error LNK2001: unresolved external symbol __ftol

I found out chkstk.obj in LIB directory, linked it and __chkstk disappeared.
But what should I do with fltused and ftol?

Regards,
Asker.

0
Tommy HuiEngineerCommented:
Are you using floating points?

0
askerAuthor Commented:
To Thui:

Yes, I am using some calculations with float values, than casting the result to int. Does that mean I have to link with CRTL? Or there is some magic file only_fp_routines.obj (like chkstk.obj)?

Regards,
Asker.

0
Tommy HuiEngineerCommented:
Try using doubles instead of floats and see what happens.


0
askerAuthor Commented:
To Thui:

I have tried - nothing changed:-( As far as I understand, _ftol is the routine which converts a float/double result to an integer value (ftol stands for float-to-long?).

_fltused (stands for float-used?) is a magic constant, defined in CRTL, _ftol I was unable to locate at all.

I do need to perform some simple float calculations - taking a fraction of an integer value, while the value of the fraction is calculated as a ratio between the two other integer values, looks like:

int a, b= 10, c = 12, d = 20;

a = (int)(float)(( ((float)b / (float)c) * (float)d));

Any ideas? Maybe some home-made FP library exists? It shouldn't be fast and very exact.

Regards,
Asker.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.