IDE: VS code
gcc version: 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)
I new in C , now I have three files:
Get_para.h
#ifndef _GETPARA_H_
#define _GETPARA_H_
extern double C;
extern double dEarthAngularVelocity;
...
extern void calParameter();
#endif
and Get_para.c, which is the implement of Get_para.h
#include <math.h>
#define _USE_MATH_DEFINES
#define pi M_PI
double C = 3e8;
double dEarthAngularVelocity = 7.29210e-5;
...
void calParameter(){
...
}
then, I want to include Get_para.h in test.c and call calParameter function which is implemented in Get_para.c
#include <stdio.h>
#include "Get_para.h"
int main(){
calParameter();
printf("%lf\n",dSemiMajorAxis);
}
I use 'run code' in VS,the command in terminal is:
if ($?) { gcc test.c -o test } ; if ($?) { .\test }
the output is:
C:\Users\bob\AppData\Local\Temp\ccuWLUIl.o:test.c:(.text+0xe): undefined reference to `calParameter'
C:\Users\bob\AppData\Local\Temp\ccuWLUIl.o:test.c:(.rdata$.refptr.dSemiMajorAxis[.refptr.dSemiMajorAxis]+0x0): undefined reference to `dSemiMajorAxis'
collect2.exe: error: ld returned 1 exit status
but I want to just include the "Get_para.h" then I can use the implement of them in "Get_para.c".I search this in google , others' code didn't work on my computer. Now I guess the problem is the parameters of gcc, but can't figure out what is it or what knowledge of C I need to know to solve this problem.