Thread: Makefile help please

  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( ~_')

  2. #2
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    Sorry, I realized that the error was caused because SDL wasn't correctly installed after all (I copied the wrong folder by mistake when installing). So, I changed that, and now I don't get the same error.

    However, I do get this error (keeping the original Makefile):

    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.
    Looks like it has problems with the comment after all.

    Once again, I am a total newbie when it comes to makefiles, so I would assume that it is in my Makefile that the error is!

    Edit: The strange this is that, if I remove the comment "#Link .", it DOES compile, but it leaves the following message:

    Code:
    mingw32-make -k 
    rm main.o #Remove .o
    process_begin: CreateProcess(NULL, rm main.o #Remove .o, ...) failed.
    make (e=2): The system cannot find the file specified.
    mingw32-make: *** [all] Error 2
    CreateProcess failed? And "make (e=2): The system cannot find the file specified", what does this mean?
    Last edited by TriKri; 09-24-2009 at 12:19 AM.
    Come on, you can do it! b( ~_')

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Did you install MSYS too? "rm" is not necessarily there for you on Windows (and you should investigate what make tool you're using that doesn't recognize # comments, since you can see #remove there in your command). I'm guessing that 2 is the error code from make.

  4. #4
    Algorithm engineer
    Join Date
    Jun 2006
    Posts
    286
    Quote Originally Posted by tabstop View Post
    Did you install MSYS too? "rm" is not necessarily there for you on Windows (and you should investigate what make tool you're using that doesn't recognize # comments, since you can see #remove there in your command). I'm guessing that 2 is the error code from make.
    You're so right! I forgot that I didn't have rm! Now when I installed msys and added the bin folder to my path, everything worked, and I can use make to instead of mingw32-make, I should always install msys! Thank you!
    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