LoginSignup
1
4

More than 5 years have passed since last update.

VSCodeでC言語自作ヘッダファイルの追加方法

Posted at

1.cファイルの作成

sum.c
#include <stdio.h>
#include "sum.h"

int main(void){
    int value;
    value = sum(50,100);
    printf("%d\n",value);
    return 0;
}

int sum(int min,int max){
    int num;
    num = (min + max) * (max - min+1) / 2;
    return num;
}

2.hファイルの作成

sum.h
int sum(int min,int max);

3.新規ヘッダファイルの追加

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "ここにパスを追記"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

使っているコンパイラにより手順が異なる場合があります。
作業ディレクトリの.vscodeディレクトリの配下にあるc_cpp_properties.jsonファイルのincludePathという括弧内にヘッダファイルのパスを追記し、保存すればOK。

1
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4