В macOS С кодом Visual Studio я попытался скомпилировать C исходный код. (Ниже представлены 3 части исходного кода)
head.h (отредактировано)
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
int add_number(int a, int b);
body. c
#include "head.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
int add_number(int a, int b)
{
return a + b;
}
main. c
#include "head.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int result = add_number (1, 2);
printf("%d", result);
return 0;
}
AND
gcc main.c
Однако, когда я нажал F5 в скомпилируйте этот код c, произошла следующая ошибка:
Undefined symbols for architecture x86_64:
"_add_number", referenced from:
_main in main-49215f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Это сообщения об ошибке ссылки? Кто-нибудь поможет мне исправить эту ошибку? например, против настройки c или ...
PS Мои задачи против c. json ниже:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "gcc build",
"command": "/usr/bin/gcc",
"args": [
"-g",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"${file}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher":
{
"fileLocation": [
"relative", "${workspaceRoot}"
],
"pattern":
{
// The regular expression.
//Example to match: helloWorld.c:5:3: warning: implicit declaration of function 'prinft'
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"group": "build"
},
{
"label": "execute",
"command": "cd ${fileDirname} && ./${fileBasenameNoExtension}",
"group": "test"
}
]
}