Thread: Makefile Problem: None rule to make target

  1. #16
    Registered User
    Join Date
    Mar 2009
    Posts
    37
    Hello guys,

    Instead of opening a new subject, I rather continue with this subject.
    Anyway, I compile/build a project with Autotools and have an issue with it.
    GCC seems to use some default flags like: -g -O2
    In the Makefile.am I have the following:
    AM_CFLAGS = -Wall
    When it compiles I see output like that "gcc somefile.c -Wall -g -O2"
    If I modify AM_CFLAGS to "-Wall -g3 -O0" I assume to get an executable for best debugging. But the output is like this: "gcc somefile.c -Wall -g3 O0 -g -O2"
    So I guess the source files will finally be compiled according to -g -O2 flags.

    The problem is when debugging, some parts of the source are optimized away and so can't see what happens.

    How can I turn off the gcc default flag or modify it?

    Thanks in advance.
    Last edited by Andaluz; 06-10-2009 at 08:19 AM.

  2. #17
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Andaluz View Post
    Hello guys,

    Instead of opening a new subject, I rather continue with this subject.
    Anyway, I compile/build a project with Autotools and have an issue with it.
    GCC seems to use some default flags like: -g -O2
    In the Makefile.am I have the following:
    AM_CFLAGS = -Wall
    When it compiles I see output like that "gcc somefile.c -Wall -g -O2"
    If I modify AM_CFLAGS to "-Wall -g3 -O0" I assume to get an executable for best debugging. But the output is like this: "gcc somefile.c -Wall -g3 O0 -g -O2"
    So I guess the source files will finally be compiled according to -g -O2 flags.

    The problem is when debugging, some parts of the source are optimized away and so can't see what happens.

    How can I turn off the gcc default flag or modify it?

    Thanks in advance.
    Have you tried re-configuring?

    Code:
    $ CFLAGS='-g -O0' ./configure
    If that doesn't work, open Makefile.in, search for where those flags are being set, remove them, and re-configure.

    (I despise autoconf, by the way)
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #18
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by brewbuck View Post
    (I despise autoconf, by the way)
    Quote Originally Posted by brewbuck View Post
    As soon as you've formed an opinion you're already wrong.
    Sorry, couldn't resist.

  4. #19
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Kennedy View Post
    Sorry, couldn't resist.
    Well, it's more of an emotion than an opinion

    But I admit to being one of the wrongest people alive.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #20
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Oh my gosh. I can't believe I put $(SOURCES) in the clean target! I'm very sorry . . . .

    I knew I should have copied a working Makefile rather than try to type one up on the spot. Sigh.

    Here's a real makefile, for my project nort. You should be able to modify it as necessary, if you still trust me after all this.
    Code:
    # Makefile for nort
    
    CXX = g++
    CXXFLAGS = -W -Wall -ansi -pedantic -g -I /usr/include/SDL
    LDFLAGS = -lSDL -lSDLmain
    SOURCES = $(wildcard *.cpp)
    OBJECTS = $(SOURCES:.cpp=.o)
    TARGET = nort
    
    # Default target: all
    .PHONY: all
    all: $(TARGET)
    
    # Executable files
    $(TARGET): $(OBJECTS)
    	$(CXX) $^ -o $@ $(LDFLAGS)
    
    # Dependencies
    include depend
    
    .PHONY: depend
    depend: $(SOURCES)
    	$(CXX) $(CXXFLAGS) -MM $(SOURCES) > depend
    
    # Other targets
    .PHONY: clean
    clean:
    	-$(RM) $(OBJECTS) $(TARGET)
    (I despise autoconf, by the way)
    I don't much like it either. Here's one good reason: when I was creating xuni, I originally used autoconf and friends to make a build system, and then I tried making the build system in CMake. CMake compiled the whole project faster than autoconf did, and I don't think that was including the time to run ./configure.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #21
    Registered User
    Join Date
    Mar 2009
    Posts
    37
    Hi guys,

    Thanks for your replies.
    Brewbuck, I don't think ./configure would affect the compiler options. Cause, AFAIK, ./configure is just to check which compilers, libraries etc... are available to use to get the same result on another platform (Linux, FreeBSD, x86, Motorola 68xxx whatever). But the make is actually compiling (first automake to generate Makefile out of Makefile.am) the sources with the right compiler (determined by ./configure). In Makefile you can add the compiler flags, like the following example:
    Code:
    INCLUDES = $(all_includes) -I$(top_srcdir)/include
    AM_CFLAGS=-Wall -g3 -O0         # O0 turns off optimization
    
    sbin_PROGRAMS = babewatch
    noinst_LIBRARIES = libabc.a libxyz.a
    noinst_HEADERS = vty/cardshell.h
    
    libabc_a_SOURCES = bisa.c babes.c...
    When build the project I get this after executing make:
    Code:
    I../include   -Wall     -g3 -O0          -g -O2 -MT gsm.o -MD -MP -MF .deps/gsm.Tpo -c -o gsm_u.o gsm_u.c
    mv -f .deps/gsm_u.Tpo .deps/gsm_u.Po
    gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\"
    -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE=\"projectname\"
    -DVERSION=\"0.0alpha1\" -DSTDC_HEADERS=1 -I.  -I../include   -Wall     -g3 -O0          -g -O2 -MT
    As you can see there is -g3 -O0 as well as -g -O2, so what overrules what?

    Thank you.
    Last edited by Andaluz; 06-11-2009 at 02:28 AM.

  7. #22
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    @dwks:
    May I advise you to use, in stead of making the actual compiler and linker flags for SDL, doing something like:
    CXXFLAGS=[...] `sdl-config --cflags`
    LDFLAGS=[...] `sdl-config --libs`
    That should be more portable at least .

  8. #23
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Andaluz View Post
    Brewbuck, I don't think ./configure would affect the compiler options. Cause, AFAIK, ./configure is just to check which compilers, libraries etc... are available to use to get the same result on another platform (Linux, FreeBSD, x86, Motorola 68xxx whatever).
    I've done it hundreds of times with no problem.

    As you can see there is -g3 -O0 as well as -g -O2, so what overrules what?
    -g and -O are independent -- both will be active. Whichever -g is listed last takes effect. Whichever -O is listed last takes effect. In your case, you are getting "-g -O2"
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  9. #24
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Quote Originally Posted by EVOEx View Post
    @dwks:
    May I advise you to use, in stead of making the actual compiler and linker flags for SDL, doing something like:
    CXXFLAGS=[...] `sdl-config --cflags`
    LDFLAGS=[...] `sdl-config --libs`
    That should be more portable at least .
    I suppose so. I'll have to consider it.
    Code:
    CXXFLAGS=[...] $(shell sdl-config --cflags)
    Brewbuck, I don't think ./configure would affect the compiler options. Cause, AFAIK, ./configure is just to check which compilers, libraries etc... are available to use to get the same result on another platform (Linux, FreeBSD, x86, Motorola 68xxx whatever). But the make is actually compiling (first automake to generate Makefile out of Makefile.am) the sources with the right compiler (determined by ./configure). In Makefile you can add the compiler flags, like the following example:
    Remember that ./configure generates the Makefile in the first place. So you can tell it how to generate the Makefile if you like.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #25
    Registered User
    Join Date
    Jun 2009
    Posts
    2
    Hello everybody,

    first a request for Brewbuck:
    I have similar templates for projects using mixed C/C++, and some more complicated examples of build processes that have more steps in them, if you ever want more examples of makefile tricks.
    Can you post some examples for mixed C/C++ ? I seem to have trouble getting something similar. I get the "No rule to make target... error" while I think I do have the rule and the source file correctly. I haven't written a complicated makefile from scratch before, and what I am doing is now is modifying a makefile for a PCIe driver in C generated by Windriver, to introduce some gui and manipulation functions I wrote in C++. Here's an excerpt from the makefile:

    Code:
    TARGET = adc
    SRCS = ../MainControlMenu.cxx ../OffLineDataAnalyzer.cxx ../Dict.cxx ../AdcControl.c ../atlas_lib.c $(WD_BASEDIR)/samples/shared/diag_lib.c $(WD_BASEDIR)/samples/shared/wdc_diag_lib.c
    
    LD = g++
    
    OD = ./
    OBJS = $(addsuffix .o, $(addprefix $(OD)/, $(basename $(notdir $(SRCS)))))
    
    
    all : $(TARGET)
    
    $(TARGET) : $(OBJS)
    	$(LD) $(LFLAGS) -o $@ $(OBJS) $(ADDITIONAL_LIBS) 
    
    MainControlMenu.o : MainControlMenu.cxx
    	$(CC) -c $(CFLAGS) -o $@ $<
    
    OffLineDataAnalyzer.o : OffLineDataAnalyzer.cxx
    	$(CC) -c $(CFLAGS) -o $@ $<
    
    Dict.o : Dict.cxx
    	$(CC) -c $(CFLAGS) -o $@ $<
    
    
    AdcControl.o : ../AdcControl.cxx
    	$(CC) -c $(CFLAGS) -o $@ $< 
    
    atlas_lib.o : ../atlas_lib.c
    	$(CC) -c $(CFLAGS) -o $@ $< 
    
    diag_lib.o : $(WD_BASEDIR)/samples/shared/diag_lib.c
    	$(CC) -c $(CFLAGS) -o $@ $< 
    
    wdc_diag_lib.o : $(WD_BASEDIR)/samples/shared/wdc_diag_lib.c
    	$(CC) -c $(CFLAGS) -o $@ $<
    I added the cxx files and changed LD to g++. Without the MainControlMenu.cxx and OffLineDataAnalyzer.cxx files it actually works. I mean the main AdcControl.cxx source file compiles ok with the C files and works. I just wanted to shift the main function to the gui and compile together with the other two but i get the error message:

    Code:
    make: Entering directory `/home/atlas/standaloneGui/linux'
    make: *** No rule to make target `MainControlMenu.cxx', needed by `MainControlMenu.o'.  Stop.
    Does anybody have any advice for this Makefile newbie?

    Thanks

  11. #26
    Registered User
    Join Date
    Jun 2009
    Posts
    2
    Stupid me... I put the source file path correct but I put it wrong in the rule list. It shout have had ../ in front of them.
    Sorry for that, but in any way, if anybody has advice on mixing C/C++ I would appreciate it.

    (It starts compiling now, but it has other issues, of course)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple problem with "include" definition and makefile
    By junketeer in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2009, 03:01 AM
  2. Trying to make C++ DLL, got a problem with hWnd
    By Ragoune in forum C++ Programming
    Replies: 8
    Last Post: 03-11-2009, 03:24 PM
  3. BSD make and GNU make problem
    By Skarr in forum Linux Programming
    Replies: 4
    Last Post: 09-10-2002, 12:31 PM
  4. stack make file problem
    By puckett_m in forum C Programming
    Replies: 2
    Last Post: 11-22-2001, 11:51 AM
  5. using MAKE with makefile to create executable file
    By sballew in forum C Programming
    Replies: 1
    Last Post: 11-19-2001, 12:49 PM