Visual studio Python extension mixed mode debugging on CMake project - c++

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

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.

C++ OpenGL Project Setup using GLEW, assimp, SDL2 and CMake with CodeBlocks

I've done a whole tutorial about making a 3D Rendering Engine in OpenGL with Java and lwjgl and the guy who made the tutorial also wrote the engine in C++
To increase my knowledge about programming I wanted to take a look at the C++ version too. Also I believe (and I might be totally wrong) that I'm actually able to do a lot more with C++ than with java. The main problem I have is that I cannot get the engine running despite the included instructions and I would really appreciate if someone can help me out.
this is the engine i want to setup: https://github.com/BennyQBD/3DEngineCpp
I want to use CodeBlocks for this project since it was recommended and unlike Visual Studio it is free.. I also already downloaded glew, assimp and sdl and I installed CMake which are needed for this to run. Now I have to put that together according to this instruction here:
###Windows/MinGW###
- Make sure CMake is both installed and added to the system PATH.
- Open a Terminal and run:
```Shell
# install dependencies
# Install GLEW in %PROGRAMFILES%/GLEW or SET %GLEW_ROOT_DIR% to where GLEW is on your machine (Example: D:\PATH_TO_GLEW)
# Install SDL2 in %PROGRAMFILES%/SDL2 or SET %SDL2_ROOT_DIR% to where SDL2 is on your machine (Example: D:\PATH_TO_SDL2)
# Install ASSIMP in %PROGRAMFILES%/ASSIMP or SET %ASSIMP_ROOT_DIR% to where ASSIMP is on your machine (Example: D:\PATH_TO_ASSIMP)
cd build
# REPLACE "Visual Studio 12" with your preferred build toolchain (Maybe you want "Codeblocks - MinGW Makefiles")
# BTW VS 10 is VS 2010, VS 11 is VS 2012 and VS 12 is VS 2013, BLAME MicroSoft for the naming! LOL!
cmake -G "Visual Studio 12" ../
# open the generated SLN file (or cbp file if using CodeBlocks) and build!
```
- Copy the DLLs in /lib/_bin/ to /build/Debug/ and /build/Release/
- In Visual Studio, set the Startup project to 3DEngineCpp
- Move the res folder into the build folder
- Run
Major problem is, since I've only done java coding in eclipse I'm a bit confused..
What does he mean by "Open a Terminal and run: '''Shell" ?? and how am I supposed to install glew, sdl2 and assimp? what's cd build? and why do I need CMake, it isn't really mentioned what it does..?
Maybe someone can elaborate (step by step if possible) what I need to do in order to get this running, thanks a lot!
No guarantees my steps will work flawlessly as external dependencies in C++ is still very painful to deal with for me, but I'll give you some leads and hope you make some progress. Also, I've never used Code::Blocks, so I'm not sure if Visual Studio projects are compatible with it. This is the only way I know how to do things on Windows.
First, you'll need to install CMake. CMake is a utility that generates project files so that the project can be easily compiled on certain platforms. It generates Visual Studio project files on Windows, which will allow you to open the project in Visual Studio, and compile them from there.
In order to build the project, you'll have to sort out its dependencies first.
GLEW:
Download GLEW's sources and extract everything. It comes with Visual Studio project files
Open up Visual Studio with Administrator permissions
Open up GLEW's project
Build everything
Run the install "project" to get Visual Studio to install GLEW
Assimp:
Download Assimp's source from GitHub
Extract the project root directory somewhere. The root directory is the directory where CMakeLists.txt is in
Open CMake's GUI utility
Click Browse Source, and select that directory
Select an output directory by clicking Browse Build
Click Configure, when that's done click Generate. This will generate a Visual Studio project file for you
Open project with Visual Studio, build everything. Run install like you did before to install Assimp
SDL2: SDL's sources come with Visual Studio project files, so you can repeat the steps for GLEW to install it.
Now you can finally start attempting to get the engine to work. No guarantees that it'll work, but I'd try the same thing I suggested for Assimp as they're both CMake projects. Once the project files are generated, you can open it up in Visual Studio. Except this time, you won't really be installing it. You can modify the sources and run it like you would any other C++ project.

Force Cmake & Emscripten to use VS 2010 for compiling

How can I force Cmake to use Visual Studio 2010 for compiling my emscripten projects, and now VS 2015?
I keep running into an issue where cmake says it cannot find the build tools for MSBuild v140. I know it exists though, as the file path is
C:\Program Files (x86)\MSBuild\14.0\Bin
I've even tried setting the path in the Emscripten Command Prompt with
set PATH=C:\Program Files (x86)\MSBuild\14.0\Bin;%PATH%
but the issue still occurs.
If I open this solution in VS 2015, I can see that the configuration is set to Msbuild v 1.40, so I can't wrap my head around why Emscripten says it can't locate it.
The closest thing I could find is in this GitHub bug report on Emscripten.
Any suggestions?
Emscripten in Visual Studio is only supported for VS2010 AFAIK. Personally, I suggest you work with makefiles when generating from CMake. It is much more stable from my experience. The Visual Studio support for Emscripten is not working well, at least for me.
But if you still want to use VS2010, then you have to set the CMake generator to "Visual Studio 10 2010", and then specify the Emscripten toolchain file. You might have to set the CMake platform name to Emscripten, using the -A argument.
cmake.exe -G "Visual Studio 10 2010" -A Emscripten -DCMAKE_TOOLCHAIN_FILE=%EMSCRIPTEN%\cmake\Modules\Platform\Emscripten.cmake
I tried doing this, but each time I did, Emscripten would return a different path to Emscripten.cmake, and say it couldn't find it. Not sure where it was getting this new path from.
Long story short, I realized I installed the web installer for Emscripten installed. So I uninstalled that and instead went with the Full installer, and it all worked well.

Open Cmake Project in Visual Studio like Qt Creator

I used to program at Qt Creator in linux But now I am working on Windows and Visual Studio (I am forced to it). When I was programming in Qt Creator these features was so great and useful for me:
Opening several cmake project at the same time and easy switching between them.
There was no need to run cmake command in terminal before opening the project and Qt Creator was handling this matter itself. Therefore, if there was any error in CMakeLists.txt I could correct it from inside of Qt Creator
Now, In Windows you should run cmake command in cmd before you open the project in Visual Studio.
Are there any Extensions or Add-on's for Visual Studio to have the mentioned features of Qt Creator for opening a cmake project?
Do you have any other suggestion for working on a cmake project in Visual Studio?
For your first question, Visual studio provide you a complete solution and you can add and switch between projects easily inside a solution. (see differences between projects and solutions in this post)
But for your second question, I don't know any official extension to do that. But once you created a solution with Cmake, you can easily change the CmakeList in VS.
If you insist in doesn't running Cmake commands, you can write an extension for visual studio see this for more information.
No. QtCreator plays better with cmake than Visual Studio. With QtCreator you can open the CMakeLists.txt as a "project" and run the cmake config step directly. With Visual Studio, you must run the initial cmake config (with the generator option) first to generate the projects and solution. With QtCreator you can also open multiple projects (corresponding to multiple top-level CMakeLists.txt files) together. With Visual Studio, you can only open one solution at a time, and each top-level CMakeLists.txt corresponds to a solution.
While QtCreator works better with cmake than Visual Studio, cmake and Visual Studio are still an excellent combination (and as a whole my preferred working toolset)--just one for which you must run the inital cmake configure step before being able to open the solution. Note that it is just the initial cmake config step that is required. Once you have generated the solution and project files and are using the VS IDE, subsequent changes to CMakeLists.txt files or any input files to the configure_file command will cause cmake to reconfigure before VS builds the solution.
Also Visual Studio 2013 works better than 2010 because when you do trigger a cmake reconfigure it will ask you if you want to reload all the projects. VS 2010 will prompt you to reload each one, which is a pain when you have a lot of projects. (I typically have 20-100 projects in a medium to large codebase.) And sometimes VS 2010 will crash with cmake reconfigures. (Nothing is lost--it is just a pain to have the IDE crash and have to re-open it.)
As for other suggestions:
my comment above about automatic reconfigures, is based on not setting CMAKE_SUPPRESS_REGENERATION to ON as suggested in a comment above by drescherjm. (Based on your workflow, this may be a fine way to proceed, it just conflicts with the way I have used cmake/VS and will prevent reconfigures as I described.)
For building you do not have to use the vcvarsall.bat script as described by DevSolar because that is all sorted out by cmake with the -G argument. For a 64-bit build with VS 2013, I use -G "Visual Studio 12 2013 Win64". (Note VS 2010 is vc10, VS 2012 is vc11, and VS 2013 is vc12.) It is still, however, helpful to have a correct runtime environment, which I get using
call "%VS120COMNTOOLS%....\VC\vcvarsall.bat" amd64
You can get a command line build by cd'ing to the build directory (the one containing the generated solution file) and executing
cmake --build . --config Release
You can also specify which project to build by adding --target MyProject
Now (2015), in Windows you should run cmake command in cmd before you open the project in Visual Studio.
Not anymore, with recent version of Visual Studio 19 (2020): See "Build systems and projects"
Open a folder that contains a CMakeLists.txt file.
CMake support is integrated into Visual Studio. You can use the IDE to edit, test and debug without modifying the CMake files in any way. This enables you to work in the same CMake project as others who might be using different editors.
CMake is the recommended approach for cross-platform development. For more information, see CMake projects.
No need to generate any files first.
That is why a project like Git, for instance, will ignore said generated files: they are not needed anymore to open a CMake project:
With Git 2.29 (Q4 2020), using the CMake support added some time ago for real with Visual Studio build revealed there were lot of usability improvements possible, which have been carried out.
See commit 0ad621f (30 Sep 2020) by Junio C Hamano (gitster).
See commit f2f1250, commit b490283, commit 2d9eb4e, commit 8c35e82, commit f1bd737, commit 8f45138 (30 Sep 2020), commit e18ae4e, commit 72b6eeb (28 Sep 2020), and commit 3eccc7b (25 Sep 2020) by Johannes Schindelin (dscho).
(Merged by Junio C Hamano -- gitster -- in commit 8250ab0, 05 Oct 2020)
cmake: ignore files generated by CMake as run in Visual Studio
Helped-by: Đoàn Trần Công Danh
Signed-off-by: Johannes Schindelin
As of recent Visual Studio versions, CMake support is built-in: https://learn.microsoft.com/en-us/cpp/build/cmake-projects-in-visual-studio?view=vs-2019
All that needs to be done is to open the worktree as a folder, and Visual Studio will find the CMakeLists.txt file and automatically generate the project files.
Let's ignore the entirety of those generated files.
That has practical consequence on a project on-boarding.
If we take the example of a project like Git, again:
cmake (Windows): initialize vcpkg/build dependencies automatically
Signed-off-by: Johannes Schindelin
The idea of having CMake support in Git's source tree is to enable contributors on Windows to start contributing with little effort. To that end, we just added some sensible defaults that will let users open the worktree in Visual Studio and start building.
This expects the dependencies (such as zlib) to be available already, though. If they are not available, we expect the user to run compat/vcbuild/vcpkg_install.bat.
Rather than requiring this step to be manual, detect the situation and run it as part of the CMake configuration step.
Note that this obviously only applies to the scenario when we want to compile in Visual Studio (i.e. with MS Visual C), not with GCC. Therefore, we guard this new code block behind the MSVC conditional.
This concludes our journey to make it as effortless as possible to start developing Git in Visual Studio: all the developer needs to do is to clone Git's repository, open the worktree via File>Open>Folder... and wait for CMake to finish configuring.

How do I build boost with Visual Studio 2008 when I have multiple Visual Studio versions installed?

I know how to build boost with the latest visual studio on my machine (this question, for example)
However, I need to build the libs for Visual Studio 2008 (vc9)
I tried using toolset=vc9 but I get problems/no success.
How can I build the libs for vc9?
After I run boostrap I try running
b2 toolset=vc9
but the output is:
C:/Development/boost
50/boost_1_50_0/boost_1_50_0/tools/build/v2/build\toolset.jam:39: in
toolset.using rule vc9.init unknown in module toolset
C:/Development/boost
50/boost_1_50_0/boost_1_50_0/tools/build/v2\build-system.jam:481: in
process-explicit-toolset-requests
C:/Development/boost
50/boost_1_50_0/boost_1_50_0/tools/build/v2\build-system.jam:562: in
load
C:\Development\boost
50\boost_1_50_0\boost_1_50_0\tools\build\v2/kernel\modules.jam:283: in
import
C:\Development\boost
50\boost_1_50_0\boost_1_50_0\tools\build\v2/kernel/bootstrap.jam:142:
in boost-build
C:\Development\boost 50\boost_1_50_0\boost_1_50_0\boost-build.jam:17:
in module scope
toolset=msvc-9.0
I have VS2008-Pro and VS2010-Express installed. The default ran with VS2010. Setting toolset=msvc-9.0 caused the build to run with VS2008. Using Boost 1.51.0.
You'll need to dig into the How-To-Build-Boost documentation, and in particular see this;
but the part you need to specify a particular MSVC version is pointed to here. That suggests creating a user-config.jam, which probably would work, but I created a project-config.jam file instead.
I seem to be able to do this by running the top-level boost build (or meta build) script from different VC command lines. For example to build with VC2012, start a command line with vc 2012 vars. And for 2010, do the same. The automatically generated build scripts seem to do the right thing.
I am sure there are ways to do this by editing the build scripts myself or by setting the toolset, but I had no success with that.