peeeeeelz
peeeeeelz

Reputation: 3

Make C Project Instead of C++

I am having trouble setting up a C projectin Clion. I changed the name of the main.cpp to main.c, and altered the CMakeLists file accordingly, with the following info:

cmake_minimum_required(VERSION 3.3)
project(Project_1__)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.c)
add_executable(Project_1__ ${SOURCE_FILES})

However I get the following error when I try to build:

fatal error: iostream: No such file or directory #include compilation terminated. mingw32-make.exe[3]: * [CMakeFiles/Project_1__.dir/main.c.obj] Error 1 mingw32-make.exe[2]: * [CMakeFiles/Project_1__.dir/all] Error 2

Upvotes: 0

Views: 204

Answers (3)

Harnirvair Singh
Harnirvair Singh

Reputation: 593

This error is due to fact that your complier is unable to find iostream header file. Make sure it exists in that directory. Plus it also depends on your IDE.

Also make sure, it is declared as #include "iostream.h" instead of #include<iostream.h>

iostream header files are declared in many of the compilers is declared by #include<iostream>

C++ needs <iostream> header file while C needs only <stdio.h>

Upvotes: 1

Craig Estey
Craig Estey

Reputation: 33631

Replace #include <iostream> with #include <stdio.h>. You'll also have to replace the stream related stuff in your code with stdio functions. See man stdio.

Also, you may have to change your makefile as I see -std=c++11 and I suspect that should be -std=c11. I'm not completely clear on this, so YMMV

Upvotes: 1

milevyo
milevyo

Reputation: 2184

iostream.h is specific to c++, c do not use stream classes

Upvotes: 0

Related Questions