none
VS Linux Project - How to target different GCC versions (2) ? RRS feed

  • Question

  • Hi, I am trying to configure Visual Studio 2017 to remotely build a C++ project using CMake on a Linux machine.  The build must use the Red Hat SCL compiler collection, not the default gcc compiler on the machine.

    I have specified a prebuild command in CMakeSettings.json:

          "remotePrebuildCommand""source scl_source enable devtoolset-7"

    I'm not sure that that will force the scl to be used.  I guess the correct headers won't be downloaded to the local machine for Intellisense's used.

    A similar question was asked here:

    https://social.msdn.microsoft.com/Forums/en-US/435b4d50-53f1-4c76-a9d1-239ed47c65e8/vs-linux-project-how-to-target-different-gcc-versions?forum=vcgeneral

    The answer given was to specify the compiler in the Configuration Properties -> C/C++ -> General.  But, is that only for a Visual Studio Project?  i.e. not for a CMake project?

    How would I specify the compiler for a CMake project?

    Tuesday, December 10, 2019 5:16 PM

Answers

  • Thanks for your answer. The following worked for me:

    -D CMAKE_CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/g++


    • Marked as answer by DavidTML Thursday, December 12, 2019 10:14 AM
    Thursday, December 12, 2019 10:14 AM

All replies

  • Hello,

    Thank you for posting here.

    When there are multiple C/C++ compilers in the system, CMake is required to compile with the specified compiler.

    For example: gcc/g++, Visual Studio 2015, the default setting of CMake is gcc/g++, if I need to generate VS Project.

    Modify CMakeLists.txt and add set (CMAKE_GENERATOR "Visual Studio 14 2015 Win64")

    Best Regards,

    Suarez Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 11, 2019 8:24 AM
  • Thanks for your answer. The following worked for me:

    -D CMAKE_CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/g++


    • Marked as answer by DavidTML Thursday, December 12, 2019 10:14 AM
    Thursday, December 12, 2019 10:14 AM