How to set C or C++ compiler for CMake

Updated post here:

7 thoughts on “How to set C or C++ compiler for CMake

    1. Einpoklum: Thanks for sharing that. Indeed, Method 1 and 2 listed in the FAQ are more elegant.

      However, in my case I wanted to use GCC for normal compilation and Intel compiler for my CMake project, so Method 1 was not suitable. Method 2 was not suitable cause our team was not interested in passing command line arguments to CMake.

      Liked by 1 person

  1. Thanks to both for the response. I have a related problem: I need to modify the compile line from ‘gcc [args]’ to ‘/usr/local/bin/fubar gcc [args]’. Where ‘fubar’ is an executable to performs instrumentation while it invokes the gcc command with [args].
    As I understand from the above replies and from the CMake FAQ, setting GCC to ‘/usr/local/bin/fubar gcc’ will NOT work since CMake treats the value of GCC as a single string that is a full path to an executable (and it checks that it exists).


  2. I want to work on project that needs make, cmake and mingw so i need to setup my environment so that cmake can access a compiler(g++ or gcc). I have install all the tools and i’m having errors tell cmake where to find the compiler either by setting the environment variable ‘CC’

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.