avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] undefined reference to `fopen' and undefined reference to


From: Jum
Subject: [avr-gcc-list] undefined reference to `fopen' and undefined reference to `strtok'
Date: Tue, 15 Nov 2011 13:07:21 -0000

Hi,

 

I wrote a c program to read arrays from a txt file and then do a insertion  sort.  It runs OK while compiling in gcc.  However, I need to convert it to elf file by using ‘avr-gcc –o filename.elf –mmcu=atmega128 filename.c’ command. And then things happened as following:

 

address@hidden:~$ avr-gcc -o fget.elf -mmcu=atmega128 fget.c

fget.c: In function 'convert':

fget.c:29: warning: assignment makes pointer from integer without a cast

fget.c:36: warning: assignment makes pointer from integer without a cast

fget.c: In function 'main':

fget.c:73: warning: initialization makes pointer from integer without a cast

/tmp/ccWExtSv.o: In function `convert':

fget.c:(.text+0x124): undefined reference to `strtok'

fget.c:(.text+0x170): undefined reference to `strtok'

/tmp/ccWExtSv.o: In function `main':

fget.c:(.text+0x31c): undefined reference to `fopen'  

 

 

My C file is shown below like :

 

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

#define LIST_SIZE 200

 

int fgetline(FILE *fp, char s[], int lim) {

    char *t;

    int c, len=lim;

 

    t = s;

    while (--lim>1 && (c=getc(fp)) != EOF && c != '\n')

        *s++ = c;

    if (c == '\n')

        *s++ = c;

    else if (lim == 1) {

                *s++ = '\n';

                fprintf(stderr, "WARNING. fgetline: Line too long, splitted.\n");

    }

    *s = '\0';

    return s - t;

}

 

 

  void convert(char* sData, int* num_list){

                char* pch;

                int i = 0;

        int v;

                pch = strtok(sData, " ");

                while(1)

                {

                                if(pch == NULL)

                                                break;

                                v = atoi(pch);

                                num_list[i++]=v;

                        pch = strtok( NULL, " ");

                }

   }

 

   void insertion_sort(FILE* fp , int * num_list){

              char sData[1000];

              int  value;

              int i, j,done;

                    

              fgetline(fp,sData,1000);

                      convert(sData, num_list);

 

                                for(i=1; i<LIST_SIZE; i++)

                                {

                                                value = num_list[i];        

                                                j = i - 1;

                                                done = 0;

                                   while (!done)

                                                {

                                                                if (value < num_list[j])

                                                                {

                                                                                num_list[j+1] = num_list[j];

                                                                                j--;

                                                                                if (j < 0)

                                                                                                done = 1;                                            

                                                                }

                                                                else

                                                                                done = 1;

                                                }

                                               

               

                                                num_list[j+1] = value;

                                }

}

 

int main(void){

                int i;      

        FILE* fp = fopen("200.txt", "r"); // there are 10K random permutations of 200 number list

       for(i=0;i<10000;i++)

                {

                int num_list[LIST_SIZE];       

                insertion_sort(fp,num_list);

                }

        asm volatile("break");

 

                return 1;

}

 

 

I will appreciate if someone could help me out from this.  Thanks a million

 

 

 

 

Best  Regards

 

Jum


reply via email to

[Prev in Thread] Current Thread [Next in Thread]