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

  • Question

  • Hi,

    Using Visual Studio 2017, I have a C++ Linux project which currently connects to a remote Linux machine (CentOS 7)

    I have both GCC 4.8.5 and GCC 7.2.1 installed on the CentOS machine

    How can I instruct Visual Studio to use the GCC 7.2.1? Currently it always defaults to 4.8.5.

    I have tried adding the following to the Remote Pre-Build Event:

    source scl_source enable devtoolset-7

    scl enable devtoolset-7 bash

    export CC=/opt/rh/devtoolset-7/root/usr/bin/gcc

    export CXX=/opt/rh/devtoolset-7/root/usr/bin/cpp

    export CPP=/opt/rh/devtoolset-7/root/usr/bin/c++

    But no matter what I try the project always builds using GCC 4.8.5.

    If I log on to the Linux machine, terminal window and type "scl enable devtoolset-7 bash" followed by "gcc --version" I get "gcc (GCC) 7.2.1 20170829 (Red Hat 7.2.1-1)"

    Wednesday, April 11, 2018 9:38 PM

Answers

  • Hi,

    thanks for posting here.

    >>VS Linux Project - How to target different GCC versions?

    You could override the compiler commands used on the remote machine in the Property Pages on the C/C++ General Property Page. That will enable you to point to specific versions of GCC if needed or even point to an alternate compiler like clang. You can use either full paths or a command available on your path.

    For more information, please refer to this document below.

    https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/

    Hope this could be help of you.

    Best Regards,

    Baron Bi


    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.

    • Marked as answer by JonesJ76 Thursday, April 12, 2018 8:14 AM
    Thursday, April 12, 2018 6:24 AM

All replies

  • Hi,

    thanks for posting here.

    >>VS Linux Project - How to target different GCC versions?

    You could override the compiler commands used on the remote machine in the Property Pages on the C/C++ General Property Page. That will enable you to point to specific versions of GCC if needed or even point to an alternate compiler like clang. You can use either full paths or a command available on your path.

    For more information, please refer to this document below.

    https://blogs.msdn.microsoft.com/vcblog/2016/03/30/visual-c-for-linux-development/

    Hope this could be help of you.

    Best Regards,

    Baron Bi


    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.

    • Marked as answer by JonesJ76 Thursday, April 12, 2018 8:14 AM
    Thursday, April 12, 2018 6:24 AM
  • Baron, thanks for pointing me in the right direction, I'd already read that URL you provided and looked through the Property pages several times but clearly missed that vital setting.

    In the Configuration Properties -> C/C++ -> General
    I changed both the C Compiler and the C++ Compiler values from just "g++" to the full path "/opt/rh/devtoolset-7/root/bin/g++"
    VS is now happily building with gcc 7.2.1

    Thanks for your help

    Thursday, April 12, 2018 8:14 AM