Mangling and static/dynamic binding in visual studo 2019 - c++

For C++ class can I see the intermediate compilation stage/s? : variable/methods mangling?
some readable representation of generated code for static binding ? vtable?
for students

VS ILDasm is a tool that can decompile code. You could add ILDasm in VS.
Here are the steps:
Select Tools->External Tools->ILDasm
Select the path of ILDasm.exe in Command. The path is generally C:\Program Files\Microsoft SDKs\Windows\vXXX\bin\NETFX 4.0 Tools\ildasm.exe.
Type $(TargetPath) /text/item: in Arguments, then click Apply

Related

Visual Studio error: /W needs an argument

I get the title's error (said to be in file "cl" line 1) but I got no idea of the meaning...
I imported the projet via the .pro file (I need to use visual studio and Qt, because I'm using CONDITION_VARIABLE and Qt only allows his own QWaitCondition. and using QWaitCondition is not an option for me).
The option /W is used to select a warning level for the compiler. But you also have to specify which level you want.

How do you run cl.exe from cmd using the same settings as in MSVS?

I have a c++ project in MSVS 2010 Express. I have been planning to write several unit tests to validate this project. Right now they go along the following lines:
#include "header.h" //Header is the header for the source I want to test
void testSomeFunction()
{
//Call function (from external src, prototype in header.h)
//Save output to file
}
int main()
{
testSomeFunction();
return 0;
}
I am creating these source files outside my project because I want to be able to run each of them as individual executable, but I am having trouble getting the Microsoft linker to link them.
This is my problem so far (CMD output):
cl ut_Converter.cpp Converter.obj
ut_Converter.cpp
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xlocale(323) : warning C4530: C++ exception handler used, but unwind semantics are not enabled. Specify /EHsc
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
/out:ut_Converter.exe
ut_Converter.obj
Converter.obj
Converter.obj : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in ut_Converter.obj
Converter.obj : fatal error LNK1313: pure module detected; cannot link with ijw/native modules
I never really use Microsoft products, I'm familiar with using the GNU tools GCC and make but I have to use the Microsoft tools for this and I have no idea how they work.
Maybe I'm going about building these tests the stupid way but it's the best way I can think of right now.
This is what I want to do:
Compile the source files in my project into object files
Compile my test files into object files
Link the test object file with the appropriate project object files to produce the test executable
How do I go about doing that? (I'm guessing there are some settings I need to set to make everything compatible but I have no idea what they are or how I would go about setting them)
Extra: I know it mentions the debug level but I'd be willing to bet that there will be other incompatible settings. Is there a way to find out what the settings are in the program so I can pass them to cl.exe when I run it?
Edit: When I say command prompt I do mean the one that comes with Visual Studio with all the environment variables setup.
Have you tried going to Programs / Microsoft Visual ... / ... Tools / ... Command Prompt, and running from that dos console window which has the environment variables setup?

VS2012 Error C1107

I am getting the following error:
fatal error C1107: could not find assembly 'platform.winmd': please specify the assembly search path using /AI or by setting the LIBPATH environment variable
Steps to reproduce
0) Create a new empty project
1) C/C++ > General > Consume Windows Runtime Extension > YES
2) C/C++ > Code Generation > Enable Minimal Rebuild > No
3) Add a source file *.cpp, file can be blank
4) Attempt to compile
I tried to manually compare and change the project settings to match that in some sample code but nothing seems to work.
I don't understand what the problem you have, so
If you don't want to code against WinRT just set "Consume..." to false and the issue will be gone
If you want to code against WinRT you should perform an additional step: go to General and set Windows Store App Support to true
To create a C++/CX Desktop application:
In C/C++ -> General project properties, set Consume Windows Runtime Extension to Yes
In the same tab enter these to your Additional #using Directories enter the directories containing the windows.winmd and platform.winmd files. For me, with VS2017, that is:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\store\references;
C:\Program Files (x86)\Windows Kits\10\UnionMetadata;
C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\2.0.0.0;
C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.FoundationContract\2.0.0.0
Then call RoInitialize or use a WinRT main style function (to remove the warning C4447 about main threading):
using namespace Platform;
int main(Array<String^>^ args) ....
References:
Using C++/CX in Desktop apps,
Calling Windows 10 APIs from a desktop application

Pass arguments to compiler to set defined variables?

It is a possible to pass argument to compiler (command line) and set defined variables:
Example:
#define EXVALUE
and I want to define EXVALUE at compiling:
application.cpp -8
'-8' it is a command line argument to define EXVALUE. So I hope that You will understand
what I want, and will help me.
I use Visual Studio C++ 2008 Express Edition.
Thanks. (Sorry for english bads)
Visual Studio (so also Visual C++ EE) uses /D option.
Example:
/D "BOOST_ALL_STATIC_LINK"
You can do it by GUI : Project Properties->C/C++->Preprocessor->Preprocessor Definitions
First link in Google for visual studio preprocessor definitions has really nice information, if you need more.

override default c++ class template in visual studio 2010

When I create a new C++ class in visual studio 2010, it generates a class with some template code. How can I modify this template to suit my own needs ?
One problem with finding info about this is most of information about creating templates is for .NET and the process is different for Visual C++. Also the answer is probably not what you want to hear because it involves editing javascript code rather than just editing some template file. It's possible that you can create a brand new wizard that uses a template file, but this is one way to modify the default template without doing that. Modifying the wizard code involves editing a javascript file:
C:\Program Files\Microsoft Visual Studio 10.0\VC\VCWizards\CodeWiz\Generic\Class\Scripts\1033\default.js
The javascript uses the CodeModel to manipulate (or generate, in this case) source code. Inside that file there is an OnFinish function which you can use to modify the class details that are output. You will see a line like this in the file:
var newclass = oCM.AddClass(strClassName,
strHeader, vsCMAddPositionEnd, "", "", vsCMAccessDefault);
to add a new function you would do something like:
newclass.AddFunction("MyFunction", vsCMFunctionFunction,
vsCMTypeRefVoid, vsCMAddPositionEnd, vsCMAccessPublic, strImpl);
You can read about it here:
Inside Visual C++ Wizards
Reference Documentation:
Designing a Wizard
The default templates are in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcprojectitems. Change as appropriate for x86-vs-x64 and VS version.
(If I understand correctly)
I don't think you can modify the code that is auto-generated by a wizard, for example when adding a new class.
You could maybe code a new wizard ?
M.
Checked in MVS 2008...
File: C:\Program Files\Microsoft Visual Studio 9.0\VC\VCWizards\CodeWiz\Generic\Class\Scripts\1033\default.js
Added code (after creating default ctor & dtor in the default.js)
var oCopyCtor = newclass.AddFunction(strClassName+"(const "+strClassName+"& refObj)", vsCMFunctionConstructor, "", vsCMAddPositionEnd, vsCMAccessPrivate, strImpl);
var oAssignmentOperator = newclass.AddFunction("operator=(const "+strClassName+"& rhs)", vsCMFunctionOperator, strClassName+"&", vsCMAddPositionEnd, vsCMAccessPrivate, strImpl);
oAssignmentOperator.BodyText = "if(&rhs == this) { return *this; }\n//TODO: real assignment here...\nreturn *this;\n"
But I still can't figure out how to turn off implementation in *.cpp (x.BodyText = ""; doesn't help), and omitting strImpl parameter puts the implementation in the *.h file