Pregunta

Tengo el siguiente .h and .archivos cpp

Si tengo que incluirá la totalidad de los códigos de las definiciones de función

Cuando puedo compilar mi programa me sale los errores que se muestran en la final

hash.h

    #define BUCKETS 64
       #define B_ENTRIES 50000
       int curr_tanker;
       typedef unsigned long int ulong;
typedef struct bucket
{
    int bucket_id;
    ulong bucket_entries;
}bucket;

typedef struct tanker_record
{
    ulong tanker_id;
    ulong tanker_size;
    ulong num_of_entries;
    ulong bucket_entry_count;
   }tanker_record;
typedef struct fpinfo
{ 
    unsigned long chunk_offset;
    unsigned long chunk_length;
    unsigned char fing_print[33];

}fpinfo;

struct fpinfo* InitHTable(fpinfo *);
int CreateTanker(tanker_record tr[]);
int Hash_CreateEntry(struct fpinfo *,struct fpinfo he,tanker_record tr);

ht.cpp

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

#include "ht.h"

struct fpinfo* InitHTable(struct fpinfo ht[][B_ENTRIES])
{
}
int CreateTanker(tanker_record tr[])
{
}
int
Hash_CreateEntry(struct fpinfo *t[][B_ENTRIES],struct fpinfo he,tanker_record tr[])
{
}
static void
WriteHTtoFile(struct fpinfo *t[][B_ENTRIES],int this_tanker)
{
}

main.cpp

#include<iostream>
#include"ht.cpp"
#include<conio.h>
#include<stdlib.h>

void main(int argc, char **argv)
{
static fpinfo hash_table[BUCKETS][B_ENTRIES];
static tanker_record tr[100];
InitHTable(&hash_table[0][0]);
CreateTanker(tr);
struct fpinfo fp;
... 
ar = Hash_CreateEntry(&hash_table[0][0], fp,tr[0]);

yo obtener los siguientes errores cuando intento compilar usando vc2010

1>principal.obj :error LNK2005:"struct fpinfo * __cdecl InitHTable(struct fpinfo (* const)[50000])" (?InitHTable@@YAPAUfpinfo@@QAY0MDFA@U1@@Z) ya definido en ht.obj

1>principal.obj :error LNK2005:"int __cdecl CreateTanker(struct tanker_record * const)" (?CreateTanker@@YAHQAUtanker_record@@@Z) ya definido en ht.obj

1>principal.obj :error LNK2005:"int __cdecl Hash_CreateEntry(struct fpinfo * (* const)[50000],struct fpinfo,struct tanker_record * const)" (?Hash_CreateEntry@@YAHQAY0MDFA@PAUfpinfo@@U1@QAUtanker_record@@@Z) ya definido en ht.obj 1>principal.obj :error LNK2005:"int curr_tanker" (?curr_tanker@@3HA) ya definido en ht.obj 1>principal.obj :error LNK2019:símbolo externo sin resolver "int __cdecl Hash_CreateEntry(struct fpinfo *,struct fpinfo,struct tanker_record)" (?Hash_CreateEntry@@YAHPAUfpinfo@@U1@Utanker_record@@@Z) que se hace referencia en función de _main 1>principal.obj :error LNK2019:símbolo externo sin resolver "struct fpinfo * __cdecl InitHTable(struct fpinfo *)" (?InitHTable@@YAPAUfpinfo@@PAU1@@Z) que se hace referencia en función de _main

GRACIAS POR SU AYUDA!!

¿Fue útil?

Solución

Estás incluyendo ht.cpp de main.cpp, que incluirá todas las definiciones de funciones ya definidas en ht.cpp sí.

Desea incluir ht.h en su lugar.

No te va a ayudar en esta situación, pero también debe proteger el archivo de cabecera con incluir a los guardias:

#ifndef HT_H
#define HT_H

// contents of ht.h

#endif

Usted también necesita los argumentos de la función declaraciones coinciden con las de las definiciones:

struct fpinfo* InitHTable(struct fpinfo[][B_ENTRIES]);
// Missing:                              ^^^^^^^^^^^

int CreateTanker(tanker_record tr[]); // OK

int Hash_CreateEntry(struct fpinfo*[][B_ENTRIES],struct fpinfo,tanker_record[]);
// Missing                         ^^^^^^^^^^^^^                            ^^

Otros consejos

Agregue una "Guardia de inclusión" en su encabezado, de modo que su contenido no esté "visto" dos veces después del preprocesamiento.Para Microsoft, #pragma once al comienzo del archivo .h.En general, agregue:

#ifndef __YOUR_HEADER_H
#define __YOUR_HEADER_H
// all the stuff from the header here
#endif

Asegúrese de adoptar un esquema de nombramiento "único" constante para cada uno de sus encabezados.Se haría __YOUR_HEADER_H, por ejemplo, customio.h en __CUSTOM_IO_H.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top