Solved

problem with Makefile

Posted on 2008-10-16
19
628 Views
Last Modified: 2012-06-21
so I have attached all of my file here, along with the Makefile I am using, I am really frustrated and don't know how to fix this makefile so that it compiles. I tried to zip all my file so all of you can see it here, but it always complaints that the file type is not supported, although I already zipped it. Below are the errors I am getting:

/C-/parse.y:65: undefined reference to `copyString'
C-/parse.y:75: undefined reference to `newDecNode'
C-/parse.y:94: undefined reference to `newStmtNode'
C-/parse.y:105: undefined reference to `newStmtNode'
/C-/parse.y:106: undefined reference to `newExpNode'
/C-/parse.y:117: undefined reference to `newDecNode'
/C-/parse.y:124: undefined reference to `newDecNode'
/C-/parse.y:132: undefined reference to `newDecNode'
C-/parse.y:139: undefined reference to `newDecNode'
C-/parse.y:164: undefined reference to `newDecNode'


lex.yy.o:/C-/lex.yy.c:1983: first defined here
scan.o: In function `yy_delete_buffer':
C-/<stdout>:1544: multiple definition of `yy_delete_buffer'
lex.yy.o:/C-/lex.yy.c:1544: first defined here
scan.o: In function `yyfree':
C-/<stdout>:2000: multiple definition of `yyfree'
lex.yy.o:/C-/lex.yy.c:2000: first defined here
scan.o: In function `yy_flush_buffer':
/C-/<stdout>:1595: multiple definition of `yy_flush_buffer'
lex.yy.o:C-/lex.yy.c:1595: first defined here
scan.o: In function `yypush_buffer_state':
C-/<stdout>:1624: multiple definition of `yypush_buffer_state'
lex.yy.o:C-/lex.yy.c:1624: first defined here
scan.o: In function `yypop_buffer_state':
C-/<stdout>:1654: multiple definition of `yypop_buffer_state'
lex.yy.oC-/lex.yy.c:1654: first defined here
scan.o: In function `yy_scan_buffer':
C-/<stdout>:1722: multiple definition of `yy_scan_buffer'
lex.yy.o:C-/lex.yy.c:1722: first defined here
scan.o: In function `yy_scan_string':
/C-/<stdout>:1759: multiple definition of `yy_scan_string'
lex.yy.o:C-/lex.yy.c:1759: first defined here
scan.o: In function `yy_scan_bytes':
C-/<stdout>:1772: multiple definition of `yy_scan_bytes'
lex.yy.o/C-/lex.yy.c:1772: first defined here
scan.o: In function `yyget_lineno':
/C-/<stdout>:1834: multiple def

CC = gcc

CFLAGS = -g
 

CFILES = main.c  lex.yy.c y.tab.c scan.c
 

OFILES = main.o  lex.yy.o y.tab.o scan.o
 

HFILES = y.tab.h globals.h util.h 
 

compile: $(OFILES)

	$(CC) $(CFLAGS) $(OFILES) -lfl -o compile
 

y.tab.c : parse.y util.h

	yacc -v -d parse.y
 

lex.yy.c : scan.l globals.h y.tab.h

	flex scan.l
 

y.tab.h : parse.y 

	yacc -v -d parse.y
 

clean:

	/bin/rm -f compile lex.yy.c y.tab.c y.tab.h *.BAK *.o

Open in new window

0
Comment
Question by:kuntilanak
  • 8
  • 7
  • 3
19 Comments
 
LVL 17

Expert Comment

by:sweetfa2
ID: 22736540
What is in your lex.yy.c file?
0
 
LVL 17

Expert Comment

by:sweetfa2
ID: 22736551
and your parse.y
0
 

Author Comment

by:kuntilanak
ID: 22736556
If you understand a bit of yacc/lex, you would understand that lex.yy.c is a file generated by yacc, it's basically generated based on the .y file
0
 
LVL 17

Expert Comment

by:sweetfa2
ID: 22736572
sure, that is why I also asked for the parse file.

But you need to see what is being generated to understand what is wrong.  Sorry for trying to help.
0
 

Author Comment

by:kuntilanak
ID: 22736575
I've managed to change all the file format to a .txt in the zip file so that it works, so please just rename the file by deleting the .txt file and you'll get all of my file
correct-this.zip
0
 

Author Comment

by:kuntilanak
ID: 22736582
>>But you need to see what is being generated to understand what is wrong.  Sorry for trying to help.


Sorry I don't mean to be rude or harsh to you :)
0
 
LVL 5

Expert Comment

by:zmo
ID: 22736628
could you give us parse.y and scan.l ?

it seems to me that you don't compile against the file object that contains the AST constructors ie newDecNode, newExpNode, etc... (that's for the .y errors) and for the lexer it seems more annoying... like gcc can't find the flex/yacc libraries.

you can use http://sharesend.com/ to share your archive if you can't here.

and remember : a linking problem is *always* something stupid you missed, and the more time you spend trying to find it, the more stupid it is ;)
0
 
LVL 5

Expert Comment

by:zmo
ID: 22736635
lol, the time I spent writing that you all came here :p
0
 

Author Comment

by:kuntilanak
ID: 22736646
yea.. I spent almost half an hour or more to debug this thing.. I really don't know what to do
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 5

Expert Comment

by:zmo
ID: 22736661
lol, last time I spent almost 2 hours trying to find out why I couldn't compile an ocaml file, to find out it was just because of a misplaced uppercase :]
0
 
LVL 5

Expert Comment

by:zmo
ID: 22736688
ok, first of all, you don't compile util.h/util.c -> util.o
0
 
LVL 5

Expert Comment

by:zmo
ID: 22736707
and when compiling util.c, I get an error not finding maxchildren...

and grep maxchildren in your sources return nothing, maybe you forgot something :)
0
 
LVL 5

Expert Comment

by:zmo
ID: 22736751
are you still following ? maybe we could meet on irc or on jabber...

now I just looked at your lexer... to find out you're redefining yylex !
and you're changing the prototype declaring it static, and I don't understand
why you have a parse() function that calls yyparse() !?

well, now I understand why gcc is getting crazy, I would get too, if I was giving a code like that :P
0
 

Author Comment

by:kuntilanak
ID: 22736756
yea, if we can meet on irc or so.. that would be great... or you have any IM?
0
 
LVL 5

Expert Comment

by:zmo
ID: 22736762
> and I don't understand why you have a parse() function that calls yyparse() !?

sorry, it's half past one am here, and I looked at your parse.y thinking it was scan.l :p
ok, parse() is fine, forget it ;)

but remove your static yylex whatever and put at the beginning :

extern int yylex(void); instead
0
 

Author Comment

by:kuntilanak
ID: 22736784
I dont see any static yylex at the .y file
0
 
LVL 5

Accepted Solution

by:
zmo earned 500 total points
ID: 22741062
well, I'm sorry to have suggested to go on IRC to do this, but there are problems that can't be solved using a forum interface, it's sometimes better to be able to be in live chat. To solve that issue, I had to explain to the question author many problems he encountered while solving it.

So to solve the first problem he reported, my comment #22736628 was the right solution. He forgot to compile util.c into util.o and link it against main.c.

To solve the second problem, I had to understand what he has done, and there the chatting has been useful, to sum up : he included parse.h that was a generated file from an older (and incomplete) version of the project. Then he generated tab.yy.h that contained the same symbols as in parse.h, then he compiled both objects, and when GCC tried to link both of them against main.c, it met multiple definitions errors.

I'm linking a tar file containing the solutions I gave him. For whoever wants to try to compile it, he will get  undefined references to 'source' and 'listing'. Those are just two variables that have to be declared in main.c and set up to whatever file you want to parse (and to output to).

the code below is what to be added to make the whole compilable. (a better solution would be to use fopen() and parse argv to get filenames, but I'm not here to do other's work, I'm here to help people find solutions to problems they have ;) ).
#include <stdio.h>
 

FILE* listing=stdout;

FILE* source=stdin;
 

main() { ... } 

Open in new window

this-is-corrected.zip
0
 

Author Closing Comment

by:kuntilanak
ID: 31506986
keep on helping me : )
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now