How can I setup CMake for use with Visual Studio 2017RC and CUDA 8.0? - c++

Visual Studio 2017 RC includes much tighter CMake integration, allowing one to skip the intermediate step of generating project/solution files and use CMake effectively as the project file itself. There is sufficient documentation from Microsoft for using these features with regular C++ files, and there is sufficient documentation on this website (example) for making CUDA and Cmake play nicely, when it comes to linking CUDA code to C++ code.
What I can't find information on is how to make CMake, Visual Studio 2017 RC, and CUDA 8.0 all play nicely. This is a difficult problem, because 2017RC has no integration for the CUDA SDK anyways, and I was hoping to use 2017RC so that my C++ interface to the CUDA code could use C++14 and/or C++17. I'm working on the beginning of a large project that will primarily involve writing a static CUDA library that is accessed through C++: so, I'd like to get the CMake to take care of compiling my CUDA sources into a static library, and for it to help with feeding the linking information to Visual Studio. So far, I haven't had any success with using FindCUDA's various features to accomplish this, but I'm assuming that's due to a misunderstanding on my part. I've read through the documentation on separable compilation from Nvidia, but that wasn't helpful for figuring out CMake.
Further, whenever I try to use CMake in VS2017RC, I still end up with the various vcxproj files that CMake likes to spit out. Is this due to an error on my part? How do I edit the build command arguments, or CMakeLists.txt, to get the functionality demonstrated here to work?

The very short (and only at the time of writing) answer is that you can't. CUDA 8 doesn't support VS2017. Only VS2015 is presently supported.
You can always find the compiler/IDE versions which the release version of CUDA supports here
Edit to add that the CUDA 9 release will add official support for VS2017.

All you need to do is set the CUDA_HOST_COMPILER variable to a supported compiler for example the visual studio 2015 compiler.
In my case this is:
C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe
As both runtime libraries are binary compatible you can use the 2015 compiler within CUDA and compile all the rest of the application with the 2017 compiler.

Related

Is there a way to force Visual studio 2017 to accept a CMAKE 2.8.12.2

So I am trying to build a basic C++ project on our university Linux server.
I went and checked the CMake version on the server, it is 2.8.12.2
I love using Visual Studio, so i tried using Visual Studio after SSH into my university server to build a basic hello world program on it.
I got the following message in my Visual Studio 2017:
CMake 3.8.x or above is not available on the remote system. See https://aka.ms/linuxcmakeconfig for more info
Is there a way to forcibly make Visual Studio accept a lower version of CMake 2.8.12.2
I made changes to the CMakeLists.txt as follows:
cmake_minimum_required(VERSION 2.8.12.2).
But still Visual Studio was complaining about not having CMake version 3.8 in the University server.
I've attached the screen shots below:
I was told to use some IDE called CLion. But I know Visual Studio is the better option, having used it all my life in the real world/non-university setting.
TL;DR
No, it's not possible.
Reason
The Visual Studio 2017 documentation states here:
The CMake support in Visual Studio requires server mode support introduced in CMake 3.8.
This means VS requires the cmake-server(7) API to query information like where CMake puts the built binaries, what include paths are used, etc. Without this information, VS would not be able to provide all the useful features of an IDE such as debugging, include path checks/auto-completion, etc. So there is no way, the CMake integration of VS (or any other IDE like CLion) is going to work with an CMake version that does not provide the server mode yet, which is definitely the case for all 2.x versions.
More Background
The server mode was actually introduced in CMake 3.7. I don't know why the VS docs suggest it's 3.8 🤷‍♂️. But I guess that's not an important difference for your case anyway.
Newer versions of Visual Studio (since 2019) even use the more recent cmake-file-api(7) introduced in CMake 3.14 as stated here:
Cmake version 3.14 or later should be installed on the target machine.
The server mode was even deprecated in 3.15 and completely removed in 3.20 in favor of the file-based API.
The VS devs even maintain their own CMake fork: github.com/microsoft/CMake.
This is because the server mode didn't provide them all the information they needed, as stated in their blog:
One of the differences in our CMake fork on github was the backtrace information needed for our Targets View feature inside Visual Studio. Prior to CMake 3.14 we needed the CMake version from our fork, in order for Targets View to work properly. Now, with the file-based API this is no longer required.
So maybe with VS 2017 you should use a CMake binary built by Microsoft. For VS 2019+ the "stock" CMake should probably be fine. As of now, they still maintain their fork, but I haven't found any source that indicates you're required to use it. Probably because Microsoft has become more involved in the CMake development the last couple of years and contributes to the upstream repository as well, e.g. cmake-presets(7) is the result of a cooperation between Microsoft and Kitware.
Recommended Solution
As #Shawn already commented, CMake 2.8.12 is seriously outdated (released 2013-10-08) and the best solution would be to ask the admin of your University to update CMake to a more recent version. This has the additional advantage, that you can use and benefit from the "Modern CMake" techniques.

Building OpenCV 3.0.0's DLLs for Visual Studio 2015 with Cmake

Following the instructions here:
docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html#windows-visual-studio-how-to
I setup an OpenCV project in VS 2015 Community and used the pre-built libraries. It works until I get this message:
"MSVCP120D.dll is missing from your computer"
From doing some searching I gathered this means that the pre-build libraries are only supposed to be used with an older version of VS so I figured I'd just compile them myself using this:
docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html#windowssetpathandenviromentvariablehere
While it appears to compile properly and despite flagging "BUILD_SHARED_LIBS" I can't find any DLL files in the output - just a lot of VS solutions:
imgur.com/JdSc5CH
Would someone be able to give me some advice on how to generate the DLLs?
thanks!
I'm a beginner at this stuff. I've since learned a lot about Visual Studio, about CMake and about OpenCV. Got it all working now, took me a day or two.
It turns out you have to compile the openCV library from git repository in order to be compatible with Visual Studio (VS14) 2015. As of this date, no go on pre-compiled version supporting VS14.
I've organized what I've learned, placed it online here in case anybody else has the same frustrations. Its pretty detailed, too much content to post here.
VS2015 uses MSVCP140.dll, I think your error message is about a redistributable package of VS2013.
And try BUILD_SHARED_LIBS as on/off.

Is it possible to create WinRT project with cmake?

To create WINRT project we need to have CMake >= 2.8.10 and:
Set project type to be Windows Store App(CMAKE: SET_TARGET_PROPERTIES(target PROPERTIES VS_WINRT_EXTENSIONS TRUE)
Add compiler flag /ZW for WinRT compilation(CMAKE: ADD_DEFINITIONS(-ZW))
Add App.xaml.h, App.xaml.cpp
Add App.xaml so VS will generate some additional files from it(CMAKE: HOW?)
Add Package.appxmanifest with description so VS will use it(CMAKE: HOW?)
Thank you.
UPDATE: CMake bug report referring to this question is here 0013749: Cannot target Windows 8 RT from CMake without workarounds.
CMake guys are working on it:
Bug report at cmake.org
This is perfectly doable. Things have considerably changed since this question was initially asked. The most significant changes are:
Visual Studio natively supports CMake since Visual Studio 2017 (see CMake support in Visual Studio). It's not longer required to separately download CMake, and have it generate .sln and .vcxproj files. CMake is part of the Visual Studio installation, and can be parsed by Visual Studio's project management infrastructure and build system.
C++/CX is no longer the only way to produce and consume Windows Runtime components. C++/WinRT provides a standard C++ language projection of the Windows Runtime API surface, with the ability to consume and produce Windows Runtime components.
With these changes you can use CMake to create a C++ project that builds a Windows Runtime application. C++/WinRT is standard C++, and Visual Studio 2017 provides built-in CMake support.

How to build o2scl with visual studio?

I want to build o2scl with visual studio. o2scl is a C++ wrapper for a GNU library. Seems like I have to use a configure and make file, some install instructions are available here. I guess they are targeted for the gcc compiler. I have never done this kind of thing before. I was wondering if anyone could tell me how to do this or point me to somewhere I can get upto speed on building these types of libraries with visual studio?
Thanks for reading
I'm the O2scl lead developer. I have indeed installed O2scl with compilers other than gcc (Pathscale, Intel C, etc.), but it appears that compilation with visual studio will
take a bit more effort. the O2scl directory and makefile structure is very similar to that used by GSL (GNU Scientific Library), so whatever visual studio files are necessary for GSL
will probably be adaptable for O2scl. See
http://gladman.plushost.co.uk/oldsite/computing/gnu_scientific_library.php
for an example of someone who's designed a system for installing GSL in visual studio.
Note that O2scl requires GSL so you might have to start by installing GSL first. I'm
away on travel this weekend, but I will check this out next week if I can.

Is it possible to compile ffmpeg in visual studio 2010?

Is it possible to compile the sourcecode from ffmpeg in visual studio 2010? Is it difficult?
Just looking for some advice (and instructions) if possible. :-)
Cheers,
Pete
Apparently someone at Google has written a C99 to C89 "downconverter" in part to get ffmpeg to compile with Visual Studio:
http://blogs.gnome.org/rbultje/2012/09/27/microsoft-visual-studio-support-in-ffmpeg-and-libav/
The tool they wrote is currently only in source code form. Although that tool is written in C, it uses some compiler specific includes, specific to the Clang compiler, so you currently need clang to compile it. I had to get all the pieces to Clang (which relies on llvm) and compile with VS2010. OK, got that figured out, so now I have the two tools compiled: c99wrap.exe and c99conv.exe.
The blog does not mention two important things that are mentioned here:
http://libav.org/platform.html#Microsoft-Visual-C_002b_002b
First, you have to ensure the link.exe you use is the Visual C linker and not the mingw linker. Also, the msvc toolchain under msys does not yet support shared DLL builds, it only supports static lib builds at this time, so --enabled-shared fails to link.
It is not possible because ffmpeg makes extensive use of C99 features (with good reason), and MSVC doesn't support nearly enough nook and crannies of the standard.
You can however, use the C library built by MinGW for use with Visual Studio projects. See the following links for all the information you need:
Information about building/using the library on Windows with Visual Studio: http://ffmpeg.arrozcru.org/wiki/index.php?title=Main_Page
Downloads: http://ffmpeg.arrozcru.org/autobuilds/
Of course it is possible
To use FFmpeg SVN libraries with your Microsoft Visual C++ project,
you must first make sure your Microsoft Visual C++ build system has
the inttypes.h and stdint.h include files.
How do I know if I have those files? Well... unless you already did
this and know you have that file, you don't have it. MSVC++ does not
adhere to the C99 standard, where that file is specified, so you're on
your own here.
Alexander Chemeris was nice enough to make such files for Microsoft
Visual C++, so they can be found here
Download latest archive from link above and unpack it to the folder to
which you installed FFmpeg's include files. The default path is
/usr/local/include, which is, in this guide for Windows,
C:\msys\local\include.
Inttypes C99
Visual Studio 2013 provides the support for C99 which was missing earlier. With this ffmpeg can now be built using Visual Studio 2013. You can read more about the new language/libraries features here.
Also, try out Visual Studio 2013 RC here.
According to the documentation it is not possible.