Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting rid of C Run-Time Library. How?

Posted on 1998-03-25
11
Medium Priority
?
798 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 400 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

783 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