Undefined reference to `WinMain@16' error when compile with gcc
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm going to run a simple program constructed with Flex an Bison.
Here are my codes.
Flex file (calc.l)
%{
#include <stdio.h>
#include <stdlib.h>
#include "tt.tab.h"
%}
/* %option noyywrap */
%%
[0-9]+(.[0-9]+)?([eE][0-9]+)? {yylval.f = atof(yytext); return NUM;}
[-+()*/] {return yytext[0];}
[tfvn] {;}
%%
int yywrap() {return -1}
Bison file (tt.y)
%{
#include <stdio.h>
#include <stdlib.h>
extern int yylex();
void yyerror(char *msg);
%}
%{
#include <stdio.h>
#include <stdlib.h>
extern int yylex();
%}
%union {
float f;
}
%token <f> NUM
%type <f> E T F
%%
S : E {printf("fn", $1);}
;
E : E '+' T {$$ = $1 + $3}
| T {$$ = $1;}
;
T : T '*' F {$$ = $1 * $3}
| F {$$ = $1;}
;
F : '(' E ')' {$$ = $2;}
| '-' F {$$ = -$2;}
| NUM {$$ = $1;}
%%
void yyerror(char *msg) {
fprintf(stderr, "%sn", msg);
exit(1);
}
To compile I follow follow commands in cmd.
Bison -d tt.y
Flex calc.l
gcc lex.yy.c tt.tab.c -o calc
when I run last gcc comman it got error like this.
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../libmingw32.a(main.o):(.text.startup+0xb0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
What is the problem in my codes or any. Thanks for any consideration :)
gcc compiler-construction bison flex-lexer
add a comment |
I'm going to run a simple program constructed with Flex an Bison.
Here are my codes.
Flex file (calc.l)
%{
#include <stdio.h>
#include <stdlib.h>
#include "tt.tab.h"
%}
/* %option noyywrap */
%%
[0-9]+(.[0-9]+)?([eE][0-9]+)? {yylval.f = atof(yytext); return NUM;}
[-+()*/] {return yytext[0];}
[tfvn] {;}
%%
int yywrap() {return -1}
Bison file (tt.y)
%{
#include <stdio.h>
#include <stdlib.h>
extern int yylex();
void yyerror(char *msg);
%}
%{
#include <stdio.h>
#include <stdlib.h>
extern int yylex();
%}
%union {
float f;
}
%token <f> NUM
%type <f> E T F
%%
S : E {printf("fn", $1);}
;
E : E '+' T {$$ = $1 + $3}
| T {$$ = $1;}
;
T : T '*' F {$$ = $1 * $3}
| F {$$ = $1;}
;
F : '(' E ')' {$$ = $2;}
| '-' F {$$ = -$2;}
| NUM {$$ = $1;}
%%
void yyerror(char *msg) {
fprintf(stderr, "%sn", msg);
exit(1);
}
To compile I follow follow commands in cmd.
Bison -d tt.y
Flex calc.l
gcc lex.yy.c tt.tab.c -o calc
when I run last gcc comman it got error like this.
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../libmingw32.a(main.o):(.text.startup+0xb0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
What is the problem in my codes or any. Thanks for any consideration :)
gcc compiler-construction bison flex-lexer
add a comment |
I'm going to run a simple program constructed with Flex an Bison.
Here are my codes.
Flex file (calc.l)
%{
#include <stdio.h>
#include <stdlib.h>
#include "tt.tab.h"
%}
/* %option noyywrap */
%%
[0-9]+(.[0-9]+)?([eE][0-9]+)? {yylval.f = atof(yytext); return NUM;}
[-+()*/] {return yytext[0];}
[tfvn] {;}
%%
int yywrap() {return -1}
Bison file (tt.y)
%{
#include <stdio.h>
#include <stdlib.h>
extern int yylex();
void yyerror(char *msg);
%}
%{
#include <stdio.h>
#include <stdlib.h>
extern int yylex();
%}
%union {
float f;
}
%token <f> NUM
%type <f> E T F
%%
S : E {printf("fn", $1);}
;
E : E '+' T {$$ = $1 + $3}
| T {$$ = $1;}
;
T : T '*' F {$$ = $1 * $3}
| F {$$ = $1;}
;
F : '(' E ')' {$$ = $2;}
| '-' F {$$ = -$2;}
| NUM {$$ = $1;}
%%
void yyerror(char *msg) {
fprintf(stderr, "%sn", msg);
exit(1);
}
To compile I follow follow commands in cmd.
Bison -d tt.y
Flex calc.l
gcc lex.yy.c tt.tab.c -o calc
when I run last gcc comman it got error like this.
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../libmingw32.a(main.o):(.text.startup+0xb0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
What is the problem in my codes or any. Thanks for any consideration :)
gcc compiler-construction bison flex-lexer
I'm going to run a simple program constructed with Flex an Bison.
Here are my codes.
Flex file (calc.l)
%{
#include <stdio.h>
#include <stdlib.h>
#include "tt.tab.h"
%}
/* %option noyywrap */
%%
[0-9]+(.[0-9]+)?([eE][0-9]+)? {yylval.f = atof(yytext); return NUM;}
[-+()*/] {return yytext[0];}
[tfvn] {;}
%%
int yywrap() {return -1}
Bison file (tt.y)
%{
#include <stdio.h>
#include <stdlib.h>
extern int yylex();
void yyerror(char *msg);
%}
%{
#include <stdio.h>
#include <stdlib.h>
extern int yylex();
%}
%union {
float f;
}
%token <f> NUM
%type <f> E T F
%%
S : E {printf("fn", $1);}
;
E : E '+' T {$$ = $1 + $3}
| T {$$ = $1;}
;
T : T '*' F {$$ = $1 * $3}
| F {$$ = $1;}
;
F : '(' E ')' {$$ = $2;}
| '-' F {$$ = -$2;}
| NUM {$$ = $1;}
%%
void yyerror(char *msg) {
fprintf(stderr, "%sn", msg);
exit(1);
}
To compile I follow follow commands in cmd.
Bison -d tt.y
Flex calc.l
gcc lex.yy.c tt.tab.c -o calc
when I run last gcc comman it got error like this.
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../libmingw32.a(main.o):(.text.startup+0xb0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
What is the problem in my codes or any. Thanks for any consideration :)
gcc compiler-construction bison flex-lexer
gcc compiler-construction bison flex-lexer
edited Jan 3 at 9:23
Georgi Hristozov
1,3981022
1,3981022
asked Jan 3 at 5:20


DhananjayaDhananjaya
204319
204319
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You do not define the main function, the code generated by flex and bison do not define the main function, you have to define it by yourself else the program do not have an entry point.
You have problems in your definitions :
- in tt.y
{printf("fn", $1);}
have a format not compatible with an argument, must be ``{printf("%fn", $1);}` ? - in tt.y declare yyerror in the header with the declaration of yylex
- in calc.l
int yywrap() {return -1}
must beint yywrap() {return -1;}
The minimal main definition is :
int main()
{
yyparse();
return 0;
}
you can put it with the definition of yyerror in tt.y
Where I have to define main() funtion, in .y file or .l file ?
– Dhananjaya
Jan 3 at 9:00
@Dhananjaya I edited my answer, please reread it. I think a%start
is also missing in the bison file
– bruno
Jan 3 at 9:18
Thanks.. we have t define main() { return yyparse();} in .y file. I got it. :)
– Dhananjaya
Jan 3 at 9:29
yywrap
needs to return 1, not -1. Although it would be better to uncomment%option noyywrap
, and not defineyywrap
at all.
– rici
Jan 3 at 18:30
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016734%2fundefined-reference-to-winmain16-error-when-compile-with-gcc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You do not define the main function, the code generated by flex and bison do not define the main function, you have to define it by yourself else the program do not have an entry point.
You have problems in your definitions :
- in tt.y
{printf("fn", $1);}
have a format not compatible with an argument, must be ``{printf("%fn", $1);}` ? - in tt.y declare yyerror in the header with the declaration of yylex
- in calc.l
int yywrap() {return -1}
must beint yywrap() {return -1;}
The minimal main definition is :
int main()
{
yyparse();
return 0;
}
you can put it with the definition of yyerror in tt.y
Where I have to define main() funtion, in .y file or .l file ?
– Dhananjaya
Jan 3 at 9:00
@Dhananjaya I edited my answer, please reread it. I think a%start
is also missing in the bison file
– bruno
Jan 3 at 9:18
Thanks.. we have t define main() { return yyparse();} in .y file. I got it. :)
– Dhananjaya
Jan 3 at 9:29
yywrap
needs to return 1, not -1. Although it would be better to uncomment%option noyywrap
, and not defineyywrap
at all.
– rici
Jan 3 at 18:30
add a comment |
You do not define the main function, the code generated by flex and bison do not define the main function, you have to define it by yourself else the program do not have an entry point.
You have problems in your definitions :
- in tt.y
{printf("fn", $1);}
have a format not compatible with an argument, must be ``{printf("%fn", $1);}` ? - in tt.y declare yyerror in the header with the declaration of yylex
- in calc.l
int yywrap() {return -1}
must beint yywrap() {return -1;}
The minimal main definition is :
int main()
{
yyparse();
return 0;
}
you can put it with the definition of yyerror in tt.y
Where I have to define main() funtion, in .y file or .l file ?
– Dhananjaya
Jan 3 at 9:00
@Dhananjaya I edited my answer, please reread it. I think a%start
is also missing in the bison file
– bruno
Jan 3 at 9:18
Thanks.. we have t define main() { return yyparse();} in .y file. I got it. :)
– Dhananjaya
Jan 3 at 9:29
yywrap
needs to return 1, not -1. Although it would be better to uncomment%option noyywrap
, and not defineyywrap
at all.
– rici
Jan 3 at 18:30
add a comment |
You do not define the main function, the code generated by flex and bison do not define the main function, you have to define it by yourself else the program do not have an entry point.
You have problems in your definitions :
- in tt.y
{printf("fn", $1);}
have a format not compatible with an argument, must be ``{printf("%fn", $1);}` ? - in tt.y declare yyerror in the header with the declaration of yylex
- in calc.l
int yywrap() {return -1}
must beint yywrap() {return -1;}
The minimal main definition is :
int main()
{
yyparse();
return 0;
}
you can put it with the definition of yyerror in tt.y
You do not define the main function, the code generated by flex and bison do not define the main function, you have to define it by yourself else the program do not have an entry point.
You have problems in your definitions :
- in tt.y
{printf("fn", $1);}
have a format not compatible with an argument, must be ``{printf("%fn", $1);}` ? - in tt.y declare yyerror in the header with the declaration of yylex
- in calc.l
int yywrap() {return -1}
must beint yywrap() {return -1;}
The minimal main definition is :
int main()
{
yyparse();
return 0;
}
you can put it with the definition of yyerror in tt.y
edited Jan 3 at 9:17
answered Jan 3 at 8:30


brunobruno
13.4k31426
13.4k31426
Where I have to define main() funtion, in .y file or .l file ?
– Dhananjaya
Jan 3 at 9:00
@Dhananjaya I edited my answer, please reread it. I think a%start
is also missing in the bison file
– bruno
Jan 3 at 9:18
Thanks.. we have t define main() { return yyparse();} in .y file. I got it. :)
– Dhananjaya
Jan 3 at 9:29
yywrap
needs to return 1, not -1. Although it would be better to uncomment%option noyywrap
, and not defineyywrap
at all.
– rici
Jan 3 at 18:30
add a comment |
Where I have to define main() funtion, in .y file or .l file ?
– Dhananjaya
Jan 3 at 9:00
@Dhananjaya I edited my answer, please reread it. I think a%start
is also missing in the bison file
– bruno
Jan 3 at 9:18
Thanks.. we have t define main() { return yyparse();} in .y file. I got it. :)
– Dhananjaya
Jan 3 at 9:29
yywrap
needs to return 1, not -1. Although it would be better to uncomment%option noyywrap
, and not defineyywrap
at all.
– rici
Jan 3 at 18:30
Where I have to define main() funtion, in .y file or .l file ?
– Dhananjaya
Jan 3 at 9:00
Where I have to define main() funtion, in .y file or .l file ?
– Dhananjaya
Jan 3 at 9:00
@Dhananjaya I edited my answer, please reread it. I think a
%start
is also missing in the bison file– bruno
Jan 3 at 9:18
@Dhananjaya I edited my answer, please reread it. I think a
%start
is also missing in the bison file– bruno
Jan 3 at 9:18
Thanks.. we have t define main() { return yyparse();} in .y file. I got it. :)
– Dhananjaya
Jan 3 at 9:29
Thanks.. we have t define main() { return yyparse();} in .y file. I got it. :)
– Dhananjaya
Jan 3 at 9:29
yywrap
needs to return 1, not -1. Although it would be better to uncomment %option noyywrap
, and not define yywrap
at all.– rici
Jan 3 at 18:30
yywrap
needs to return 1, not -1. Although it would be better to uncomment %option noyywrap
, and not define yywrap
at all.– rici
Jan 3 at 18:30
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54016734%2fundefined-reference-to-winmain16-error-when-compile-with-gcc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown