NO

Author Topic: Could something like "smart linking" be implemented ?  (Read 2279 times)

impopia

  • Guest
Could something like "smart linking" be implemented ?
« on: November 11, 2010, 08:31:52 am »
Hello,
I wrote some general functions and put them in a C file which I used then for developing a certain application. So the C file was compiled in the context of that application. But the application does not use ALL the functions from that C file. Still, looking through the dependencies of the generated executable (with Multithreaded DLL) I noticed that the exe needs some functions from the RTL that are never called. For example, in that C file, I implemented a function "long long IsInt64(wchar_t* str,long long* val)", which makes use of RTL function wcstoll(). I don't use wcstoll() anywhere in the program but IsInt64(), which is not called anywhere. But the dependencies of the exe show that it uses wcstoll(), which means that the function IsUInt64() is compiled and linked within the exe, even if it is never called. Could the linker detect that some function compiled in the .obj is not called and not include it in the executable ? This feature exists in some IDEs (Delphi, Virtual Pascal etc.) and is very useful for reducing the size of the executable.
Thank you

CommonTater

  • Guest
Re: Could something like "smart linking" be implemented ?
« Reply #1 on: November 11, 2010, 12:32:47 pm »
My solution for this is to create a static library.
Pleace each function call on it's own .c source page
Create a common library header with all calls listed.
Compile.

You now have a library with multiple objects included.

When you include the header file (.h) in your project and link with your library the linker will include only the objects it needs.

« Last Edit: November 11, 2010, 12:34:47 pm by CommonTater »