How to ensure that the /EDITANDCONTINUE directive is not ignored - visual-studio

I get this message when I try to edit and continue in VSC15:
'file.cpp' in 'LIB.DLL' was not linked with Edit and Continue enabled.
Ensure that /INCREMENTAL linking is enabled, and the /EDITANDCONTINUE directive is not ignored.
I've already ensured that /INCREMENTAL is enabled but can't figure out the second part.
Compiler command line:
/Yu"stdfx.h" /GS /analyze- /W3 /Gy /Zc:wchar_t /ZI /Gm- /Od /Fd".\Debug\vc140.pdb" /Zc:inline /fp:fast /D "x86" /D "WIN32" /D "_WINDOWS" /D "DEBUG" /D "_UNICODE" /D "UNICODE" /D "_WINDLL" /errorReport:none /WX- /Zc:forScope /RTC1 /GR /Gd /Oy- /MTd /Fa".\Debug\" /EHsc /Fo".\Debug\" /Fp".\Debug\LIB.pch"
Linker command line:
/OUT:".\Debug\LIB.dll" /MANIFEST:NO /NXCOMPAT /PDB:".\Debug\LIB.pdb" /DYNAMICBASE /DEF:"EXPORT.DEF" /IMPLIB:".\Debug\LIB.lib" /DLL /MACHINE:X86 /NODEFAULTLIB:"libc.lib" /OPT:REF /SAFESEH /INCREMENTAL /PGD:".\Debug\LIB.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:".\Debug\LIB.dll.intermediate.manifest" /MAP /OPT:ICF

Looking at the command lines:
Compiler command line: Edit and Continue isn't really compatible with /Gm-, it requires "Enable Minimal Rebuild" (/Gm).
Linker command line: /OPT:REF, /SAFESEH, /OPT:ICF are all incompatible with Edit and Continue and should cause LNK4075.
If you try a clean build of LIB.dll, you should see warnings such as:
1>LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/OPT:REF' specification
1>ConsoleApplication1.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification

Try turning off SAFESEH on the advanced page of the linker settings.
/SAFESEH:NO

The complete official answer for vs2015 case is here https://blogs.msdn.microsoft.com/vcblog/2016/07/01/c-edit-and-continue-in-visual-studio-2015-update-3/ Also it may be helpful to read this one https://blogs.msdn.microsoft.com/vcblog/2013/10/29/the-visual-c-linker-best-practices-developer-iteration/
As for my case I haven't seen any uncompatible flags in linking command line, and it turned out that
/LTCG
is turned on by default, so I had to turn it of manually with additional linker option in every project of my solution
/LTCG:OFF

I had the same problem, did all steps described above but no luck.
I use VS2017.
Helped next: you have to specify /ZI for each specific *.cpp file in your project:
right click on the *.cpp file in the Solution Explorer
Properties > C/C++ > General > Debug Information Format = Program Database for Edit And Continue (/ZI)

Related

openmp offloading feature throws error "Intel Compiler compatibility mode was disabled"

I try to make use of the openmp offloading feature. Unfortunatley I get some strange error messages when I try to compile. (Windows 10)
Here are the command line options I use:
/Yu"stdafx.h" /GS /fsycl /Qiopenmp /W3/fsycl-targets=spir64_gen-unknown-unknown-sycldevice /Zi /O2 /Qopenmp-targets:spir64/Qipo /Zc:forScope /MD /std:c++17 /Fa"x64\Release" /EHsc /nologo /Fo"x64\Release" //fprofile-instr-use "x64\Release" /Fp"x64\Release\AlgoGPU.pch"
I remove the /I and /D
This is what I get during compilation:
error: Enables or disables Intel Compiler compatibility mode was enabled in PCH file but is currently disabled
error: PCH file was compiled for the target 'x86_64-pc-windows-msvc19.28.29914' but the current translation unit is being compiled for target 'spir64_gen-unknown-unknown-sycldevice'
2 errors generated.
C:\Program Files(x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Platforms\x64\PlatformToolsets\Intel C++ Compiler 2021\Toolset.targets(199,5): error MSB6006: "icx.exe" exited with code 1.
Does anyone know what I'm doing wrong?
I tried the below command line option with oneAPI DPC++/ icx compilers
-fsycl -fsycl-targets=spir64_gen-unknown-unknown-sycldevice /std:c++17 /O2 /Zc:forScope /MD /Qiopenmp /Qopenmp-targets=spir64

vc6 project is tyring to link against mfc42.lib under debug mode in vs2008

I have my project converted from vc6 to vs2008。 When i rebuild it under "debug" mode, an link error occurs. " fatal error LNK1104: cannot open file 'mfc42.lib'".
I donot know why.
why the compiler would link against 'mfc42.lib'?
Isn't it supposed to link against 'mfc42d.lib' ??
I have checked my project properties. See the followings:
C/C++:
/Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "USER_CLASS=AFX_EXT_CLASS" /D "GROUP_CLASS=AFX_EXT_CLASS" /D "_VC80_UPGRADE=0x0600" /D "_AFXDLL" /D "_MBCS" /Gm /EHsc /RTC1 /MDd /Yu"stdafx.h" /Fp".\Debug/SunyRTM.pch" /Fo".\Debug/" /Fd".\Debug/" /FR".\Debug/" /W3 /nologo /c /ZI /TP /errorReport:prompt
Linker:
/OUT:".._debug\ChiticRTMD.exe" /INCREMENTAL:NO /NOLOGO /MANIFEST /MANIFESTFILE:".\Debug\ChiticRTMD.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:".\Debug/ChiticRTMD.pdb" /MAP:".\Debug/ChiticRTMD.map" /SUBSYSTEM:WINDOWS /DYNAMICBASE:NO /MACHINE:X86 /ERRORREPORT:PROMPT "..\SNetDrv\Debug\SNetDrvD.lib" "..\RdbRW2008\Debug\RdbRWD.lib" "..\IOC\Debug\IOCD.lib"
when I compared these command lines to another project converted from vc6 to vs2008 and they appear similiarly. However, that project (not current one) is able to run correctly under 'debug' mode.
It is rather confusing , who can help me?

LNK2001 error when compiling on command line, but not in IDE

I have a large VC++ project developed in Visual Studio 2010 that I need to be able to build from the command line using CL.exe. In the IDE, the project builds successfully, but I haven't been able to build it on the command line.
I've mostly dealt with linker errors and have gotten it down to one:
LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
C:\<path_to>\Debug\LargeProject.exe : fatal error LNK1120: 1 unresolved externals
I found in the debug folder a file called "LargeProject.log" that shows the precise command line arguments that get called from the IDE when the IDE builds. I've listed them here, if it helps.
(See edit notes at bottom of this question for some updates)
CL.exe /c /Zi /nologo /W3 /WX- /Od /Oy- /D WIN32 /D _WINDOWS /D _DEBUG /D _MBCS /D _AFXDLL /Gm- /EHa /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yc"StdAfx.h" /Fp"Debug\LargeProject.pch" /Fo"Debug\\" /Fd"Debug\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt "Source Files\stdafx.cpp" /wd4482 > testDump.txt
CL.exe /c /Zi /nologo /W3 /WX- /Od /Oy- /D WIN32 /D _WINDOWS /D _DEBUG /D _MBCS /D _AFXDLL /Gm- /EHa /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Debug\LargeProject.pch" /Fo"Debug\\" /Fd"Debug\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt <list of all source files except the following> /wd4482 > testDump.txt
CL.exe /c /Zi /nologo /W3 /WX- /Od /Oy- /D WIN32 /D _WINDOWS /D _DEBUG /D _MBCS /D _AFXDLL /Gm- /EHa /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Yu"StdAfx.h" /Fp"Debug\LargeProject.pch" /Fo"Debug\\" /Fd"Debug\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt "Source Files\LargeProject.cpp" /wd4482 > testDump.txt
rc.exe /D _DEBUG /D _AFXDLL /l"0x0409" /I"Debug\\" /nologo /fo"Debug\LargeProject.res" LargeProject.rc > testDump.txt
rc.exe /nologo /fo"Debug\LargeProject.exe.embed.manifest.res" "Debug\LargeProject_manifest.rc" > testDump.txt
link.exe /ERRORREPORT:PROMPT /OUT:"C:\<path_to>\Debug\LargeProject.exe" /INCREMENTAL /NOLOGO <list of libraries used> /MANIFEST /ManifestFile:"Debug\LargeProject.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\<path_to>\Debug\LargeProject.pdb" /SUBSYSTEM:WINDOWS /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\<path_to>\Debug\LargeProject.lib" /MACHINE:X86 "Debug\LargeProject.res" > testDump.txt
// note that I don't run any of the commands below because the above command
// threw an error.
mt.exe /nologo /verbose /out:"Debug\LargeProject.exe.embed.manifest" /manifest "Debug\LargeProject.exe.intermediate.manifest" "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Include\Manifest\dpiaware.manifest" > testDump.txt
rc.exe /nologo /fo"Debug\LargeProject.exe.embed.manifest.res" "Debug\LargeProject_manifest.rc" > testDump.txt
link.exe /ERRORREPORT:PROMPT /OUT:"C:\<path_to>\Debug\LargeProject.exe" /INCREMENTAL /NOLOGO <list of libraries used> /MANIFEST /ManifestFile:"Debug\LargeProject.exe.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"C:\<path to>\Debug\LargeProject.pdb" /SUBSYSTEM:WINDOWS /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\<path_to>\Debug\LargeProject.lib" /MACHINE:X86 "Debug\LargeProject.res" > testDump.txt
As you can see, I ran each of these in sequence (until I got an error) and dumped the contents to testDump.txt. Here's testDump.txt's contents after the first link.exe command
LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
C:\<path_to>\Debug\LargeProject.exe : fatal error LNK1120: 1 unresolved externals
I'm confused that I'm getting this error on the command line, but not from the IDE, which is presumably just running these commands behind the scenes. It's also worth noting that I've run the vcvars32.bat file from my command prompt window, so it can't be a local environment variable issue.
Edit:
I've tried adding msvcrt.lib to the list of libraries in the link command. This produced a new linker error:
msvcrt.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain#16 referenced in function ___tmainCRTStartup
C:\<path_to>\Debug\LargeProject.exe : fatal error LNK1120: 1 unresolved externals
I've read that this means the proper entry point wasn't defined in the project. ie, that there should be a WinMain() function in the project to serve as the the entry point for the application. That seems logical, but I haven't found that function and, to reiterate, the project compiles and links fine in the IDE, and presumably the log file I got these commands from is merely listing what the IDE was doing anyway.
There seem to be other CRT libraries. I tried msvcprt.lib, but that yeilded an identical error message to before I had added anything. The other similar .lib files that exist are msvcmrt.lib,msvcmrtd,msvcprtd,msvcrtd,msvcurt,and msvcurtd. What are the differences between these library files, and how does someone choose which one to use?
I had the same error and I know how to fix it.
In your project, you choose a non GUI project : it is a mistake and to fix it choose (I dont known the exact names, I use VS in French)
option->Link options->System->Sub-système=Windows
and it should work

wxWidgets (static lib) will not link under VC++ 2010

I cannot get a wxWidgets program that uses the wxWidgets static libraries to compile and link properly under VC++ 2010. Under VC++ 2008, it's fine. (WxWidgets still ships with vc++ 2008 project files.)
I compiled and ran the "minimal" sample program that comes with wxWidgets. It is a GUI hello world. No problem. I used VC++ 2010 to convert the .vsproj to .vsxproj and attempt to compile and link under VC++ 2010. Problem.
Be assured that I changed absolutely nothing other than to run the VC++ 2010 conversion to create minimal.vsxproj.
I got many linker warnings and errors, all having to do with STL wchar_t strings in the wxWidgets libs. Here is what I think is happening. I believe there must be #ifdefs in the wxWidgets code that select __declspec(import) or not, based on preprocessor symbols. When VC++ 2010 converted the project, it must have changed the symbols to something that fools wxWidgets. If so, the bug could be in either place, either wxWidgets is making invalid assumptions about pre-processor definitions, or the VC++ 2010 conversion messed them up.
The command lines for compiling the lone .cpp file in the project differ more than I would expect them to.
2008 command line
/Od /I ".....\lib\vc_lib\mswud" /I ".....\include" /I "." /I
".....\samples" /D "WIN32" /D "_DEBUG" /D
"_CRT_SECURE_NO_DEPRECATE=1" /D "_CRT_NON_CONFORMING_SWPRINTFS=1" /D
"_SCL_SECURE_NO_WARNINGS=1" /D "WXMSW" /D "_UNICODE" /D "_WINDOWS"
/D "NOPCH" /D "UNICODE" /FD /EHsc /RTC1 /MDd /Fo"vc_mswud\minimal\"
/Fd"vc_mswud\minimal.pdb" /W4 /nologo /c /Zi /TP /errorReport:prompt
/MP
2010 command line
/I".....\lib\vc_lib\mswud" /I".....\include" /I"."
/I".....\samples" /Zi /nologo /W4 /WX- /Od /Oy- /D "WIN32" /D
"_DEBUG" /D "_CRT_SECURE_NO_DEPRECATE=1" /D
"_CRT_NON_CONFORMING_SWPRINTFS=1" /D "_SCL_SECURE_NO_WARNINGS=1" /D
"WXMSW" /D "_UNICODE" /D "_WINDOWS" /D "NOPCH" /Gm- /EHsc /RTC1
/MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /GR
/Fp"vc_mswud\minimal\minimal.pch" /Fa"vc_mswud\minimal\"
/Fo"vc_mswud\minimal\" /Fd"vc_mswud\minimal.pdb" /Gd /analyze-
/errorReport:queue
Example 2010 warning and error
1>wxbase29ud.lib(ipcbase.obj) : warning LNK4049: locally defined symbol ??1?$basic_string#_WU?$char_traits#_W#std##V?$allocator#_W#2##std##QAE#XZ (public: __thiscall std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >::~basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >(void)) imported
1>wxbase29ud.lib(mimecmn.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> > & __thiscall std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >::assign(class std::_String_const_iterator<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >,class std::_String_const_iterator<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >)" (__imp_?assign#?$basic_string#_WU?$char_traits#_W#std##V?$allocator#_W#2##std##QAEAAV12#V?$_String_const_iterator#_WU?$char_traits#_W#std##V?$allocator#_W#2##2#0#Z)
You absolutely must build wxWidgets and the application using it with the same version of the compiler, different MSVC versions use different, incompatible versions of the CRT and so there is no chance at all that you can use VC10 to build an application and link it with wxWidgets built with VC9.
As for building wx itself with VC10, there are indeed sometimes some problems when importing VC9 projects, the custom build rules can somehow be mangled. If this happens to you (although AFAIK nobody reported it for wx 2.9.4 project files yet), just copy the custom build rules for setup.h manually or simply execute them yourself manually.
FWIW we hope to have "native" VC10 and VC11 projects in 3.0 release (coming soon).

Build dll from command line [ Visual Studio ]

I have developed a DLLin c++ using visual studio 2008. I want to run static code analysis on it using a tool which requires me to compile it on command line.
How can i use cl.exe to achieve this.
My project depends on the boost date_time library and couple other referenced projects.
How to build a DLL from the command line in Windows using MSVC
UPDATE: command line
cl /Od /GL /I "..\..\..\..\..\..\..\..\..\..\..\..\..\boost144" /I "..\include" /I "..\..\..\..\..\cincludes" /I "..\..\BASBESUtil\include" /I "..\..\..\..\..\..\..\..\..\..\..\wutility\include" /I "..\..\..\t\include" /I "..\..\..\..\..\..\..\..\..\..\..\enterprise\common\LicenseLib" /I "..\..\Common" /I "..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "UNICODE" /D "_UNICODE_" /D "_WINDLL" /D "_UNICODE" /FD /EHa /MD /Zc:wchar_t- /Fo"Release\\" /Fd"Release\vc90.pdb" /W3 /c /Wp64 /Zi /TP <<src files >> /OUT:".\Release\snaplv.dll" /INCREMENTAL:NO /LIBPATH:"..\..\..\..\..\..\..\..\..\..\..\..\..\boost144\stage\lib" /DLL /MANIFEST /MANIFESTFILE:"Release\snaplv.dll.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"c:\DevEnv\PerforceWorkspace\dev\adamodarachar\snap-tools\LicenseValidator\main\enterprise\BAS\main\server\nativeutil\src\core\main\cpp\xyxmgr\xyxmgr\Release\snaplv.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG /DYNAMICBASE:NO /MACHINE:X86 /NXCompat /DynamicBase version.lib Ws2_32.lib rpcrt4.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib <<obj files>>
Instead of calling the compiler executable directly and passing all those options manually, you can simply call MSVC, and pass the project file on the command line.
devenv.com MyProject.sln /Build "Release|x86_64" /Project MyLib
In my copy of MSVS v8, devenv.com can be found in C:\Programs\Microsoft Visual Studio 8\Common7\IDE. Call devenv.com /? for a list of options.
From the Tools menu select the option Visual Studio 2008 Command Prompt ?

Resources