# CMake is forcing MSVC to use C compiler on C++ code

**URL:** <https://discourse.cmake.org/t/cmake-is-forcing-msvc-to-use-c-compiler-on-c-code/1463>\
**Category:** Code\
**Created:** [June 30, 2020, 4:11am UTC](https://discourse.cmake.org/t/cmake-is-forcing-msvc-to-use-c-compiler-on-c-code/1463 "2020-06-30T04:11:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnratius](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johnratius/32/412_2.png) [@johnratius](https://discourse.cmake.org/u/johnratius)\
**Post date:** [June 30, 2020, 4:11am UTC](https://discourse.cmake.org/t/cmake-is-forcing-msvc-to-use-c-compiler-on-c-code/1463/1 "2020-06-30T04:11:56Z")

</div>

I have no idea what I did; I am trying to compile C++ code and CMake on CLion chooses the Visual Studio C compiler to compile it. When I don’t use CMake, it runs fine.

main.cpp:

```
#include <iostream>
#include "include/Window.hpp"

int main()
{
  Window * window = new Window();
  return 0;
}

```

Window.hpp:

```
#ifndef WINDOW_HPP
#define WINDOW_HPP
class Window
{
	public:
	Window();

};
#endif //WINDOW_HPP

```

Window.cpp is empty

CMakeLists.txt:

```
cmake_minimum_required( VERSION 3.16 )
set( CMAKE_CXX_STANDARD 14 )
project( myProject )

include( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/App.cmake" )

set( SOURCES
    main.cpp
    src/Window.cpp
    include/Window.hpp

    )
make_app(
    SOURCES ${SOURCES}
)

```

App.cmake:

```
include( CMakeParseArguments )

set( USED_PATH "../" )

function( make_app )

# parse arguments that come through function
set( oneValueArgs NAME PATH)
set( multiValueArgs SOURCES INCLUDES LIBRARIES )
cmake_parse_arguments( ARG "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

# make sure name is set for app
if( NOT ARG_NAME )
    set( ARG_NAME "${PROJECT_NAME}" )
endif()

# set path
if( ARG_PATH )
    set( USED_PATH ${ARG_PATH} )
endif()

include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/include" )

# setup GLAD
include_directories( "extern/glad/include" )
list( APPEND PROJECT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/extern/glad/include/glad/glad.h" )
list( APPEND PROJECT_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/extern/glad/src/glad.c" )

# setup GLFW
find_package( OpenGL REQUIRED )

include_directories( "extern/glfw/include" )
include_directories( ${OPENGL_INCLUDE_DIRS} )

set( GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE )
set( GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE )
set( GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
set( GLFW_BUILD_INSTALL OFF CACHE BOOL "GLFW lib only" FORCE )

add_subdirectory( extern/glfw )

# add argument sources to project sources
list( APPEND PROJECT_SOURCES ${ARG_SOURCES} )

# the executable, using the argument name and project sources
add_executable( ${ARG_NAME} ${PROJECT_SOURCES} )
target_link_libraries( ${ARG_NAME} ${OPENGL_LIBRARIES} glfw ${GLFW_LIBRARIES} )

endfunction()

```

That is actually all the code I have. I have a feeling that somewhere in App.cmake this is causing this issue.  
Would anyone mind to explain why this is happening and how to fix it?

---

<div class="post-metadata">

**Author:** ![robert.maynard](https://discourse.cmake.org/user_avatar/discourse.cmake.org/robert.maynard/32/4_2.png) [@robert.maynard](https://discourse.cmake.org/u/robert.maynard)\
**Post date:** [July 1, 2020, 1:19pm UTC](https://discourse.cmake.org/t/cmake-is-forcing-msvc-to-use-c-compiler-on-c-code/1463/2 "2020-07-01T13:19:58Z")

</div>

> I am trying to compile C++ code and CMake on CLion chooses the Visual Studio C compiler to compile it.

In general this is pretty hard to do as the Visual Studio compiler and CMake both prefer C++ over C.

> add\_subdirectory( extern/glfw )

My initial guess it that something in `glfw` is somehow forcing everything to be C instead of C++.
