Reputation: 431
I am trying to compile a very simple ("hello world!" like) C program with Clion, but I am keep failing.
this is my code:
#include "main.h"
#include <stdio.h>
int main() {
printf("hi hi hi\n");
return 0;
}
main.h:
#ifndef EXONE_HELLO_H
#define EXONE_HELLO_H
#endif //EXONE_HELLO_H
nd my make file:
cmake_minimum_required(VERSION 3.3)
project(exone)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra -Wall -Wvla -std=c99")
set(SOURCE_FILES main.c main.h)
add_executable(exone ${SOURCE_FILES})
but I get this message:
/dist/local/x86_64.debian64-5776/jetbrains/clion-1.1/bin/cmake/bin/cmake
--build /tmp/.clion-oarzi/system/cmake/generated/48ee084e/48ee084e/Debug
--target exone -- -j 4
[ 50%] Building C object CMakeFiles/exone.dir/main.c.o
cc: error: -Wextra: No such file or directory
cc: error: -Wall: No such file or directory
cc: error: -Wvla: No such file or directory
cc: error: -std=c99: No such file or directory
CMakeFiles/exone.dir/build.make:62: recipe for target
'CMakeFiles/exone.dir/main.c.o' failed make[3]: ***
[CMakeFiles/exone.dir/main.c.o] Error 1 CMakeFiles/Makefile2:67:
recipe for target 'CMakeFiles/exone.dir/all' failed make[2]: ***
[CMakeFiles/exone.dir/all] Error 2 CMakeFiles/Makefile2:79: recipe for
target 'CMakeFiles/exone.dir/rule' failed make[1]: ***
[CMakeFiles/exone.dir/rule] Error 2 Makefile:118: recipe for target
'exone' failed make: *** [exone] Error 2
also, this happen when I just compile with gcc using the console, and when I
change CMAKE_C_FLAGS
to CMAKE_CXX_FLAGS
everything works fine (even if I
change only in the first of two places).
Update: It appears I used minus signs instead of dashes. now I get only one CC error:
`cc: error: unrecognized command line option ‘-Wvla’`
Upvotes: 1
Views: 2439
Reputation: 1518
In your variable SOURCE_FILES
you don't need the header file, because it will be found by the compiler. You also need the qoutes for it to work.
set(SOURCE_FILES "main.c")
add_executable(exone "${SOURCE_FILES}")
Also you need to set the compiler options with a dash infront for all compiler options (you missed the one for -Wextra
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra -Wall -Wvla -std=c99")
Now your CMakeLists.txt should look like this
cmake_minimum_required(VERSION 3.3)
project(exone)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra -Wall -Wvla -std=c99")
set(SOURCE_FILES "main.c")
add_executable(exone "${SOURCE_FILES}")
Upvotes: 1