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

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.

Related

Visual studio Python extension mixed mode debugging on CMake project

I'm trying to create a C++ Python extension using pybind11 and CMake, and would like to take advantage of visual studio's mixed mode debugging (see) for developing the extension.
I tried following the MSDN guide, and was able to create an extension and debug it using visual studio solution configurations. However, trying to recreate the project with CMake and debug it, breakpoints inside the C++ code are not triggered. I tried recreating the project twice:
a full CMake project (i.e. first create a folder with a CMake file then open it in VS).
a Python solution with a CMake subproject (adding the build folder to python search paths to access the extension).
In both methods C++ breakpoints are not triggered. Is there any way to make this work? Something I'm missing? I know there is a VSCode plugin which enables something similar. I'm currently using it, however I'd like to know if it is possible in Visual Studio proper.
Versions:
Visual Studio 2022
CMake 3.18
Python 3.8 (with debug symbols installed), however this is not the Python distributed with Visual Studio

How to compile source C++ code that doesn't have a project file?

I have just started learning more about C/C++ and I am using Visual Studio 2013 to manage the code.
A project I am working on to use the Tobii EyeX eye gaze system requires me to be able to tweak this code slightly, however I do not understand how I can compile this code to an exe file without a Microsoft Visual Studio project file. This is that code:
https://github.com/MastaLomaster/bkb
In the source folder you see all the project's files but not an actual project file. How would I go about compiling this code? Where do I start? I can not seem to be able to load this is Visual Studio at all - the programmer of the code says (at the bottom of the Github page):
Compiling the source codes As for now, you have to use Microsoft
Visual Studio 2012 (latest update preferred)...
Either create a makefile(if no makefile is exist) for visual studio using nmake or you can use the suggestion provided in this link.
Additionally you can create a project by adding these codes as source. follow this link.

TInyXML++ Premake with Visual Studio 2010

I tried to compile TinyXML++(or TICPP) using premake4 with these settings: "premake4 vs2010 [--unicode] [--ticpp-shared] [--dynamic-runtime]". It compiles the .libs but I can't compile TiCPP.vcxproj because the compiler says "Unable to start program c:\ticpp\lib\ticpp.lib. This file is an unrecognized or unsupported binary file." Anyone got a clue how to make this work? Oh and one more thing, why does Windows ask me if I want to open a .vcxproj with Visual Studio 2010 or Visual Studio 10? How do I make it so that it only picks one, and what's the difference. I tried the first answer, but it didn't work.
Download last version of premake, it does support VS2010
I have compiled tinyXML++ using it, by executing:
premake4 vs2010
it does generate valid sln and vcxproj files.
From oolua build instructions
Visual Studio 2010 (vs10) is not currently supported by premake yet if you have vs10 installed you can run the following command, it will generate vs9 projects and update them using the vs10 command line tool.
premake4 vs2010
As vs10 adds files which have not been created directly by premake, a specific clean operation has been added to the premake script.
premake4 cleanVS10
Scripts to build a local install, build and run unit test etc. have been added for vs10 in the script directory.
Notes:
* oolua's premake4 script may not be the same as yours.
* VS2010 support is borked in premake. Current workaround is to make a 2008 project and make VS2010 convert it for you.

Extend the Visual Studio C++ Build Process

A found an article (Extend the Visual Studio Build Process) that explained how to override build targets in a C# project file. I tested this, and it seems to work well. However, what I really want to do is override a build target in a C++ project (with Visual Studio 2005). The problem is that C++ projects use different XML. Instead of having <project> as the root, C++ projects have <VisualStudioProject> as the root. When I add the <target> tag to a C++ project file and try to open the project in Visual Studio, I get this error:
The following error has occurred during XML parsing:
File:
[Path to Project File].vcproj
Line: 304 Column: 30 Error Message:
Element 'Target' is unexpected
according to content model of parent
element 'VisualStudioProject'.
The file
'[Path to Project File].vcproj'
has failed to load.
How can I override a Visual Studio build target for a C++ project? Or is there a better way to customize what happens during a C++ build?
In Visual Studio 2005 there are no build "targets" for C++ builds as the C++ build system does not use MSBuild.
However, VC++2005 defines the Pre-Build, Pre-Link, Post-Build Events as well as the ability to add a Custom Build Step for non-standard files.
You may be able to achieve what you want using these settings.
Note:
VC++2005 projects can be built using MSBuild, it's just not what Visual Studio does out of the box.
Visual Studio 2010 uses MSBuild for all project types.

How can I debug a MinGW EXE with the Microsoft Visual C++ debugger?

How can I debug a MinGW EXE with the Microsoft Visual C++ debugger?
You can attach the Visual C++ debugger to any process running on the system (from the Visual C++ menu). But for being able to step through your source code Visual C++ would have to load the symbol file (.pdb if I remember correctly) and I don't think GCC generates those files.
Exists many Visual studio extensions such us: WinGDB, VisualGDB you can find it on the web. It allows you to debug as regular Visual Studio project. These projects are not free but it has full functional 30 days trial. It has some restrictions but it's good enough.
The Problem:
GCC compiler (ie MinGW's gcc) generates debug info with "-g" flag. The debug info is embedded into the generated executable. Windows' compiler, on the other hand, uses a peculiar ".pdb" format to store the debug info. For example, Microsoft Visual Studio's debugger needs not only the executable (.exe), but also its debug info (.pdb) to be available.
The Solution:
There is a small program that can extract .pdb files from executables compiled with gcc.
It is called cv2pdb, available at https://github.com/rainers/cv2pdb.
Download cv2pdb https://github.com/rainers/cv2pdb
Put the cv2pdb.exe somewhere in your path, maybe a custom bin folder, so that it will be accessible through the command line.
Compile your file as usual using MinGW's gcc compiler, with the "-g" flag, so that the debug info is included.
Simply run cv2pdb.exe on your executable.
cv2pdb out.exe
This will generate a out.pdb file in the same directory.
(If you have Microsoft Visual Studio installed) Open the executable directly in Microsoft Visual Studio
devenv out.exe
Note: This command simply opens the executable in Microsoft Visual Studio, without creating a project for it. In effect, you can use whatever text editor + build system you want to build your executable, and then use Visual studio only as a standalone debugger.