gcc erreur : undefined reference to `ltid'
si je inclure stdlib.h puis aussi itoa() n'est pas reconnu. Mon code :
%{
#include "stdlib.h"
#include <stdio.h>
#include <math.h>
int yylex(void);
char p[10]="t",n1[10];
int n ='0';
%}
%union
{
char *dval;
}
%token ID
%left '+' '-'
%left '*' '/'
%nonassoc UMINUS
%type <dval> S
%type <dval> E
%%
S : ID '=' E {printf(" x = %sn",$$);}
;
E : ID {}
| E '+' E {n++;itoa(n,n1,10);printf(" %s = %s + %s ",p,$1,$3);strcpy($$,p);strcat($$,n1);}
| E '-' E {n++;itoa(n,n1,10);printf(" %s = %s – %s ",p,$1,$3);strcpy($$,p);strcat($$,n1);}
| E '*' E {n++;itoa(n,n1,10);printf(" %s = %s * %s ",p,$1,$3);strcpy($$,p);strcat($$,n1);}
| E '/' E {n++;itoa(n,n1,10);printf(" %s = %s /%s ",p,$1,$3);strcpy($$,p);strcat($$,n1);}
;
%%
main()
{
yyparse();
}
int yyerror (char *s)
{
}
Après avoir exécuté le code que j'ai :
gcc lex.yy.c y.tab.c -ll
12.y: In function ‘yyparse’:
12.y:24: warning: incompatible implicit declaration of built-in function ‘strcpy’
12.y:24: warning: incompatible implicit declaration of built-in function ‘strcat’
12.y:25: warning: incompatible implicit declaration of built-in function ‘strcpy’
12.y:25: warning: incompatible implicit declaration of built-in function ‘strcat’
12.y:26: warning: incompatible implicit declaration of built-in function ‘strcpy’
12.y:26: warning: incompatible implicit declaration of built-in function ‘strcat’
12.y:27: warning: incompatible implicit declaration of built-in function ‘strcpy’
12.y:27: warning: incompatible implicit declaration of built-in function ‘strcat’
/tmp/ccl0kjje.o: In function `yyparse':
y.tab.c:(.text+0x33d): undefined reference to `itoa'
y.tab.c:(.text+0x3bc): undefined reference to `itoa'
y.tab.c:(.text+0x43b): undefined reference to `itoa'
y.tab.c:(.text+0x4b7): undefined reference to `itoa'
Où vais-je tort ? Pourquoi je ne peux pas trouver la référence à la ltid ? J'ai aussi essayé avec <> supports pour la ltid.
- double possible de C Erreur: undefined reference to '_itoa'
Vous devez vous connecter pour publier un commentaire.
itoa
est un non-standard d'une fonction qui est pris en charge par certains compilateurs. En passant par l'erreur, il n'est pas pris en charge par votre compilateur. Votre meilleur pari est d'utilisersnprintf()
à la place.snprintf (buff, sizeof(buf), "%d",n); // print int 'n' into the char[] buffer
snprintf(n1, sizeof(n1), "%d",n);
avec votre code.- Je utiliser
sprintf
manière suivante:J'espère que cela va sauver quelqu'un moment 😉