Targetting Linux with Visual Studio 2017 and CMake

697 views Asked by At

I'm trying to target a simple CMake-based project to Linux (x86) from VS2017.

CMakeLists.txt

project (hello-cmake)
add_executable(hello-cmake hello.cpp)

hello.cpp

#include <iostream>

int main(int argc, char* argv[])
{
    std::cout << "Hello from Linux CMake" << std::endl;
}

My setup:

  • Visual Studio 15.8.2 running on Win7
  • Ubuntu 16.04
  • CMake 3.12.1
  • g++ 5.4.0, gcc 5.4.0

I've carefully read the instructions on MSDN's website, but cannot get it to work.

Using the default CMakeSettings.json generated by VS, the rsync command proceeded to wipe my '~' directory!

Below the command as it appears in VS:

rsync -t --delete --delete-excluded -v -r --exclude=.vs --exclude=.git --exclude=.vs --exclude=.git  /D/JP/svn/mirtec/test_cmake_vs2017/ rsync://alex@localhost:60584/temp

I understand what the --delete --delete-excluded does. But I do not understand why is it targeting my home directory?

How am I meant to specify the location on the target machine where the files will be copied (I thought it was remoteCMakeListsRoot, but my experience shows it is not).

Am I meant to create a dedicated user for VS/CMake debugging?

I edited the CMakeSettings.json to remove the "--delete --delete-excluded" options. As result rsync stops trying to wipe ~, but now VS says it cannot find CMake! I am completely stuck. I have installed CMake and it is available in /usr/local/bin. I have tried with and without the name of the program to cmakeExecutable in the json file to no avail.

This is the output in VS:

1> Copying files to remote machine...
1> rsync -t -v -r --exclude=.vs --exclude=.git --exclude=.vs --exclude=.git  /D/JP/svn/mirtec/test_cmake_vs2017/ rsync://alex@localhost:56138/temp
1> sending incremental file list
1> ./
1> CMakeSettings.json
1> 
1> sent 828 bytes  received 42 bytes  580.00 bytes/sec
1> total size is 1349  speedup is 1.55
1> Finished copying files.
1> /usr/local/bin/cmake does not exist

Is there anyone out there using the VS2017 / CMake integration to target Linux successfully? Have you had similar issues? Am I missing something?

1

There are 1 answers

0
jagger2048 On

I met the same error as yours but finally solved it.

  • 1 Check weather the cmake is installed in you linux or not.

  • 2 Find the CMakeSetting.json file in your vs2017 project,it is automatic generated by vs2017 when building, the problem is in this file.

    Check the "cmakeExecutable": "/usr/bin/cmake" option,and make sure the path is the same as your remote linux.(use which cmake to check the path ).As your mentioned,the "cmakeExecutable": /usr/local/bin/cmake should be "cmakeExecutable": /usr/bin/cmake.