-
February 21st, 2011, 05:19 PM
#1
Build Win32 application without particular dependencies or size bloat
Hello everybody,
I am trying to build a small Win32 application using Visual C++ 2008, but I want it to run on any modern Windows machine without having to ship additional libraries and without having to bloat its size linking them statically.
I have read many articles around the internet about this topic, like this one: http://kobyk.wordpress.com/2007/07/2...visual-c-2005/
I understood that a good idea would be to dinamically link my project to msvcrt.dll which can be found in any modern Windows being a system dll, on the contrary of newer runtimes like msvcr90 which change with each new Visual Studio version.
So in the linker options,
I ignored all default libraries (/NODEFAULTLIB)
I added msvcrt.lib to the additional dependencies
But I get a bunch of "unresolved external symbol" errors when compiling, like these ones:
1>StubLib.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall std::bad_cast::~bad_cast(void)" (??1bad_cast@std@@UAE@XZ)
1>StubLib.obj : error LNK2001: unresolved external symbol "public: __thiscall std::bad_cast::bad_cast(char const *)" (??0bad_cast@std@@QAE@PBD@Z)
1>StubLib.obj : error LNK2001: unresolved external symbol "public: __thiscall std::bad_cast::bad_cast(class std::bad_cast const &)" (??0bad_cast@std@@QAE@ABV01@@Z)
1>StubLib.obj : error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB)
I also tried to use some alternative C++ runtime libraries designed to reduce size bloat like Minicrt, WCRT etc. but in any case I get "unresolved external symbol" errors.
Any help is greatly appreciated,
thanks in advance
-
February 24th, 2011, 09:31 AM
#2
Re: Build Win32 application without particular dependencies or size bloat
No ideas anyone?
-
February 24th, 2011, 09:43 AM
#3
Re: Build Win32 application without particular dependencies or size bloat
1. Have a look at this thread.
2. bad_cast Exception
Victor Nijegorodov
-
February 24th, 2011, 04:19 PM
#4
Re: Build Win32 application without particular dependencies or size bloat
I'm not certain but I think the linking issue is due to the fact that you are using the Visual Studio 2008 Standard Library in your code, but trying to link against the DLL used in older versions. There are clearly differences in the library. You could solve this by using an older version of Visual Studio to do the compiling, or maybe by using an older version of the Standard Library.
-
February 26th, 2011, 03:45 PM
#5
Re: Build Win32 application without particular dependencies or size bloat
I am trying to build a small Win32 application using Visual C++ 2008, but I want it to run on any modern Windows machine without having to ship additional libraries and without having to bloat its size linking them statically.
VS 2008 is not the best choice then.
I understood that a good idea would be to dinamically link my project to msvcrt.dll which can be found in any modern Windows being a system dll, on the contrary of newer runtimes like msvcr90 which change with each new Visual Studio version.
A good idea would be to avoid using standard C/C++ runtime at all.
Anyway, the errors you show have nothing to do with linking to msvcrt.dll as the latter contains C runtime but not STL (which actually resides in msvcp*.dll).
Last edited by Igor Vartanov; February 26th, 2011 at 03:47 PM.
Best regards,
Igor
-
March 11th, 2011, 08:49 AM
#6
Re: Build Win32 application without particular dependencies or size bloat
Thanks for your replies guys, I'll keep experimenting...
Originally Posted by Igor Vartanov
VS 2008 is not the best choice then.
A good idea would be to avoid using standard C/C++ runtime at all.
Anyway, the errors you show have nothing to do with linking to msvcrt.dll as the latter contains C runtime but not STL (which actually resides in msvcp*.dll).
What is the best choice then? I compiled (release mode) same project in
Visual C++ 2008: size 115 KB;
Visual C++ 6: size 172 KB!
I thought that compiling using older version would lead to smaller size, it iseems this is not the case!
I'm always trying to avoiding use C++ runtime functions and use Windows APIs instead, when possible.
What do you mean that the errors have nothing to do with linking to msvcrt.dll? I didn't understand well this part.
Regards
Last edited by Viotto; March 11th, 2011 at 09:05 AM.
-
March 11th, 2011, 11:21 AM
#7
Re: Build Win32 application without particular dependencies or size bloat
Originally Posted by Viotto
What do you mean that the errors have nothing to do with linking to msvcrt.dll? I didn't understand well this part.
This is what you wrote:
Originally Posted by Viotto
I added msvcrt.lib to the additional dependencies
But I get a bunch of "unresolved external symbol" errors when compiling, like these ones:
1>StubLib.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall std::bad_cast::~bad_cast(void)" (??1bad_cast@std@@UAE@XZ)
1>StubLib.obj : error LNK2001: unresolved external symbol "public: __thiscall std::bad_cast::bad_cast(char const *)" (??0bad_cast@std@@QAE@PBD@Z)
1>StubLib.obj : error LNK2001: unresolved external symbol "public: __thiscall std::bad_cast::bad_cast(class std::bad_cast const &)" (??0bad_cast@std@@QAE@ABV01@@Z)
1>StubLib.obj : error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF@std@@3JB)
The namespace std is STL library. The STL implementation resides in msvcp*.dll but not msvcrt.dll. No surprise the symbols cannot be resolved, as you miss to include the required lib.
Last edited by Igor Vartanov; March 11th, 2011 at 11:23 AM.
Best regards,
Igor
-
March 11th, 2011, 11:39 AM
#8
Re: Build Win32 application without particular dependencies or size bloat
Ah yes, now I understand, thanks :-)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|