VS Code中C檔案呼叫另外一個C檔案
阿新 • • 發佈:2018-12-23
main.c
#include <stdio.h>
#include "BaseStore.h"
int main()
{
baseStore_aboutSizeofFunc();
return 0;
}
BaseStore.h
#include <stdio.h>
void baseStore_aboutSizeofFunc();
BaseStore.c
#include "BaseStore.h"
void baseStore_aboutSizeofFunc()
{
int integerType;
float floatType;
double doubleType;
char charType;
// sizeof操作符用於計算變數的位元組大小
printf("size of int: %d bytes\n",sizeof(integerType));
printf("size of float: %d bytes\n",sizeof(floatType));
printf("size of double: %d bytes\n",sizeof(doubleType));
printf("size of char: %d bytes\n",sizeof (charType));
return;
}
重點在於編譯: 在tasks.json 檔案中包含要引用的檔案
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build hello world",
"type": "shell",
"command" : "gcc",
"args": [
"-g","main.c",
"-g","BaseStore.c"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
編譯執行
E:\C_Study>gcc main.c BaseStore.c -o main
E:\C_Study>main.exe
size of int: 4 bytes
size of float: 4 bytes
size of double: 8 bytes
size of char: 1 bytes
E:\C_Study>
問題:
main.c
引入多個C檔案該怎麼辦?求大神指導
參考連結
https://blog.csdn.net/u013145697/article/details/85112700
https://segmentfault.com/q/1010000015905887
https://blog.csdn.net/sunshine_in_moon/article/details/50396942