Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: g++ makefile problem

  1. #1
    Join Date
    Feb 2007
    Beans
    8

    g++ makefile problem

    I'm learning to create makefiles for my g++ code and I could use some help with an error I'm getting. I have the compile section of the makefile working ok, but I can't get my "clean" section to work. When I enter the command, "make clean" from the command prompt, I get the following error:

    make : *** No rule to make target 'clean'. Stop.

    Here is my make file:
    ==================================

    # Compile-Assemble-Link project:
    rc: rc.cpp io.o io.h
    g++ rc.cpp io.o -o rc
    #
    # Compile and Assemble components:
    io.o: io.cpp io.h
    g++ -c io.cpp
    #
    # File cleanup:
    clean:
    -rm -f *.o core

    Can anyone tell me what the problem is with the makefile? Note: Even though the message doesn't show it, there are correct tabs on each build line as expected.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Beans
    961

    Re: g++ makefile problem

    ok, this doesn't really answer your question but i'm going to suggest that you should use another build-tool when you have this opportunity

    examples are
    * scons ( sudo aptitude install scons )
    * cmake

    ..i know scons well and can help you get started with it; it is a major improvement over plain make (which has many flaws) ..

    a SConstruct-file that does the same thing as your Makefile looks like:

    Code:
    # Construction environments
    ###########################
    
    dbg = Environment(CCFLAGS = '-g -Wall -std=c99',
                      CXXFLAGS = '-g -Wall')
    
    rel = Environment(CCFLAGS = '-O2 -Wall -std=c99',
                      CXXFLAGS = '-O2 -Wall')
    
    
    # Current set environment
    #########################
    env = dbg
    
    
    env.Program('rc', ['rc.cpp', 'io.cpp'])
    and..that's it! .. type scons -u to build, and scons -c to clean .. and ask if you have any problems getting started

  3. #3
    WW is offline Iced Blended Vanilla Crème Ubuntu
    Join Date
    Oct 2004
    Beans
    1,532

    Re: g++ makefile problem

    I cut-and-pasted your example into a file, added tabs in front of the g++ and -rm lines, and saved it as Makefile. Then the command "make clean" worked fine for me. Did you run the command in the correct directory? Is your file named "Makefile" or "makefile"? (To use any other name, you will have to use the -f option with the make command.) You will get the error "make: *** No rule to make target `clean'. Stop." if the make command doesn't find "Makefile" or "makefile" (or if there is no "clean" target in the file).

    If you do have the Makefile in the directory where you ran "make clean", how about attaching it to a post here, so we can see *exactly* what is in the file.

    I agree with Inostdal that using something like scons or cmake would be better in the long term, but it is definitely worthwhile to learn how to create and use a basic Makefile.

  4. #4
    Join Date
    Feb 2007
    Beans
    8

    Smile Re: g++ makefile problem

    WW,
    Thank you for your reply and for running the makefile. That helps knowing the syntax for the file is correct. The name of the file is Makefile. I run the command line command "make clean" from the the directory where the makefile is located and where the .cpp source files are located. So I'm not sure what is causing the error. Any suggestions where to go from here?

    On the question of another make tool. I have learned over the years to use the tools you have at hand first, then explore other alternatives. Changing because you can't get it to work sometimes causes more problems in the long run. Having come from using Visual Studio for quite a while, the g++ compiler with Gedit and make is rather refreshing. I've gotten rather tired of complicated, bloated tools. Simplicity has it's place. *grin*

    Thanks guys for your help.

  5. #5
    WW is offline Iced Blended Vanilla Crème Ubuntu
    Join Date
    Oct 2004
    Beans
    1,532

    Re: g++ makefile problem

    There must be something wrong in your version of the Makefile. I have attached my version of the file you posted earlier. (I had to gzip it in order to attach it here.) Is it the same as yours? Save it in a different directory (say, /tmp), and try "make clean" in that directory (you won't need the source code files just to test "make clean").
    Attached Files Attached Files

  6. #6
    Join Date
    Feb 2007
    Beans
    8

    Re: g++ makefile problem

    Well, you are right. There must have been a format mistake somewhere.
    Here is the results which is now correct with the makefile you sent me back.

    > cd testing
    > ls
    Makefile Makefile.gz
    > make clean
    rm -f *.o core
    >

    Maybe I had a space somewhere. Well, thank you both for your help. I love this
    forum and Ubuntu(Linux)! Take care.

  7. #7
    Join Date
    Jan 2006
    Beans
    961

    Re: g++ makefile problem

    Quote Originally Posted by 2many2count View Post
    On the question of another make tool. I have learned over the years to use the tools you have at hand first, then explore other alternatives. Changing because you can't get it to work sometimes causes more problems in the long run.
    this is true when you have a significant investment in tools you already know - it is not so true when this is not the case as i believe this to be here (edit: at the starting cross-roads)

    i strongly suggest you to reconsider when you clearly have the opportunity of a better way with absolutely no significant "step back" for relearning

    i'll even promise to help you so you'll have immediate equivalent and even _better_ results than what you already have or are able to do with `make' at all times

    .. if you don't believe me i'll stop "bothering" you ..

    Having come from using Visual Studio for quite a while, the g++ compiler with Gedit and make is rather refreshing. I've gotten rather tired of complicated, bloated tools. Simplicity has it's place. *grin*
    i agree completely, and that is why you should know that `make' does have _actual flaws_ that complicate things instead of simplify them .. this is _not_ a matter of taste or personal opinion/preferences from my side .. this makes `make' _more_ complex and hard to use than for instance scons ..

    setting up Gedit to call "scons -u" instead of "make" is a trivial task and you will save time and be more productive in this way without losing _any_ simplicity (you gain it) or "to the bones" knowledge/control
    Last edited by lnostdal; February 28th, 2007 at 05:42 AM.

  8. #8
    Join Date
    Feb 2007
    Beans
    8

    Re: g++ makefile problem

    lnostdal ,
    I agree with that and you are not bothing me. I still have a lot to learn about programming tools for Ubuntu/Linux. Sometimes the number of applications/utilities available in Linux can be overwhelming trying to find solid reliable tools. I will be installing scons tonight look forward to discussing it with you once I get it installed and played with it some. Thanks for writing back and I hope we can discuss scons again soon. Thank you for your help. Take care.

  9. #9
    Join Date
    Feb 2007
    Beans
    8

    Re: g++ makefile problem

    Ok, I found the problem. As WW said, it was a formatting issue. I have two PCs, one running desktop and the other server. I was using Gedit for my makefile editing on my desktop pc and the makefile worked fine. I had to use nano on my server box. Nano was inserting spaces for the tab. Is there a way to configure nano to use a tab instead of spaces for a tab? I used VI (yuck) and fixed the problem.

    Now I can get on to exploring scons as lnostdal suggested. Thanks again for the help.

  10. #10
    Join Date
    Jan 2006
    Beans
    961

    Re: g++ makefile problem

    Quote Originally Posted by 2many2count View Post
    Ok, I found the problem. As WW said, it was a formatting issue. I have two PCs, one running desktop and the other server. I was using Gedit for my makefile editing on my desktop pc and the makefile worked fine. I had to use nano on my server box.
    sshfs is great for remote editing:

    Code:
    sshfs lars@nostdal.org:/ ~/mounts/nostdal.org
    cd ~/mounts/nostdal.org/home/lars/public_html
    gedit index.html
    ~/mounts/nostdal.org is just a directory i use as a mount-point in my home-folder as you see .. (i watch DVD movies from my server over the wireless network using this btw.)

    you use fusermount -u -z ~/mounts/nostdal.org to unmount

    you can also execute a command remotely, like this:

    Code:
    lars@ibmr52:~$ ssh lars@nostdal.org gcc --version
    gcc (GCC) 4.1.2 20061028 (prerelease) (Debian 4.1.1-19)
    Copyright (C) 2006 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
    lars@ibmr52:~$
    ..so you can both edit and trigger compilation (execute scons -u) on a remote computer

    Nano was inserting spaces for the tab. Is there a way to configure nano to use a tab instead of spaces for a tab? I used VI (yuck) and fixed the problem.
    that's weird; i tried nano here just now (ubuntu feisty) and it inserts a tab-character (0x09) when i press tab .. the -E argument to nano converts tabs to spaces but that's probably not the problem
    Last edited by lnostdal; February 28th, 2007 at 07:57 PM.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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