Thread: Makefile help please

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286

    Makefile help please

    Hi! I'm programming C++ in windows and I am compiling using a Makefile. Since I've just got started using makefiles, I'm not very good at coding them. I basically just tried to mimic an already existing makefile for another project. Anyway, here is what my Makefile currently looks like (after reading the Makefile you can skip down to my second post, since I realized that this error was caused by an incorrect installation of SDL):

    Code:
    CC=g++
    CPPFLAGS=-Wall
    CPPFLAGS+=-I..
    CPPFLAGS+=-lmingw32 -lSDLmain -lSDL
    CPPFLAGS+=-mwindows
    SRC=main.cpp #../imanip/imanip.cpp #../imanip/imfuncs.cpp
    OBJ=$(SRC:.cpp=.o)
    OUT=image_test.exe
    
    all: $(OUT)
    	rm $(OBJ) #Remove .o
    
    $(OBJ) :
    	$(CC) $(SRC) $(CPPFLAGS) -c #Create .o
    
    $(OUT) : $(OBJ)
    	$(CC) $(OBJ) $(CPPFLAGS) -o $@ #Link .
    I'm compiling using mingw32-make.exe and g++, both in the mingw package. g++ complains though, when compiling from emacs, and here is what comes up in the split window in emacs:

    Code:
    mingw32-make -k 
    g++ main.o -Wall -I.. -lmingw32 -lSDLmain -lSDL -mwindows -o image_test.exe #Link .
    g++: #Link: No such file or directory
    mingw32-make: *** [image_test.exe] Error 1
    mingw32-make: Target `all' not remade because of errors.
    It looks like mingw32-make.exe is trying to parse what comes after the '#', but that should be interpreted as a comment, right?

    The project by the way uses SDL. The code I have written is split up in two different folders, with the main function in a file lying in the same directory as the Makefile.

    Edit:
    Strange. Anyway, I tried removing the comment (#Link .), and here is what it says instead:

    Code:
    mingw32-make -k 
    g++ main.o -Wall -I.. -lmingw32 -lSDLmain -lSDL -mwindows -o image_test.exe
    C:\Program1\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lSDLmain
    collect2: ld returned 1 exit status
    mingw32-make: *** [image_test.exe] Error 1
    mingw32-make: Target `all' not remade because of errors.
    I don't understand much of this; I wrote the Makefile along with the code files long time ago on another computer, and I am now trying to make the same project I wrote back then compile with the same files and the same code. I have little knowledge of makefiles though. The project has compiled before and I find it funny that a bunch of new problems shall arise everytime you try to compile old projects that you know has compiled before.

    I have installed the SDL development package on this computer, following the steps given in Lazy Foo' Productions.
    Last edited by TriKri; 09-24-2009 at 12:05 AM.
    Come on, you can do it! b( ~_')

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 08-11-2009, 06:45 AM
  2. Building a project using a Makefile
    By starcatcher in forum Windows Programming
    Replies: 2
    Last Post: 11-23-2008, 11:50 PM
  3. unix makefile won't work but works in Dev C++
    By jk1998 in forum C++ Programming
    Replies: 1
    Last Post: 06-09-2007, 03:54 PM
  4. makefile blues....
    By WaterNut in forum C Programming
    Replies: 6
    Last Post: 05-30-2005, 08:22 PM
  5. Need help with Makefile
    By xshapirox in forum C++ Programming
    Replies: 14
    Last Post: 09-28-2004, 03:32 PM