Compile Win32 application without particular dependencies or size bloat - visual-c++

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.
I understood that a good idea would be to dynamically 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.

The "bloat" in this case comes from the use of the STL. So unless you want to refactor your code to get rid of the STL references, you may simply be out of luck.
However, I can suggest using the WDK to build the application. With Windows XP the msvcrt.dll was "knighted" to a system DLL (i.e. always on board, no need for redistributables) and to my knowledge it was also included in Windows 2000 SP4+SRP. So if these minimum requirements are okay for you, use the WDK to build your application and all the "bloat" will be in DLLs that should be on any supported system already.

Related

Unable to add a NIDAQ dll reference to Visual Studio 2012

I have a project which is simulating a graphical environment. What I need in this program is to integrate it with NIDAQ library. Currently I am getting LNK2019 of unresolved external symbol.
LNK2019: unresolved external symbol DAQmxCreateTask referenced in function "public: virtual void __cdecl sofa::component::behaviormodel::MyBehaviorModel::updatePosition(double)" (?updatePosition#MyBehaviorModel#behaviormodel#component#sofa##UEAAXN#Z) C:\Sofa\applications\plugins\NIPlugin\MyBehaviorModel.obj NIPlugin
I have included header file and lib file into my project but as my project is very big and includes lots of library and sub projects it seems that I have to add dynamic library of national instrument to the project as well. However I can not add any new reference to my new code in reference option of my project (there is no browse option abailable). I have also tried adding the path of the .dll file to the additional directory of the project and it doesn't seem to work. but when I add my .dll to additional dependency in Input-->Linker section of the project I get LNK1107 error.
LNK1107: invalid or corrupt file: cannot read at 0x2D0 C:\git\sofa\v15.12\src\lib\win64\nicaiu.dll 1 NIPlugin 1
Do you have any idea how I can make VS read my .dll file?

Visual Studio error "LNK2019: unresolved external symbol"

I get this error in my program. I don't know what that means. can you help me ?
Error 3 error LNK2019: unresolved external symbol
imp_CrtDbgReportW referenced in function "public: class std::_Vector_const_iterator > > & __thiscall
std::_Vector_const_iterator > >::operator+=(int)"
(??Y?$_Vector_const_iterator#V?$_Vector_val#U?$_Simple_types#PAVCommissionEmployee###std###std###std##QAEAAV01#H#Z) C:\Users\Dell\Documents\Visual
Studio 2012\Projects\Base-Commission Employee\Base-Commission
Employee\main.obj
Take a look here please:
The vector class is going to want to tell you that the at() method
failed in debug mode. Thus the reference to CrtDbgReportW(), the
runtime function that displays diagnostics while debugging. When you
link with /MD, you link with the release version of the run-time
library; the one that doesn't tell you anything and is missing the
CrtDbgReportW() export. Thus the linker error.
You can fix this by removing the _DEBUG define from the preprocessor
definitions. If you don't want to lose that valuable tool, tell us
what goes wrong when you link with /MDd.
If you are building a debug version with a static CRT linking (/MT) then just do this:
#define _ITERATOR_DEBUG_LEVEL 0 before#include<vector> or #include<algorithm> and so on...

Unresolved external symbol __Atomic_fetch_add_4 referenced from LIBCMTD.lib

I've just installed the VS2012 beta, and upgraded my VS2010 project, it seems to compile as it should, but when linking, I get the following errors:
1>LIBCMTD.lib(excptptr.obj) : error LNK2019: unresolved external
symbol __Atomic_fetch_add_4 referenced in function "unsigned long
__cdecl std::_Inc_atomic_counter_explicit(unsigned long &,enum std::memory_order)"
(?_Inc_atomic_counter_explicit#std##YAKAAKW4memory_order#1##Z)
1>LIBCMTD.lib(excptptr.obj) : error LNK2019: unresolved external
symbol __Atomic_fetch_sub_4 referenced in function "unsigned long
__cdecl std::_Dec_atomic_counter_explicit(unsigned long &,enum std::memory_order)"
(?_Dec_atomic_counter_explicit#std##YAKAAKW4memory_order#1##Z)
Google has no reference to these error messages, which is surprising.
It looks as if __Atomic_fetch_add_4 should be an intrinsic for the fetchadd4 op-code, but it's not (as far as I can tell), the proper intrinsic is _InterlockedIncrement.
I have no idea what could be causing this. Interestingly it comes from excptptr.obj, and I have C++ exceptions disabled in this project. Enabling them made no difference.
Edit:
I notice when googling that this symbol only appears to be referenced by GNU code. Perhaps MS have updated the STL for VS2012 and pulled in some GNU reference code that hasn't been caught yet; needs to be changed to use the MS intrinsic?
I was having a similar problem with a project of mine which was compiled in VS2010 and getting the unresolved external symbol __Atomic_fetch_add_4 error when compiled in VS2012.
I couldn't figure out why it was happening but after a "clean solution" and "rebuild all" the problem went away. I suspect there where old obj files lying around that caused the problem.

error LNK2019: unresolved external symbol referenced in function main

I'm using a library to generate multimodal optimization functions using VS2010. I include the header file of the library and tell VS where the library directory is; however, there is no *.lib file that comes with it, just source files and header files, so I can't point VS to "Additional Library Directories".
If I just include the header file and run my code it works fine. If I call any method from that library I get the LNK2019 error:
error LNK2019: unresolved external symbol "void __cdecl g_initialize(char *)" (?g_initialize##YAXPEAD#Z) referenced in function main".
I looked around and everyone is saying I should link the library, but I don't have a library file to begin with. What should I do??
Regards,
There're 2 ways if you have implementation of those header files.
1) You can add it to you project.
2) To compile library yourself, and you will get *.lib files. After this add it to you project.
Read documentation of this library how to use it.
Also you can check if there's implementation methods/functions which declared in header files.

LINK ERROR in VC++

I needed help making sense out of the following LNK error which i am getting.
SwitchFunctions error LNK2019: unresolved external symbol "__declspec(dllimport) ??$?8DU?$char_traits#D#std##V?$allocator#D#1##std##YA_NABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##0#PBD#Z" (__imp_??$?8DU?$char_traits#D#std##V?$allocator#D#1##std##YA_NABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##0#PBD#Z) referenced in function "??$find#Viterator#?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##std##PBD#std##YA?AViterator#?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##0#V120#0ABQBD#Z" (??$find#Viterator#?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##std##PBD#std##YA?AViterator#?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##0#V120#0ABQBD#Z)
Have you checked whether you have included all necessary dlls or lib files in your project settings?
Such an error usually indicate that you have used a function which definition is found, but implementation is not. Usually in the case of external libraries, the implementation is inside a dll or a static lib. Failure to provide the dll or the static lib will cause the linking to fail.
Which version of Visual Studio are you using? This might be relevant for VS2005:
Link error using a CString derived class from a DLL

Resources