Native C++ project cannot compile in release mode? - c++

I was building a win32 static library project and on debug mode it compiles without any problem but when I changed the build mode to release I get this link errors. Can anyone suggest what is going wrong here?
Error 2 error LNK1120: 1 unresolved externals C:\Users\serak\Desktop\Cimg Wrapper\Release\nativeWin32console.exe nativeWin32console
Error 1 error LNK2001: unresolved external symbol _main C:\Users\serak\Desktop\Cimg Wrapper\nativeWin32console\MSVCRT.lib(crtexe.obj) nativeWin32console

I think in the Project Propierty Pages (rigth click the project in VS solution explorer) of the project change for ALL configuration and platform, the Configuration Propiertie->Project Defaults->Configuration Type-> from Aplication to Static Libraries: you probably have set it for debug but not for the release configuration.

If you're using Visual Studio, you need to add any external libs that you are linking against in release mode as well. Chances are you have already done this for the debug build configuration, but it does not transfer to release by itself.

Related

VS 2017 Community gets linker errors but Professional doesn't

We're facing a strange issue and I've run out of troubleshooting ideas. The issue is that on some machines, which are running Visual Studio 2017 Community, we get reports that our project (which is CMake based) gets linker errors like this:
17>------ Build started: Project: ndt, Configuration: RelWithDebInfo x64 ------
17> Creating Library E:/NDT_3_0/19_Sept18/qualnet/RelWithDebInfo/exata_so.lib and object E:/NDT_3_0/19_Sept18/qualnet/RelWithDebInfo/exata_so.exp
17>ndt-main-windows-x64-vc14.obj : error LNK2019: unresolved external symbol edKJPOs664VT referenced in function "void __cdecl CheckLibraryLicenses(struct NodeInput*,...)
17>ndt-main-windows-x64-vc14.obj : error LNK2019: unresolved external symbol zzPIPSGJWa referenced in function main
...
17>E:\NDT_3_0\19_sep18\qualnet\bin\exata_so.exe : fatal error LNK1120: 17 unresolved externals
(Apologies if there are typos: for some reason they sent us a screenshot of the text instead of just a copy-and-paste of the text, so I'm transcribing. However, the parts I'm leaving out contain no mention of errors trying to open lmgr.lib which defines these symbols.)
The strange thing is, we can't reproduce these errors here when we do a fresh clone of the same Bitbucket repository they're using and follow the same build instructions. About the only difference I can tell is that our machines are running Visual Studio 2017 Professional. (Though I'm certainly not sure if this is actually the cause of the behavior differences.)
So far, what we've checked:
The library that contains the unresolved external symbols passes sha1sum checks so their Git client isn't corrupting the library binary file lmgr.lib - and same for the ndt-main-windows-x64-vc14.obj file.
The generated ndt.vcxproj project contains (the correct path to) lmgr.lib in the "Linker -> Input -> Additional Dependencies" property, as expected.
The lmgr.lib file does define the mentioned symbols (verified by Cygwin binutils nm).
On their machines, they get essentially the same linker errors whether using the Visual Studio 15 2017 Win64 generator and building from the IDE, or using the NMake Makefiles generator and building from a command prompt. Both configurations work fine on our machines.
I was wondering if somebody out there might have any ideas on why some machines might be failing to find the symbols in lmgr.lib whereas our machines have no problems completing the link stage.
(Possibly relevant: lmgr.lib contains the FlexNet Publisher licensing libraries where the symbols in both lmgr.lib and ndt-main-windows-x64-vc14.obj have been obfuscated by Flexera's lmstrip tool.)
It turned out that when we asked them to upgrade their Visual Studio 2017 Community installation to the latest service pack release, then after that the linker errors disappeared.

Visual Studio Project doesn't build when using MFC

I am building a small game and I would like to show off my progress to my friends by sending them the game.
When trying to send them the Release folder after building it they get the error that they're missing a Visual studio library. I read that I need to create a static MFC library but when I do so my project won't build.
My project is in /MT modus or whatever it is.
Should add Debug mode still builds fine!
It gives me one LNK1120 error message and a lot LNK2001 error messages.
Errors:
Error: LNK1120 70 unresolved externals
Error: LNK2001 unresolved external symbol
I don't know what I'm doing wrong. It's my first C++ project.
Any help is appreciated!
Thanks in advance.

build Bullet Physics for multiple architectures in Visual Studio

I am building a Windows OpenGL application with bullet physics support.
My development environment setup is :
OS : Windows 7 SP1 64 bit
IDE ; Visual Studio 2010 SP1
BulletPhysics - bullet-2.82-r2704
My application has two configurations i.e. Win32 and x64.
Here's my step to build the Windows application :
First I execute the vs2010.bat file in "bullet-2.82-r2704\build".
I add project files from vs2010 folder created by step 1 into my visual studio solution.
Add project dependencies for BulletDynamics, BulletCollision and LinearMath
Add References for all the thee bullet libraries.
Now when I build my solution for both the configurations (i.e Batch Build for Win32 and x64), everything builds properly except for :
x64 Release - with errors like :
BulletCollision_vs2010_x64_debug.lib(btDefaultCollisionConfiguration.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in stdafx.obj
Win32 Release - with errors like :
Win32_Window.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btConvexInternalShape ...
Win32 Debug - with errors like :
Win32_Window.obj : error LNK2019: unresolved external symbol "public: __thiscall btRigidBody
Final message - Build: 13 succeeded, 3 failed
I am following this help to build my Visual Studio project :
http://bulletphysics.org/mediawiki-1.5.8/index.php/Creating_a_project_from_scratch#Create_a_new_Visual_Studio_project
Note: If I use CMAKE to build VisualStudio solutions for BulletPhysics and then link those separately to my windows application for each CPU architecture then it builds properly (i.e. Build for Win32 and x64 separately).
Is there any way I can make that work with just one Visual Studio solution ?
In x64 Release you are trying to link a static library compiled in debug mode (BulletCollision_vs2010_x64_debug.lib) with object files from your app compiled in release mode (stdafx.obj specifically). Compiler options (_ITERATOR_DEBUG_LEVEL) of your object files and compiler options of a lib don't match (values 0 for release and 2 for debug respectively). That's why linking fails. And in Win32 Debug and Win32 Release cases it looks like you don't link libs at all.
I think that project references went wrong way.
In my opinion while "Project references" is good for C# style of modules, in native development it is more like unnecessary complication of things. Just add plain old libs to linker input explicitly, like this:
..\..\lib\BulletDynamics_vs2010_x64_debug.lib
..\..\lib\BulletCollision_vs2010_x64_debug.lib
..\..\lib\LinearMath_vs2010_x64_debug.lib
Change "debug" and "x64" parts accordingly for each configuration. I think it is more reliable.
Add BulletDynamics, BulletCollision and LinearMath to "Project dependencies" for your app project. That will guarantee that bullet will be built before your app. Check "Build order" tab to make sure that builds go in right order.
Double check that compiler options are the same for each module.
In <Build->Configuration manager> for all "Solution configurations" and all "Solution platforms" (dropdowns above) check that project configurations and platforms are right. (i.e. you don't have projects that use debug when you switch solution to release and vice versa)
Still fails? Take a look at sample Bullet applications, like "App_HelloWorld". Compare it's options to your app's options, and you will surely find a source of error.
Probably, you could make it other way around: add your app project to Bullet's solution (remove unneeded stuff), to see if it works.

Visual Studio 2010 : error LNK2001: unresolved external symbol : sapi.h and Microsoft Speech SDK for KINECT

I'm encountering a strange bug in Visual Studio 2010...
I work with the Kinect for Windows SDK v1.8 on VS 2010 Ultimate, for a speech recognizer program using the MS Kinect.
Like it's explained in the sample SpeechBasics (available on Kinect Developer Toolkit Browser), I added the specifics VC++ include and library paths into my project properties, before listing the default system include and library directories.
But When I buid the solution, I get the following errors :
CKinect_Squeletton.obj: error LNK2001: unresolved external symbol _SPDFID_WaveFormatEx
CKinect_Squeletton.obj: error LNK2001: unresolved external symbol _CLSID_SpStream
CKinect_Squeletton.obj: error LNK2001: unresolved external symbol _CLSID_SpInprocRecognizer
CKinect_Squeletton.obj: error LNK2001: unresolved external symbol _CLSID_SpObjectTokenCategory
build failed.
I had checked all my include files, all my project properties. I did a lot of research, and tested many possibilities of response, but I hadn't found response for my problem...
I have tried cleaning the solution, build with a x64 target architecture, but that doesn't always work.
Why have I this problem ?
Like suggested in the comment, I've checked the link on social MSDN
I've resolved some errors but not all in using __uuidof(SpStream) instead of CLSID_SpStream , and __uuidof(SpInprocRecognizer) instead of CLSID_SpInprocRecognizer .
But i don't found CLSID_SpObjectTokenCategory in my code, I have only
ISpObjectToken *pEngineToken = NULL;
hr = SpFindBestToken(SPCAT_RECOGNIZERS,L"Language=40C;Kinect=True",NULL,&pEngineToken);
I can't replace it with __uuidof(SpObjectTokenCategory) .
Also, I always don't know how to resolve the error
CKinect_Squeletton.obj: error LNK2001: unresolved external symbol _SPDFID_WaveFormatEx
I've added sapi.lib in Project + Properties, Linker, Input, and I also try with #pragma comment(lib, "sapi.lib")
I have resolved my problem !
I work on Windows 7 64bit, and I had installed MS Speech Platform SDK 11 x64.
But to build with a x86 target architecture , I had to install and use MS Speech Platform SDK 11 x86, and specify in my project properties the path for the x86 sapi lib !
The compiler gave me errors when I've tried to build with a x64 target architecture, because others specific libraries that I have included in the project are for a x86 architecture...
Sorry and maybe this solution will help someone one day !

LIBCMTD.lib(crt0.lib) LNK 2019 error in project

I've created an OpenGL (GLEW) project in VS2012 and it is working perfectly. Now I've moved the project to VS2013. I've created a new project and set the project's environment the same as I did in VS2012:
Character Set:--------------Use Multi-Byte Character Set
Include Directories:--------C:\Foo\glew-1.9.0\include
Library Directories:--------C:\Foo\glew-1.9.0\lib
Additional Dependences:-opengl32.lib; glu32.lib; glew32.lib
Runtime Libary:-------------Multi-Threaded Debug (/MTd)
All code is exactly the same as before, but when I run the program, I get this error:
Error 1 error LNK2019: unresolved external symbol _main referenced in
function ___tmainCRTStartup c:\FooBar\...\Projects\OpenGL\OpenGL\LIBCMTD.lib(crt0.obj)
OpenGL
I can't see why this same project with the same settings and code doesn't work when it is an exact duplicate.
Hi #SpicyWeenie LIBCMTD is the debug version of the static multi-threaded C runtime library, and according to Microsofts licensing you cannot use than in the release version of code, I would check you are compiling in debug mode:
in debug mode use /MTd as the runtime library
in release mode use /MT as the runtime library
This will hopefully help, if not, then clean your project before building, and if that does not help either, apply liberally with swearing before creating a new project and ensuring it is a Windows Console Application and not a Windows Application (the last one has been the most common cause of the exact error you are describing for me, and happens mostly to me when moving between versions of Visual Studio (2008 to 2010 or 2010 to 2012)
Sincerely hope this helps, but if it doesnt let me know and maybe I can figure out whats wrong:)