Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 集合2:ld再次返回1退出状态_C_Linker_Microcontroller - Fatal编程技术网

C 集合2:ld再次返回1退出状态

C 集合2:ld再次返回1退出状态,c,linker,microcontroller,C,Linker,Microcontroller,我正在编程一个微控制器。我使用VisualStudio 2010创建所有代码,现在,在微控制器上使用相同的代码,我发现以下错误: ... ./src/main.o:(.rodata.GPS_latitude+0x0): multiple definition of `GPS_latitude' ./src/empresa1.o:(.rodata.GPS_latitude+0x0): first defined here ./src/main.o:(.rodata.GPS_hora+0x0

我正在编程一个微控制器。我使用VisualStudio 2010创建所有代码,现在,在微控制器上使用相同的代码,我发现以下错误:

...
    ./src/main.o:(.rodata.GPS_latitude+0x0): multiple definition of `GPS_latitude'
./src/empresa1.o:(.rodata.GPS_latitude+0x0): first defined here
./src/main.o:(.rodata.GPS_hora+0x0): multiple definition of `GPS_hora'
./src/empresa1.o:(.rodata.GPS_hora+0x0): first defined here
./src/gps.o: In function `GPS_PreencheCampos':
gps.c:(.text.GPS_PreencheCampos+0x4): undefined reference to `GPS_GuardaAnterior'
./src/main.o: In function `main':
main.c:(.text.startup.main+0xa0): undefined reference to `GPS_PegaValorLatitude'
main.c:(.text.startup.main+0xa4): undefined reference to `GPS_PegaLatitudeInt'
main.c:(.text.startup.main+0xc0): undefined reference to `GPS_PegaValorLongitude'
main.c:(.text.startup.main+0xc4): undefined reference to `GPS_PegaLongitudeInt'
main.c:(.text.startup.main+0xf8): undefined reference to `GPS_PegaHoraInt'
main.c:(.text.startup.main+0x110): undefined reference to `GPS_PegaStatusInt'
main.c:(.text.startup.main+0x128): undefined reference to `GPS_PegaModoInt'
main.c:(.text.startup.main+0x140): undefined reference to `GPS_PegaSatelitesInt'
collect2: ld returned 1 exit status
make: *** [TFRT_Leandro.axf] Error 1
最初我们可以看到,msg的“多重定义”有一些错误。所有这些MSG都是关于在.h文件中定义的变量。它们被定义为GPS_数据,定义如下:

struct {
  char data[7];     // Data no formato ddMMyy\0
  char hora[7];     // Hora no formato hhmmss\0
  char latitude[10];    // Latitude no formato ddmm.mmmm\0
  char longitude[11];   // Longitude no formato dddmm.mmmm\0
  char velocidade[6];   // Velocidade no formato sss.s\0
  char curso[6];      // Curso no formato ccc.c\0
  char satelites[3];    // Número de satélites no formato nn\0
  char status[2];     // Qualidade do GPS Invalido(0), Valido GNSS fixo(1) ou Valido GNSS fixo diferencial(2)
  char norteSul[2];   // Direção de latitude (N/S)
  char lesteOeste[2];   // Direção de longitude (E/W)
  char modo[2];     // Modo: Sem fixo disponível (1), 2D (2), 3D (3)
} GPS_Info;

typedef struct GPS_Dado{
  int origem;
  int posicao;
  int tamanho;
  char * pDado;
};

const struct GPS_Dado GPS_hora =    {GPS_Tipo_GPRMC, 0,   7,  GPS_Info.hora};
我们可以注意到的另一件事是,存在对函数的未定义引用。我不明白。每个函数在头文件中都有声明,该声明正确地包含在main.c文件中

我希望有人能帮我解决这个错误。 好吧,关于这个疑问的任何其他问题,请随时提出评论


致以最诚挚的问候

您不应在头文件中定义变量和常量,只应声明它们:

extern const struct GPS_Dado GPS_hora;
然后在实现(
.c
)文件中定义它:

const struct GPS_Dado GPS_hora = { GPS_Tipo_GPRMC, 0, 7,  GPS_Info.hora };

好的,问题解决了。有些函数签名在.c和.h文件中是不同的。我还在.h文件中定义变量。