Assertions not compiled out of release build - visual-c++

I've told VC++ to compile my program in release mode, yet the assert() statements still fire. I thought assertions were supposed to be compiled out of release builds for performance. What's going on? Is there some other setting I need to set skip compiling them?

Check which preprocessor symbold you're defining. A Debug build would normally define _DEBUG, and a Release build would normally define NDEBUG. Assertions would normally be switched off when NDEBUG is defined.

Open the app under the debugger. Do debug->break when the assertion dialog is up. Look at the source file where the assert is firing. Now look at the build settings of that file. If the settings seem right and you are loading the release version, set /P and /d1PP on the compiler command line to reveal where the errant #define is coming from.
Martyn

Related

HaxeDevelop debug does not stop on breakpoint

I am new to HaxeDevelop (but experienced with FlashDevelop) and it has essentially no useful documentation that I can find via a Google search. I am trying to get a simple app up and running with OpenFL and Starling. It had an issue so I tried putting a breakpoint. However, it doesn't stop at the breakpoint. I even put several breakpoints in the main class code and it won't stop. I've even tried making a new project with just a main class and a dummy class and it won't breakpoint on this either. Do I have to tell it to use a special debug process or something? Do I need to install any more software? Should I just use VS Code?
I installed HaxeDevelop and haxe and lime and OpenFL. I made a new OpenFL project and did some simple work in the Main file (make some integer variables, prints some stuff etc.) and littered it with breakpoints. I run it and the output prints (but does not stop at any breakpoints):
Build succeeded
Done(0)
haxelib run lime run "project.xml" neko -debug
Running process: C:\HaxeToolkit\haxe\haxelib.exe run lime run "project.xml" neko -debug
Main.hx:17: Hello World!
Main.hx:21: Did some stuff... Did it stop?
Done(0)
I've tried it using neko, html5, and flash and none of them will stop at the breakpoints.
If anyone knows of a good tutorial for getting Haxe to run in debug mode in HaxeDevelop, FlashDevelop, or VS Code, I would super appreciate it.
HaxeDevelop / FlashDevelop only support breakpoint debugging on the Flash target. It can be a bit tricky to set up since it requires a 32 bit Java to be in your PATH (this limitation does not exist with Flash debugging in VSCode). You also need to make sure that a Flash Debug Player is associated with .swf files. You can find more details here and here.
VSCode on the other hand supports debugging a much wider range of targets:
JavaScript
HashLink
HXCPP
Eval (macros)
Flash
There is no debugging support for the Neko target in any IDE.
If you are using OpenFL, you should install the Lime extension, which handles all the configuration of the individual debug adapters for you (note: this requires Lime 7.3.0 or newer). In a fresh project, simply "Start Debugging" and select "Lime" from the dropdown:
This creates a Lime launch configuration in .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Lime",
"type": "lime",
"request": "launch"
}
]
}
Debugging should now work out of the box with the currently selected target (just make sure you have the "Debug" configuration of the target selected). You can click the status bar indicator to switch between configurations:
If you're missing a debug extension, the Lime extension should open a popup that offers to install it.
If you use HaxeDevelop and target JavaScript, you can make a debug build (add -debug to your HXML or select 'debug' dropdown), which provides source-maps. Then you can use the browsers devtools (F12) and step through all Haxe code.
You can easily place a debugger statements in your code using js.Lib.debug() to place a "breakpoint" at this position. From there you can also start stepping.
This isn't HaxeDevelop specific, but works very good when using HaxeDevelop + JavaScript target.
https://haxe.org/manual/debugging-javascript.html

Configuring VC++ for WxWidgets

I am trying to follow this guide
to configure VC++ for WxWidgets. I got stuck here.
So for Core wxWidgets libraries to include, I did include wxmsw31u[d]_core.lib and wxbase31u[d].lib under Linker>>Input>>Additional Depenedencies. That is all to it right?
As for Linking with correct runtime library, can someone tell me how that is done? I manage to get here but don't know how to set the indicated settings.
Please help. I really appreciate it.
When you want to debug your app the debugger must know where in the compiled code is each function used. In jargon, the "debugging symbols". Windows puts these symbols in the compiled executable, while Linux uses another, .devfile.
When you compile code (your app or wxWidgets library) you must tell the compiler whether you want a "Debug" version or a "Release" one.
If you want the debugger to be able to step into wxWidgets code, then you must compile wxWidgets in "debug" mode, which will add the character d to the library files built. So, you must add, for example, wxmsw31ud_core.lib to your app dependencies. Notice the d between u and _. Use the file explorer to see all files generated by wxWidgets compilation process.
Perhaps you don't want all this wxWidgets "debug". Then use another wxWidgets compilation route and add wxmsw31u_core.lib instead of the d'd version. Still you can compile your own app in debug mode, but not being able to step through wxWidgets internals.
Now for your app, a) do you want a single executable file also containing wxWidgets code? or b) let your app in a .exe file which uses as needed external .dll files?
a) is called "static linkage" while b) is called "dynamic linkage"
As you can see, there are four combinations of debug/release & static/dynamic. You must choose one "runtime library" to link to your app.
The table in the wiki shows the switch and MSVC lib (select the desired combination in the 'properties' page) to use in your app; and macro definition required to build wxWidgets if you use nmake instead of the already provided configurations in VS.
Take a look at docs\msw\install.txt for more info.
The best advice I give is that you look into "minimal" sample project. Load it into VS and read every option. You can even make a copy, change some file names and use it for your own app.
I recommend using the official instructions instead of the wiki, they're simpler and, if you look at the last paragraph, you can see that you don't even have to link the libraries manually with MSVC.
You also don't need to do anything special to link with the correct version of the CRT, the defaults are just fine.

Using Resharper to compile the source cant hit the breakpoint

When I use Resharper to compile my source that I always cant hit the breakpoint and the Visual Studio say that
The breakpoint will not currently be hit. The source code is different from the original version.
I must click the rebuild button to rebuild the source to hit it.
Can anyone give me some way to make the resharper to build the source well?
I don't want to do some step when I want to run app than press F5.
This may be a result of perceived differences between the source code and compiled debugging symbols. I'm not sure if this will help, but you could try allowing slightly different source code when debugging. Untick the option as shown...
Tools > Options > Debugging

Make VC++ Recompile All Files

I am writing a simple C++ application using the Visual Studio IDE and the VC++ compiler.
In this application I have an erroneous file that affects the other files as well. When I compile it, as expected I get errors. Now, if I remove all references to the file from my project, and then run it, the compiler will still exit in an error. In the compile message I then see the filename of the erroneous file. The only way to prevent this from occurring is by either removing all contents of that file, or remove the file, and then recompile it.
My guess is, because VC++ is 'smart' it saves compilations and when they are unaffected it doesn't recompile it. But because the erroneous file affects the other files, some compile errors (not all) simply stay.
Does anyone know how to disable such behaviour?
Can you show the errors ?
If the file contains actual functional code then fix the compilation errors ?
If the file does not contain functional code, then what is it doing in your project.
I expect this "erronous" file to be a header (.h) file that is included in other c++ files, so when it tries to compile the c++ files it will generate an error (or more) per c++ file.
If you just remove the file from the IDE project; the compiler will still include the file (because it still exists on disk); and will continue generating errors.
If you actually remove the file on disk, then you will have other types of errors.
In all cases, just fix the compilation errors.
To recompile all files you can rebuild all, or make a clean build.
Yes VC++ will save compilations if things have not changed, it will probably say up to date.
I don't think that you can disable it, but a clean build should be able to solve it. If that is the entire problem, also check how it is linking things, there you should be able to remove references to files.
The build should be under the build tab.
MSBuild and the Visual C++ compiler to an excellent job producing a correct binary when you make changes such as adding or removing a file. Chances are, even without a complete rebuild the compiled executable will be correct. If you are seeing unexpected behavior, it is most likely caused by one of the following things:
Check that Visual Studio is configured to build your project before running it. Check the following options under Tools → Options... → Projects and Solutions → Build and Run:
Before building: Save all changes
On run, when projects are out of date: "Prompt to build" or "Always build"
On run, when build or deployment errors occur: "Prompt to launch" or "Always launch"
If Visual Studio asks if you want to run an old version of your program, you may have introduced a compile error by removing the file, so the compiled binary will certainly be out-of-date until you correct it.
If your project contains a file that directly or indirectly #include "yourRemovedFile", then removing the file from the project may have no effect.
The Visual Studio Errors List reports issues independently from the compiler. You might be seeing old errors reported that are no longer relevant to your project but have not been cleared from the UI yet. In these cases, when you run your program you would still get the same results. You can also see if this is your problem by restarting Visual Studio and seeing if the error messages persist.

nmake: is it possible to disable compilation warnings?

Microsoft nmake tool will output any compiler warnings during build process. This is very annoying while building large projects (like Qt). Is it possible to disable warnings display while using nmake?
Not nmake is showing you the warnings, but the compiler/tools/scripts that are used. So you have to look into your Makefile, find out which programs nmake is calling and look into their documentation about the command line options of this tools. For example, for the Microsoft C++ command line compiler cl, you can add "/w" to disable all warnings. cl /? will show you the list of available options. For other programs, other command line options may be appropriate.
If you really do not like to see any output, you can call
nmake >nul: 2>nul:
sending all output to nirwana, but I am pretty sure that is not what you want.
For Microsoft's C/C++ compiler you can disable spesific warnings from the code using #pragma directives
#pragma warning(disable:4005)
This will disable warning 4005. When you have included the suspect code, you can re enable the warning:
#pragma warning(default:4005)
first of all, the absolute majority of warnings should be taken in consideration and "resolved".
secondly, you can use #pragma as indicated Arve
the third solution see here:
To disable all compiler warnings
With a project selected in Solution Explorer, on the Project menu click Properties.
Click the Compile tab.
Select the Disable all warnings check box.
To disable a single compiler warning
With a project selected in Solution Explorer, on the Project menu, click Properties.
Click the Compile tab.
In the Default Compiler Options table, set the Notification value for the warning to None.
To treat all compiler warnings as compilation errors
With a project selected in Solution Explorer, on the Project menu, click Properties.
Click the Compile tab.
Select the Treat all warnings as errors check box.
To treat a single compiler warning as a compilation errors
With a project selected in Solution Explorer, on the Project menu, click Properties.
Click the Compile tab.
In the Default Compiler Options table, set the Notification value for the warning to Error.

Resources