Use Clang with MSVC 2010 - visual-c++

First of all, I want to ask if Clang compiler is better than MSVC's default compiler? And how can I use Clang with MSVC? For example, I write code in MSVC then when I hit Build, it call Clang to build the project.

https://github.com/ishani/ClangVSx
AddIn for Visual Studio 2010 that allows use of the Clang C/C++ compiler in place of MSVC++. Translates VC project and build settings into gcc-friendly command line arguments, along with existing platform tools (MSVC Linker, Librarian, RC) to complete the build chain.

Using clang compiler on Windows is still considered to be in experimental state. However, some progress has been made recently. As I answered similar question:
LLVM provides Windows snapshot builds - a clang toolset for Visual Studio as Windows installer. Currently it should integrate with Visual Studio 2010, 2012 and 2013. More information can be found on LLVM's blog post A path forward for an LLVM toolchain on Windows.

You can use a "makefile project" to have Visual Studio invoke a makefile (or any command-line process) when you tell it to build.
I've done this before to get MSVC's nice source navigation for non-Windows embedded projects.
The drawback is that you have to manually keep the makefile in sync with the files in the project (or vice-versa depending on how you want to look at it) - generally not a huge problem.

Related

CMake to create a Visual Studio Code project

Does any know if there are any efforts for cmake to generate a Visual Studio Code project (not to be confused with Visual Studio)? IE
cmake -G "Eclipse CDT4 - Unix Makefiles"
not for eclipse, but for Visual Studio Code? This would be awesome for linux projects.
As already mentioned, VS Code has the vscode-cmake-tools extension to integrate with CMake projects.
See here for documentation on what features it has to offer. You will see that building and debugging within the IDE are supported.
The design of VS Code is very much centered around being simple and extensible, whereas Visual Studio is more of a monolith and includes its own build system for C++. VS Code is not monolithic like that.

Configure Visual C++ project to use the 64-bit tool set when building 32-bit executable

I am trying to enable link-time codegen (LTCG) and whole program optimization (WPO) for the build of a large Windows C++ application built with Visual Studio 2017. The 64-bit product builds fine but the codegen step of our 32-bit build runs out of memory.
So, I need to switch the 32-bit builds to use the 64-bit link.exe as described here: How to: Enable a 64-Bit, x64 hosted Visual C++ toolset on the command line
Specifically:
The 32-bit and 64-bit tools generate identical code, but the 64-bit tools support more memory for precompiled header symbols and the Whole Program Optimization (/GL and /LTCG) options. If you run into memory limits when you use the 32-bit tools, try the 64-bit tools.
It describes doing this from a command line build but I need it within the devenv environment. I have searched unsuccessfully for a Solution or Project setting to control using the 64-bit tool set for a 32-bit build.
I suspect I'll need to edit the .vcxproj file directly but am not sure what to add. Can anyone tell me how to setup my 32-bit build this way?
An alternative answer is to use PreferredToolArchitecture in the project.
Using Visual Studio 2019 (v16.1) this can be done in the properties dialog of the project under "Configuration Properties\Advanced\Prefered Build Tool Architecture". Specify x64.
For older versions of Visual Studio, editing the vcxproj is required. This is documented in Walkthrough: Using MSBuild to Create a Visual C++ Project
<PropertyGroup>
<PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>
Found my own answer... You do need to hand-edit the .vcxproj file and add this to the PropertyGoup
<UseNativeEnvironment>true</UseNativeEnvironment>
So mine now looks like this:
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<UseOfMfc>Dynamic</UseOfMfc>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<UseNativeEnvironment>true</UseNativeEnvironment>
</PropertyGroup>

Add reference to CMake project in Android Studio

In my particular case, I implemented a cross platform project in C++11 that uses CMake. I initially designed this project to work on PC (Windows, Unix), but now I realized that I can use it on mobile platforms too, without re-implementing the business logic on every platform. The project uses standard libraries: Boost, Poco, OpenSSL, Protobuf.
After a few searches I came to conclusion that this is not even an usual mode to put together native and managed code in Android.
Is it possible to add reference in a Gradle project in Android Studio to a native project that uses CMake?
Can NDK adopt the project in a simple manner if I compile everything in command line (assuming I don't use Android Studio)?
If it is possible, is it recommended at all?
Is it possible to add reference in a Gradle project in Android Studio to a native project that uses CMake?
Since Google announced Android Studio 2.2 that comes with cmake plugin, so it's possible to reference CMake project to android project.
Can NDK adopt the project in a simple manner if I compile everything in command line (assuming I don't use Android Studio)?
In my experience, i compile NDK in separate way and then link the static/shared library (.so file) to be used in android project. I used NDK while developing PDF Reader using mupdf here
Hope this helps.
it would be possible with android studio 2.2, mainly the android plugin for gradle makes it possible. you could look at some examples in:
https://github.com/googlesamples/android-ndk/tree/master-cmake
android studio directly reads-in your cmake scripts -- there is nothing like desktop systems that generate project files for their native IDEs ( Visual Studio or XCode ); so you might have to modify your existing cmake files to eventually make it to work for android studio.
as long as you build to the correct APK, command line or IDE does not matter too much. If you intend to ship source code, having your project ready with an IDE would be attractive.
Please see CMaker_Boost, build the Boost with the CMake at a configure time. Now it is tested on the Linux and Android, gcc and clang. This can be included to the gradle project in the Android Studio. I hope this helps.

Can I use Visual Studio for developing Linux C or C++?

I have to develop something in Linux(CentOS 6.5) Environment using C or C++ language with many of libraries for linux.
As you know, CentOS is not GUI. So, I want to use Microsoft Visual Studio for my work. It's OK even if use just VS as the Editor.
I mean that I like the features of IDE visual studio(intellisense, debugger, and so on).
I have Visual Studio 2008, 2010, 2013 Professional.
yes you can, in fact, if you have setup a VM machine, you can even directly include the C++ include library of Linux (However, this only works for write code, not work with compiling). You could also setup CYGWIN or MINGW for referencing the header of Linux platform.
In fact, for myself, I switched to QtCreator as a cross platform C++ IDE, it also has auto-complete and debug features.

Makefiles for Microsoft Visual C++

I have few queries regarding makefiles for MSVC. I want to create makefiles which will compile my project on Visual C++ compiler. One thing I found in the web named "nmake" which is said to be the makefiles for MSVC(correct me if I am wrong).
So, I introduced myself with nmake and compiled a single source file successfully with this. But the issue is, I need to run this nmake file using command prompt of visual studio. I haven't found a way to use the file in normal command prompt. Is it really possible?
Suppose, I don't have a visual studio installed. I have only the visual C++ compiler. Then how I will be able to compile my projects using nmake?
One Additional question, if I have only visual C++ compiler installed(like the old compilers eg. microsoft visual C++ 2005), then is it certain that I will get nmake command on this?
Thanks in advance.
Solved! Answering myself, so that if anyone intend to compile makefiles using nmake for Visual C++ compiler.
Yes, it is compiles in older version of visual C++ also. I have tested and it works fine. But it may cause problems when some properties are use of latest visual C++ compiler. Because you will not find those properties in older version of C++ compiler. Otherwise it is quite OK.

Resources