Skip to content

Instantly share code, notes, and snippets.

@hosackm
Last active January 6, 2025 19:20
Show Gist options
  • Save hosackm/c3e34d75a1f4496b6f5aec1803aa2032 to your computer and use it in GitHub Desktop.
Save hosackm/c3e34d75a1f4496b6f5aec1803aa2032 to your computer and use it in GitHub Desktop.
C project template
BasedOnStyle: LLVM
BreakBeforeBraces: Allman
AllowShortFunctionsOnASingleLine: false
CompileFlags:
CompilationDatabase:
./build

Scaffold for a new C Project.

To start new project, run:

gh gist clone c3e34d75a1f4496b6f5aec1803aa2032 new_c_project

This will make a directory named new_c_project with cmake, compile_commands.json, clangd, and clang-format support.

Then build the project with:

cd new_c_project
mkdir build
cd build
cmake -G Ninja ..
ninja
./myproject
cmake_minimum_required(VERSION 3.10)
project(myproject C)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_executable(myproject main.c)
target_compile_options(myproject PRIVATE -Wall -Wextra -Werror -fsanitize=address,undefined)
target_link_options(myproject PRIVATE -fsanitize=address,undefined)
#include <stdio.h>
int main(void)
{
fprintf(stderr, "Hello World!\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment