Build Win32 application without particular dependencies or size bloat
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Build Win32 application without particular dependencies or size bloat

  1. #1
    Join Date
    Feb 2011
    Posts
    13

    Question 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

  2. #2
    Join Date
    Feb 2011
    Posts
    13

    Re: Build Win32 application without particular dependencies or size bloat

    No ideas anyone?

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,288

    Re: Build Win32 application without particular dependencies or size bloat

    1. Have a look at this thread.
    2. bad_cast Exception
    Victor Nijegorodov

  4. #4
    Join Date
    Aug 2008
    Posts
    902

    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.

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,927

    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 02:47 PM.
    Best regards,
    Igor

  6. #6
    Join Date
    Feb 2011
    Posts
    13

    Re: Build Win32 application without particular dependencies or size bloat

    Thanks for your replies guys, I'll keep experimenting...

    Quote Originally Posted by Igor Vartanov View Post
    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 08:05 AM.

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,927

    Re: Build Win32 application without particular dependencies or size bloat

    Quote 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:
    Quote 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 10:23 AM.
    Best regards,
    Igor

  8. #8
    Join Date
    Feb 2011
    Posts
    13

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center