gpt4 book ai didi

c - 构建C程序时如何解决CodeBlocks中的这个 'Multiple Definitions of'错误?

转载 作者:太空宇宙 更新时间:2023-11-04 06:30:07 24 4
gpt4 key购买 nike

我正在尝试在 CodeBlocks 中构建这个项目,以便我可以单步执行其中一个函数,但我在构建它时遇到了问题。这是我的错误

||=== Build: Debug in MAGLAT (compiler: GNU GCC Compiler) ===|
obj\Debug\GMCORD.o||In function `GM_CartesianToSpherical':|
C:\Users\Guest\SkyDrive\temp\MAGLAT\MAGLAT\GM_SubLibrary.c|11|multiple definition of `GM_CartesianToSpherical'|
obj\Debug\GM_SubLibrary.o:C:\Users\Guest\SkyDrive\temp\MAGLAT\MAGLAT\GM_SubLibrary.c|11|first defined here|

//头文件

#ifndef GMHEADER_H
#define GMHEADER_H
#endif

#ifndef M_PI
#define M_PI ((2)*(acos(0.0)))
#endif

#define GM_STARTYEAR 1900
#define RAD2DEG(rad) ((rad)*(180.0L/M_PI))
#define DEG2RAD(deg) ((deg)*(M_PI/180.0L))
#define ATanH(x) (0.5 * log((1 + x) / (1 - x)))
#define MU_0 4*M_PI / 10000000
#define R_e 6.371 * 1000000

#define TRUE ((int)1)
#define FALSE ((int)0)


typedef struct {
int Day;
int Month;
int Year;
double DecimalYear;
int DayNumber;
} GMtype_Date;

typedef struct {
double lambda;// longitude
double phi; // geodetic latitude
double HeightAboveEllipsoid; // height above the ellipsoid (HaE)
} GMtype_CoordGeodetic;

typedef struct {
...
...
}...;

//GM Cord functions
void GM_CartesianToSpherical(GMtype_CoordCartesian CoordCartesian, GMtype_CoordSpherical *CoordSpherical);

///GM_SubLibrary.c

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#include "GMHeader.h"



void GM_CartesianToSpherical(GMtype_CoordCartesian CoordCartesian, GMtype_CoordSpherical *CoordSpherical)
{
/*This function converts a point from Cartesian coordinates into spherical coordinates*/
double X, Y, Z;

X = CoordCartesian.x;
Y = CoordCartesian.y;
Z = CoordCartesian.z;

CoordSpherical->r = sqrt(X * X + Y * Y + Z * Z);
CoordSpherical->phig = RAD2DEG(asin(Z / (CoordSpherical->r)));
CoordSpherical->lambda = RAD2DEG(atan2(Y, X));
} /*GM_CartesianToSpherical*/

///GMCORD.c

//----------------------------------------------------------------------------------------

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#include "GM_SubLibrary.c"


//----------------------------------------------------------------------------------------


int main()
{
int Flag = 1;
char ans[20];
GMtype_Date date;
GMtype_Data G0, G1, H1;
GMtype_CoordGeodetic location;
GMtype_CoordDipole GMlocation;
GMtype_Ellipsoid Ellip;


GM_ScanIGRF(&G0, &G1, &H1);
GM_SetEllipsoid(&Ellip);
while(Flag == 1) {
GM_GetUserInput(&location, &date);
GM_CORD(location, &date, Ellip, G0, G1, H1, &GMlocation);
GM_PrintUserData(location, date, GMlocation);
...
}
return 1;
}

最佳答案

您在 GMCORD.c 中包括了 C 源文件 GM_SubLibrary.c 而不是头文件 GMHeader.h。

参见:Including one C source file in another?

关于c - 构建C程序时如何解决CodeBlocks中的这个 'Multiple Definitions of'错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21665854/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com