Find the answer to your Linux question:
Results 1 to 2 of 2
Hello all I'm having trouble getting my Makefiles to work. I want to organise my code into separate directories as shown below. I'm trying to make it so I can ...
  1. #1
    Just Joined! robz0rz's Avatar
    Join Date
    Apr 2007
    Location
    Germany
    Posts
    19

    Please help me with my Makefile ... [Multiple directories]

    Hello all

    I'm having trouble getting my Makefiles to work. I want to organise my code into separate directories as shown below. I'm trying to make it so I can type in make all one time in the root directory and compile my application. The problem is that I can't compile GFX, because there is no entry-point. This is the error I get:
    Code:
    rob@rob-laptop:~/dev/engine$ make all
    cd ./gfx ; make GFX
    make[1]: Entering directory `/home/rob/dev/engine/gfx'
    g++ -c gfx_opengl.cpp
    g++ -o GFX gfx_opengl.o `sdl-config --cflags --libs` -lGLU
    /usr/lib/gcc/i486-linux-gnu/4.2.3/../../../../lib/crt1.o: In function `_start':
    (.text+0x18): undefined reference to `main'
    collect2: ld returned 1 exit status
    make[1]: *** [GFX] Error 1
    make[1]: Leaving directory `/home/rob/dev/engine/gfx'
    make: *** [GFX] Error 2
    Whereas if I select to compile MAIN first, I get this:
    Code:
    rob@rob-laptop:~/dev/engine$ make all
    cd ./main ; make MAIN;
    make[1]: Entering directory `/home/rob/dev/engine/main'
    g++ -c main.cpp
    g++ -o MAIN main.o `sdl-config --cflags --libs` -lGLU
    main.o: In function `main':
    main.cpp:(.text+0x116): undefined reference to `gfx::init()'
    collect2: ld returned 1 exit status
    make[1]: *** [MAIN] Error 1
    make[1]: Leaving directory `/home/rob/dev/engine/main'
    make: *** [MAIN] Error 2

    How can I solve this?



    File list:
    Code:
    ./Makefile
    ./Makefile.common
    ./gfx/gfx_opengl.cpp
    ./gfx/gfx_opengl.h
    ./gfx/Makefile
    ./main/main.cpp
    ./main/Makefile
    The Makefiles
    Code:
    ## Makefile at .:
    
    CC = g++
    CFLAGS = `sdl-config --cflags --libs` -lGLU
    PROG = application
    TRGTS = GFX MAIN
    
    
    
    # Link program
    ${PROG} : ${TRGTS}
    	${CC} -o ${PROG} ${TRGTS}
    
    
    all : ${PROG}
    
    
    # Compiling targets
    MAIN :
    	cd ./main ; make MAIN;
    
    GFX :
    	cd ./gfx ; make GFX
    
    
    # Cleaning
    clean :
    	rm -f *~ *.o ${PROG}
    	cd ./main ; make clean
    	cd ./gfx ; make clean
    Code:
    ## Common Makefile
    
    CC = g++
    CFLAGS = `sdl-config --cflags --libs` -lGLU
    
    
    
    # Link program
    ${PROG} : ${OBJS}
    	${CC} -o ${PROG} ${OBJS} ${CFLAGS}
    
    
    # Compiling sources
    %.o : %.cpp
    	${CC} -c $<
    
    
    # Cleaning
    clean :
    	rm -f *~ *.o ${PROG}
    
    
    
    ## End of common Makefile
    Code:
    ## Makefile at ./gfx:
    
    PROG = GFX
    OBJS = gfx_opengl.o
    
    
    include ../Makefile.common
    
    
    
    # Objects
    gfx_opengl.o : gfx_opengl.cpp gfx_opengl.h
    Code:
    ## Makefile at ./main:
    
    PROG = MAIN
    OBJS = main.o
    
    
    include ../Makefile.common

  2. #2
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    From a quick skim, you need to tell make that main depends on gfx.

    The last half of O'Reilly's book on make discusses component designs, recursive makes, etc. If this is a start of a large and complex project, you may want to consider obtaining that book or one like it ... cheers, drl
    Title: Managing Projects with GNU Make
    Author: R Mecklenburg
    Edition: 3rd
    Date: 2004
    Publisher: O'Reilly
    ISBN: 0-596-00610-1
    Pages: 280
    Categories: *nix, development, compiling, building, programming, tools
    Comments: Visit O'Reilly Media | Spreading the knowledge of innovators to get the corrections for a large
    Comments: number of errors.
    Comments: GNU manual: GNU `make'
    Comments: 43 page tutorial: http://www.cs.utah.edu/classes/cs563...mentsOfMake.ps
    Comments: Conflicting opinions amazon.com; 4 stars, 8 reviews, 2007.05.
    Comments: see also cons, scons
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...