Aymane Bo
Aymane Bo

Reputation: 59

undefined reference to xxx include doesn't work

I'm trying to compile a .c file but I get "undefined reference to" error even though I put the necessary includes. by the way as you can see in the header of my code bellow, I don't have any probleme with #include drive.h, but with #include hardware it's like gcc is ignoring this line.

here is my code and thank you :)

by the way I'm compiling like this: gcc drive.c

 #include <stdlib.h>
 #include <stdio.h>
 #include <assert.h>
 #include "include/hardware.h"
 #include "drive.h"

 static void empty_it(){
  return ;
 }

int main(int argc , char** argv){

unsigned int numCyl ; 
unsigned int numSec ; 

unsigned char* buffer ; 

unsigned int i ;

/* init hardware */
/* on initialise toujours le materiel de la meme facon*/
if(init_hardware("hardware.ini") == 0){
    fprintf(stderr, "hardware initialisation error ! \n");
    exit(EXIT_FAILURE) ;
}

/* Interrupt handlers */
for(i=0 ;i<16;i++){
    IRQVECTOR[i] = empty_it ; 
}

/* Allows all IT */
_mask(1);

assert(argc == 3);
numCyl = atoi(argv[1]) ;
numSec = atoi(argv[2]) ;

buffer = malloc(sizeof(char) *HDA_SECTORSIZE);
assert(buffer);

read_sector(numCyl , numSec , buffer);

for(i=0;i<HDA_SECTORSIZE;i++)
    printf("%01X\n", buffer[i]);

free(buffer) ; 

return EXIT_SUCCESS ;
}

Upvotes: 0

Views: 1711

Answers (1)

Iharob Al Asimi
Iharob Al Asimi

Reputation: 53006

Including a header file does not add the definition of functions, only their declarations. To add definitions you either:

  1. Add the source files defining them to the compiler command.
  2. Add the object (already compiled files) files to the compiler command.
  3. Link to an external static or shared library.

Your question as it is, doesn't contain the specific information to help you, what is read_sector() for instance? But the general answer to your current problem is this.

Upvotes: 2

Related Questions