Solved

Getting rid of C Run-Time Library. How?

Posted on 1998-03-25
11
786 Views
Last Modified: 2011-09-20
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.
0
Comment
Question by:asker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 1

Expert Comment

by:focht
ID: 1183780
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
 

Author Comment

by:asker
ID: 1183781
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
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1183782
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:asker
ID: 1183783
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
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 total points
ID: 1183784
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
 

Author Comment

by:asker
ID: 1183785
To Thui:

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

:-(

Regards,
Asker.
0
 

Author Comment

by:asker
ID: 1183786
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
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1183787
Are you using floating points?

0
 

Author Comment

by:asker
ID: 1183788
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
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1183789
Try using doubles instead of floats and see what happens.


0
 

Author Comment

by:asker
ID: 1183790
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question