Can MSVC throw warnings if /ZA is violated? - visual-c++

I want to write portable code. For this, I want to disable language extensions with the compiler flag /ZA.
Since Win32 APIs (Windows.h) need MSVC extensions, I need to remove /ZA. However, is it possible that MSVC still throws warnings if a language extension is used?
I am writing a CMake project and I want to use the language extensions only where necessary (the part of the project that is used for the Windows compilation)

Related

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.

How to run c++11 codes in vim with cvim plugin?

I have installed cvim plugin for vim in Ubuntu from this link :
http://www.thegeekstuff.com/2009/01/tutorial-make-vim-as-your-cc-ide-using-cvim-plugin/
Now I want to run c++11 standard programs in vim.How to configure vim so that it can compile and run c++11 programs ?
The plugin defaults to gcc as the C compiler, configured by g:C_VimCompilerName (as per the help). You need to have a compiler version installed that supports the new C++11 features.
To inquire about general plugin support for C++11 (e.g. in its snippets and other features), best directly ask the plugin author (the plugin page even references a mailing list), and ideally offer patches and your help.

Warning LNK4098 and LNK1123 when working with OpenGL in VC++

So I'm trying to get the first exercise in the OpenGL Superbible 5th edition to run. It should draw a triangle. I've managed to fix all of my dumb typos. Now I'm down to just two error messages, one of which I think is familiar;
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
I think I stumbled across LNK1123 when I first used C++, and I fixed it by disabling 'Incremental Linking' in the project settings. However, when I try this now, though the program does run and a window does open, no triangle is drawn, and I'm given a list of errors relating to OpenGL tools. And LNK4098 is still there as well.
This is my first project using library imports. Although it was a minefield trying to get it to work, I finally got the graphics libraries GLEW and freeGLUT into my project, by adding them to the project's include path list, and then adding them as existing items to the project. But I suspect that this method has upset the mighty VC++. Could someone please help?
This has nothing to do with OpenGL. This error is basically telling you that you are using the multi-threaded version of Microsoft's C standard library in a project that is already linking to another version of the library.
The interesting thing is that newer versions of MSVC do not have different versions of the C standard library for threaded vs. non-threaded. Thus, your MSVC version is relevant information that is absent from the question.
In any case, the linker warning actually tells you exactly how to resolve the warning. You can add /NODEFAULTLIB:libc to the linker command in your project settings. There is usually an edit-box in the project settings to accomplish this as well, but since its location varies from version to version, adding this to the command-line is simpler.
As for the COFF issue, this is related to the generation of debug symbols in an incremental linking project. /INCREMENTAL:NO should fix this issue. Regarding the cause of it, have you installed different versions of MSVC on this system in the past?

How to disable c++ strong type checking in VS

When porting unix project developed in C language to windows and compiling it with VS 2005, compiler reports errors related to incorrect type conversion like " can not convert 'const char*' to 'char*' ". Is it possible to disable this strong checking through compiler options.
-Thanks for attention
Assuming your code is valid C (C89, specifically, since VC++ doesn't support C99), it will be automatically disabled if you either name the file with a .c extension, or in project properties, set it to "Compile as C"
That should disable all C++-specific features and type checks.
I'm pretty sure, you only need to set the "Compile as C" commandline option (/TP). I'm not entirely familiar with ANSI-C (Over ANSI-C++) but i'd strongly recommend converting it to be type safe regardless. Why return a const and then ignore this fact?
I'm not sure you can - it may be the case that the C code isn't valid (and the Unix compiler you're using incorrectly allows it). You can disable warnings, but I don't think you can disable specific errors.
If you haven't already, you can change the project options to compile as C instead of C++ (Prpoerties -> Config Properties -> C/C++ -> Advanced) but I don't think that'll help.
If you can compile as C++, const_cast might be able to help: http://msdn.microsoft.com/en-us/library/bz6at95h(VS.80).aspx

Loading Boost 1.40.0 into Intellisense in Visual Studio 2005?

Is there any way to get Intellisense in Visual C++ for Visual Studio 2005?
I'm trying to get the Boost libraries to load up with intellisense and in the object browser/class view.
I installed the binary for Windows with the BoostPro installer (BoostPro 1.40.0 Installer).
I'm not certain that it comes with the source code however, which may be required to make Intellisense work in VS2005.
Boost is open source, and mostly header only. Just make sure IntelliSense knows the directory where boost resides so it can explore it.
As an un-answer, you might try out Visual Assist X, which works far better and has more features that Visual Studio's IS.
To make sure Intellisense can find boost, just make sure Boost is in the include directories (under Project Properties->C/C++->Additional Include Directories). Maybe move it to the top. After that, close your instance of Visual Studio, and search the a *.ncb file near your project, and delete it. This will cause IntelliSense to refresh. This should hopefully be enough for it to assist you. (You have to include boost headers into your source files with #include for IntelliSense to consider it)
Keep in mind boost has some very complex parts that IS will choke on, but should still provide the names.
Intellisense scans the headers #included in source files in Visual C++ projects.
So create a project with a single source file that includes the top level header of the boost library that you're interested in. Some of the boost code can't be parsed by intellisense though, and the boost code contains a lot of code to workaround language or compiler limitations that's just noise to someone wanting to see the user facing structure of the libraries.

Resources