auto compile MS visual c++ - c++

I have 2 programs: One written in c++ and compile on MS visual studio 2010; The other written in C# and compile on MS visual studio 2010.
My second program automatically edit one of first projects file (.cpp), I want to know is there any way to auto compile my c++ code on file changed?
Thanks.

Yes, call msbuild.
E.g.
msbuild YourSolution.sln /p:Configuration=Release
(Or Debug, if that's what you're building for)
Sounds like your tool would be better off written as an msbuild task though.

Related

Is is possible to build codes using Bazel in Visual Studio?

I'm currently following this instruction to build C++ code with tensorflow.
What I want to do is to run the execution (binary) file with Visual Studio's debug mode.
To do this, I think I have to build a binary file via Visual Studio first so that I can set a breakpoint and execute the code line by line.
But problem is that building the code in VS is not that simple because it uses bazel command instead of g++.
Is is possible to build codes using Bazel in Visual Studio?
As of version 0.22.0, there is no plugin support for Visual Studio: see list of supported IDEs and editors.
There is, however, an API to build IDE plugins.
In the meantime, https://github.com/tmandry/lavender has been published. This is a project generator that generates a Visual Studio Solution file and project files given Bazel build files (WORKSPACE, BUILD, etc.). Also debugging works surprisingly well.

Why different sizes when compiling with Visual Studio and Command Line

This is not a very technical question per se, this is mostly about a curiosity I've got, why is it that when building software with the Visual Studio when you click "Build" or "Build & Run", or you simply compile your software the generated .exe is very lightweight in comparison when using the CMD
For example, I code using the Visual Studio and it may generat a .exe of around 1.5MB, but when I compile the same single .cpp file using >CL, the output .exe may weight even the double
Why is that? Also the same dumb question applies to GNU compilers? when using cpp file.cpp the generated exe can be three times bigger than the ones with Microsoft
Visual Studio also just calls CL (and LINK). The difference is that Visual Studio is passing different options than you are. You can see what options Visual Studio is passing by examining the project properties, and/or examining the build output.

How to debug project compiled with gcc in VS?

I have DLL project (wrote in fortran, C++) compiled with gcc. I would like to debug this DLL but I have to attach to process running on Windows (compiled in Visual Studio). I can't insert breakpoints in Visual Studio to DLL sources.
Please could you help me someone?
Thanks.
In order to set a break point into source code Visual Studio, and really any debugger, has to find a way to map the source lines to address ranges in the executable code. Visual Studio uses the PDB format to create this type of mapping. This file is generated during build time for all languages in Visual Studio. gcc though does not produce this file and hence there is really no way for Visual Studio to map source lines from the file to meaningful values in the generated executable
You could try http://www.wingdb.com/
Apart from that, the easiest way is to rebuild the code using Visual Studio since you have the source. You can get IVF on one month evaluation and use it to generate the DLL and pdb files. If it works and you like IVF, ask your bosses to get you a copy.
Another alternative is to use ddd in a Linux environment. Just create a Linux VM on your Windows machine, rebuild everything for Linux, get ddd and you're away.

Compile single C++ file in Visual Studio 2010

I want to compile a single file in c++ using Visual Studio 2010. I created a new file, not a project, and wrote some "hello world" code and I want to compile it and run it. How to do so?
I've searched here and in Google, I got things like F7 or F5 nothing worked.
You can follow this guide from MSDN to compile standalone C++ files without an IDE.
In Visual Studio 6.0, you could load up a single CPP file, with a main(), and compile it. Can't remember if this was taken away in Visual Studio 2008 or 2010, but it's gone.
It used to be easy to fire up a new instance, paste in some test code an just run it. Now it takes creating or using a dummy project, as others above have noted.
Not hard, just less handy than before.
Probably for simple tests editing your source file in some editor like Notepad or Metapad and building from the command line with something like:
cl /EHsc /W4 /nologo YourSource.cpp
would be just fine (faster than starting up VS2010 IDE, create new project, etc.)

Can C++ projects use T4 in Visual Studio 2010?

T4 did not work for C++ projects in Visual Studio 2008 since it did not use msbuild for C++ projects. (Yes there were workarounds) In Visual Studio 2010, C++ projects uses MsBuild, so do anyone know if C++ projects can use T4 in the same way as C# or VB?
The main integration mechanism for T4 in C# and Visual Basic projects is the TextTemplatingFileGenerator custom tool. Although in Visual Studio 2010 C++ projects now use MSBuild, they still don't support custom tools. As a workaround, you could use T4 Toolbox, which allows you to put a .tt file in a C# or Visual Basic project and have the files it generates added to your C++ project automatically.
I was interested in finding a way of using C++ with the T4 Templating myself and ended up just using the command line and the TextTransform.exe tool directly. You can then write a batch file that will call the TextTransform.exe against all your individual template.tt files, then just call the Batch file as part of your build in visual studio.
As I was learning it I decided to write up my findings in a tutorial which can be found here... http://www.gamelogicdesign.com/2012/04/12/c-code-generation-using-t4-templates/
Maybe this will be of use to people who would like to do something similar.