Search code examples
ccmakecompilationclion

CLion says 'Process finished with exit code 127'


So I am running a sample c code Hello World project that appears when you make a new c project:

main.c:

#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.15)
project(untitled1 C)
set(CMAKE_C_STANDARD 99) 
add_library(untitled1 library.c library.h main.c)

When I press Run, earlier it was giving me "error 12, permission denied" so I modified the file permissions. Now I am getting the following in the Run window:

/Users/alan/CLionProjects/untitled1/library.c

Process finished with exit code 127

I googled but cant seem to find any solution.

The following is the image of the preferences:

enter image description here enter image description here


Solution

  • You are trying to run a library. Modifying file permissions by hand is not the way to make it work, you could as well try running an arbitrary random file.

    In order to make an executable, you need to use add_executable.

    What you are running is not called an object file. I recommend reading some introduction like this one.

    Also, if you want to create a library and link against it, you need to describe it with add_library using library.c, and then an executable with add_executable using main.c. Then link the executable to the library with target_link_libraries. Here's a CMake tutorial that may help.