title: How to properly link and include libraries?
body: <p>It's the first time I prepare a pretty complex application in C++ (Visual Studio 2010) and I have serious linking problems which gave me a solid headache (maybe cause I've never got what it's all about).</p>
  
  <p>I'm implementing fluid flow simulator using:
  - NVidia PhysX (SDK 3.2.3)
  - glew (1.9)
  - freeglut (2.8.1)
  - gltools library (addon to OpenGL Superbible 5th)</p>
  
  <p>I have no idea how to properly set Release/Debug and MD/MDd/MT/MTd options to get everything working.</p>
  
  <ul>
  <li>I can compile freeglut with MD/MDd/MT/MTd and also with Relese/Release-Static/Debug/Debug-Static solution configurations</li>
  <li>I can compile gltools with MD/MDd/MT/MTd and also with Relese/Debug</li>
  <li>PhysX is precompiled lib and dll files (I have no idea what options were used in compiling process)</li>
  <li>Same is about glew</li>
  </ul>
  
  <p>I tried a lot of configurations but all the time i get compilation errors like</p>
  
  <pre><code>defaultlib 'MSVCRT' conflicts with use of other libs;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>fatal error C1189: #error :  Exactly one of NDEBUG and _DEBUG needs to be defined by preprocessor
  </code></pre>
  
  <p>I read that It's all about setting mentioned configuration in a right way, but I actually can't do it.</p>
  
  <p>What should be right configuration (and why?) and which libraries should I link with lib files and which with dll? Im kind of newbie with C++ so please try to explain it clearly.</p>
  
  <p>That's 'include part' of my application (It was pretty similar and it worked before i accidentally broke it):</p>
  
  <pre><code>//#define WIN32
  #include &lt;windows.h&gt;        // Must have for Windows platform builds
  
  #include &lt;GLTools.h&gt;
  #include &lt;GLFrustum.h&gt;
  #include &lt;GLBatch.h&gt;
  #include &lt;GLMatrixStack.h&gt;
  #include &lt;GLShaderManager.h&gt;
  #include &lt;GLGeometryTransform.h&gt;
  #include &lt;StopWatch.h&gt;
  
  //#define GLEW_STATIC
  #include &lt;GL\glew.h&gt;            // OpenGL Extension "autoloader"
  //#define FREEGLUT_STATIC
  #include &lt;GL\freeglut.h&gt;
  //#include &lt;GL\gl.h&gt;            // Microsoft OpenGL headers (version 1.1 by themselves)
  
  #include &lt;math.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  #include &lt;PxPhysicsAPI.h&gt; 
  #include &lt;extensions/PxExtensionsAPI.h&gt; 
  #include &lt;extensions/PxDefaultErrorCallback.h&gt;
  #include &lt;extensions/PxDefaultAllocator.h&gt; 
  #include &lt;extensions/PxDefaultSimulationFilterShader.h&gt;
  #include &lt;extensions/PxDefaultCpuDispatcher.h&gt;
  #include &lt;extensions/PxShapeExt.h&gt;
  #include &lt;foundation/PxMat33.h&gt; 
  
  #include &lt;pxtask/PxCudaContextManager.h&gt;
  #include &lt;physxprofilesdk\PxProfileZoneManager.h&gt;
  
  #include &lt;extensions/PxSimpleFactory.h&gt;
  
  #pragma comment(lib, "PhysX3_x86.lib")
  #pragma comment(lib, "PhysX3Common_x86.lib") 
  #pragma comment(lib, "PxTask.lib")
  #pragma comment(lib, "PhysX3Extensions.lib")
  #pragma comment(lib, "PhysXProfileSDK")
  </code></pre>
  
  <p>I'm not sure if last lanes are necessary if everything is set well (found it somewhere in google and it worked).</p>
  
  <p>If you need more information or more detailed error log with some configuration, just tell me and I'll provide it.</p>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT:</p>
  
  <p>Debug /MDd</p>
  
  <pre><code>PxTask.lib(CudaWrapper.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtDefaultSimulationFilterShader.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtSimpleFactory.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtDefaultCpuDispatcher.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtDefaultErrorCallback.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtRigidBodyExt.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtCpuWorkerThread.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysXProfileSDK.lib(PxProfileEventImpl.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
  1&gt;main.obj : error LNK2019: unresolved external symbol _glewInit@0 referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
  1&gt;C:\dev\SPHFluids\SPHFluids\Debug\SPHFluids.exe : fatal error LNK1120: 1 unresolved externals
  1&gt;
  1&gt;Build FAILED.
  </code></pre>
  
  <p>Release /MDd</p>
  
  <pre><code>PxTask.lib(CudaWrapper.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtDefaultSimulationFilterShader.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtDefaultErrorCallback.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtDefaultCpuDispatcher.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtSimpleFactory.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtCpuWorkerThread.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtRigidBodyExt.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysXProfileSDK.lib(PxProfileEventImpl.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
  1&gt;LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
  1&gt;main.obj : error LNK2001: unresolved external symbol _glewInit@0
  1&gt;C:\dev\SPHFluids\SPHFluids\Release\SPHFluids.exe : fatal error LNK1120: 1 unresolved externals
  1&gt;
  1&gt;Build FAILED.
  </code></pre>
  
  <p>Release /MTd</p>
  
  <pre><code>PxTask.lib(CudaWrapper.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtDefaultSimulationFilterShader.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtDefaultErrorCallback.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtDefaultCpuDispatcher.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtSimpleFactory.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtCpuWorkerThread.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysX3Extensions.lib(ExtRigidBodyExt.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;PhysXProfileSDK.lib(PxProfileEventImpl.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
  1&gt;MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fclose already defined in LIBCMTD.lib(fclose.obj)
  1&gt;MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fwrite already defined in LIBCMTD.lib(fwrite.obj)
  1&gt;MSVCRT.lib(MSVCR100.dll) : error LNK2005: _free already defined in LIBCMTD.lib(dbgfree.obj)
  1&gt;MSVCRT.lib(MSVCR100.dll) : error LNK2005: _malloc already defined in LIBCMTD.lib(dbgmalloc.obj)
  1&gt;MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fgetc already defined in LIBCMTD.lib(fgetc.obj)
  1&gt;MSVCRT.lib(MSVCR100.dll) : error LNK2005: _fprintf already defined in LIBCMTD.lib(fprintf.obj)
  1&gt;MSVCRT.lib(MSVCR100.dll) : error LNK2005: ___iob_func already defined in LIBCMTD.lib(_file.obj)
  1&gt;MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &amp;)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
  1&gt;MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info &amp; __thiscall type_info::operator=(class type_info const &amp;)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
  1&gt;LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
  1&gt;libcpmtd.lib(xdebug.obj) : warning LNK4098: defaultlib 'libcmt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
  1&gt;main.obj : error LNK2001: unresolved external symbol _glewInit@0
  1&gt;C:\dev\SPHFluids\SPHFluids\Release\SPHFluids.exe : fatal error LNK1120: 1 unresolved externals
  1&gt;
  1&gt;Build FAILED.
  </code></pre>
  
  <p>Everything without d (/MD /MT):</p>
  
  <pre><code>c:\dev\soft\physx-3.2.3_pc_sdk_core\include\foundation\pxpreprocessor.h(318): fatal error C1189: #error :  Exactly one of NDEBUG and _DEBUG needs to be defined by preprocessor
  </code></pre>
  
  <p>and it's only one configuration of lib files. I can compile gltools and freeglut other way or set #define GLEW_STATIC or #define FREEGLUT_STATIC other way... It's just too many options for a newbie. :)</p>
  
  <p>One more:</p>
  
  <pre><code>1&gt;LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
  1&gt;main.obj : error LNK2001: unresolved external symbol "class physx::PxFlags&lt;enum physx::PxFilterFlag::Enum,unsigned short&gt; __cdecl physx::PxDefaultSimulationFilterShader(unsigned int,struct physx::PxFilterData,unsigned int,struct physx::PxFilterData,class physx::PxFlags&lt;enum physx::PxPairFlag::Enum,unsigned short&gt; &amp;,void const *,unsigned int)" (?PxDefaultSimulationFilterShader@physx@@YA?AV?$PxFlags@W4Enum@PxFilterFlag@physx@@G@1@IUPxFilterData@1@I0AAV?$PxFlags@W4Enum@PxPairFlag@physx@@G@1@PBXI@Z)
  1&gt;main.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall physx::PxDefaultErrorCallback::~PxDefaultErrorCallback(void)" (??1PxDefaultErrorCallback@physx@@UAE@XZ)
  1&gt;main.obj : error LNK2001: unresolved external symbol "public: __thiscall physx::PxDefaultErrorCallback::PxDefaultErrorCallback(void)" (??0PxDefaultErrorCallback@physx@@QAE@XZ)
  1&gt;main.obj : error LNK2001: unresolved external symbol "public: static class physx::PxProfileZoneManager &amp; __cdecl physx::PxProfileZoneManager::createProfileZoneManager(class physx::PxFoundation *)" (?createProfileZoneManager@PxProfileZoneManager@physx@@SAAAV12@PAVPxFoundation@2@@Z)
  1&gt;main.obj : error LNK2001: unresolved external symbol "class physx::pxtask::CudaContextManager * __cdecl physx::pxtask::createCudaContextManager(class physx::PxFoundation &amp;,class physx::pxtask::CudaContextManagerDesc const &amp;,class physx::PxProfileZoneManager *)" (?createCudaContextManager@pxtask@physx@@YAPAVCudaContextManager@12@AAVPxFoundation@2@ABVCudaContextManagerDesc@12@PAVPxProfileZoneManager@2@@Z)
  1&gt;main.obj : error LNK2001: unresolved external symbol "class physx::PxDefaultCpuDispatcher * __cdecl physx::PxDefaultCpuDispatcherCreate(unsigned int,unsigned int *)" (?PxDefaultCpuDispatcherCreate@physx@@YAPAVPxDefaultCpuDispatcher@1@IPAI@Z)
  1&gt;main.obj : error LNK2001: unresolved external symbol __imp__PxCreateFoundation
  1&gt;main.obj : error LNK2001: unresolved external symbol _glewInit@0
  1&gt;main.obj : error LNK2001: unresolved external symbol _PxCreatePlane
  1&gt;main.obj : error LNK2001: unresolved external symbol __imp__PxRegisterArticulations
  1&gt;main.obj : error LNK2001: unresolved external symbol __imp__PxRegisterHeightFields
  1&gt;main.obj : error LNK2001: unresolved external symbol __imp__PxCreateBasePhysics
  1&gt;C:\dev\SPHFluids\SPHFluids\Release\SPHFluids.exe : fatal error LNK1120: 12 unresolved externals
  1&gt;
  1&gt;Build FAILED.
  </code></pre>
  
  <p>It's with all these PhysX pragmas commented.</p>