Makefile question

This is a discussion on Makefile question within the C Programming forums, part of the General Programming Boards category; Ok, first of all here's my code: Code: CC = gcc CFLAGS = -g CFILES = main.c lex.yy.c y.tab.c util.c ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    569

    Makefile question

    Ok, first of all here's my code:

    Code:
    CC = gcc
    CFLAGS = -g
    
    CFILES = main.c lex.yy.c y.tab.c util.c
    
    OFILES = main.o lex.yy.o y.tab.o util.o
    
    HFILES = y.tab.h globals.h util.h scan.h
    
    compile: $(OFILES)
    	$(CC) $(CFLAGS) $(OFILES) -lfl -o compile
    
    y.tab.c : parse.y util.h scan.h
    	yacc -v -d parse.y
    
    lex.yy.c : scan.l y.tab.h globals.h
    	flex scan.l
    
    y.tab.h : parse.y util.h scan.h 
    	yacc -v -d parse.y
    
    clean:
    	/bin/rm -f compile lex.yy.c y.tab.c y.tab.h *.BAK *.o
    I think there's something wrong as when I run make it can't found the function which is defined in util.c and global.h

    The file scan.l is using an extern variable which is defined in the globals.h file, and I've already included globals.h on the header of scan.l.


    Can you tell me what's wrong here?
    Last edited by -EquinoX-; 10-16-2008 at 11:48 AM.

  2. #2
    Registered User
    Join Date
    Sep 2008
    Posts
    54
    Aww Equinox, sounds like a name from an Album of Eric Jordan, are u a fan?

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    Quote Originally Posted by AvaGodess View Post
    Aww Equinox, sounds like a name from an Album of Eric Jordan, are u a fan?
    no I am not

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If the function is in util.c, then you should probably compile util.c at some point along the way. (Including util.h as a requirement doesn't help -- you need util.o in your OFILES, I would guess.)

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    I don't see util.c / util.o listed anywhere, so how would it know to compile and link them?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    okay, I already edited my first post and edited it also in my code, however it still fails.

  7. #7
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Are your getting a compiler error or a linker error? In otherwords, are you not putting prototypes, or are your prototypes (or lack thereof) mismatching what the file actually contains?

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    Maybe post the log of make clean followed by make
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    here's a part of the error, mostly it's a linker error I think

    Code:
    /home/-/<stdout>:692: multiple definition of `yyin'
    lex.yy.o:/home/-/lex.yy.c:692: first defined here
    scan.o: In function `yylex':
    /home/-/<stdout>:692: multiple definition of `yyout'
    lex.yy.o:/-/lex.yy.c:692: first defined here
    scan.o:(.data+0x0): multiple definition of `yylineno'
    lex.yy.o:(.data+0x0): first defined here
    scan.o: In function `yylex':
    /home/-/<stdout>:704: multiple definition of `yy_flex_debug'
    lex.yy.o:/home/-/lex.yy.c:704: first defined here
    scan.o: In function `yylex':
    /home/-/<stdout>:692: multiple definition of `yylex'
    lex.yy.o:/home/herlamba/cs453/ass3/C-/lex.yy.c:692: first defined here
    scan.o: In function `yy_create_buffer':
    /home/-/<stdout>:1516: multiple definition of `yy_create_buffer'
    lex.yy.o:/-/lex.yy.c:1516: first defined here
    scan.o: In function `yyrestart':
    /home/-/<stdout>:1454: multiple definition of `yyrestart'
    lex.yy.o:/home/-/lex.yy.c:1454: first defined here
    scan.o: In function `yyrealloc':

  10. #10
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Code:
    make clean
    make all

  11. #11
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    I did make clean and make all, still the same thing

  12. #12
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    some additional info:

    /home/-/parse.y:219: undefined reference to `newStmtNode'
    /home/-/parse.y:220: undefined reference to `newStmtNode'
    /home/-/parse.y:228: undefined reference to `newStmtNode'
    /home/-/parse.y:233: undefined reference to `newStmtNode'
    /home/-/parse.y:240: undefined reference to `newStmtNode'

    where newStmtNode is a function in util.c and I already include util.h on the header of parse.y, why can't it find that function saying it's an undefined reference

  13. #13
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Do your prototypes jive with how they are defined?

  14. #14
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    Quote Originally Posted by master5001 View Post
    Do your prototypes jive with how they are defined?
    What do you mean by prototypes jive?

  15. #15
    Registered User
    Join Date
    Jan 2008
    Posts
    569
    here's the header of each file

    scan.l:

    Code:
    #include "globals.h"   
    #include "util.h"   
    #include "y.tab.h"
    util.c
    Code:
    #include "globals.h"   
    #include "util.h"   
    #include "y.tab.h"
    parser.y
    Code:
    #include "globals.h"   
    #include "util.h"   
    #include "scan.h"
    all the other .h file of course doesn't include anything
    Last edited by -EquinoX-; 10-16-2008 at 12:24 PM.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick Compilation Question
    By chacham15 in forum C Programming
    Replies: 10
    Last Post: 10-12-2008, 08:15 PM
  2. A question about an interesting Makefile
    By meili100 in forum Tech Board
    Replies: 2
    Last Post: 08-12-2008, 03:56 PM
  3. about Makefile and Macro
    By tom_mk in forum C++ Programming
    Replies: 1
    Last Post: 09-18-2003, 01:07 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Makefile Newbie: Inheritance Question
    By Ashes999 in forum C++ Programming
    Replies: 2
    Last Post: 07-10-2003, 02:34 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21