CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Feb 2007
    Posts
    112

    Makefile for windows

    Hi All,
    I hope I am not doing some unusual thing. I use to work in EMACS and used GDB for running and compiling my C++ code in LINUX environment. I have to move to windows now but I do not want to leave EMACS and GDB. I installed g++ and EMACS in windows successfully but I am unable to run the program because of the makefile errors. I get the following error:
    Code:
    make
    make: *** No rule to make target `main.o', needed by `main.exe'.  Stop
    Here is my makefile which I used in linux:
    Code:
    EXEC	= main.exe
    
    CC	= g++ -g -O2 -Wall 
    
    CSRC 	= main.cpp Eulerian.cpp Util.cpp  advectPar.cpp Random.cpp Dispersion.cpp Turbulence.cpp LocalMixing.cpp
    
    COBJS   = $(CSRC:.cpp=.o)
    
    
    $(EXEC): $(COBJS)
    	$(CC) -o $(EXEC) $(COBJS)  
    
    %.o : %.cpp %.h
    	$(CC)  -c $<
    
    clean:
    	rm -f $(EXEC) *.o *.o
    Thanks a lot in advance.

    Pipa-

  2. #2
    Join Date
    Feb 2007
    Posts
    112

    Re: Makefile for windows

    Can somebdy please help me?? Please.

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Makefile for windows

    I've never played with this myself, but is g++ in your path?
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  4. #4
    Join Date
    Feb 2007
    Posts
    112

    Re: Makefile for windows

    Quote Originally Posted by Marc G View Post
    I've never played with this myself, but is g++ in your path?
    Yeah, g++ is in my path. It works fine from the Dos prompt.

    Thanks for you reply!

  5. #5
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: Makefile for windows

    You could call make with the -d switch to see if make recognices the implicit rule .cpp -> .o
    Kurt

    edit:
    try to add this rule
    Code:
    %.o:    %.cpp
            $(CC) -c $< $(CFLAGS) -o $@
    Another EDIT:
    Played a little with your makefile.
    The only case where I could reproduce your error message was when main.cpp was missing.
    Kurt
    Last edited by ZuK; March 22nd, 2009 at 01:35 PM.

  6. #6
    Join Date
    Feb 2007
    Posts
    112

    Re: Makefile for windows

    Thanks for your reply.
    I did "make -d" and Emacs printed out a lot of lines...which I was not able to understand.

    Also, I dont have any variable named CFLAGS. Can I still use the above rule you stated in your reply?

    Thanks a lot for your reply!

  7. #7
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: Makefile for windows

    Quote Originally Posted by pipa View Post
    I dont have any variable named CFLAGS. Can I still use the above rule you stated in your reply?
    That should not matter but I noticed that you alredy have a rule
    Code:
    %.o : %.cpp %.h
    	$(CC)  -c $<
    This is basically the same and should work as well.


    Are you shure there is a file main.cpp ? ( see the edit of my last post ).
    Kurt
    EDIT: Just noticed that all the all the other filenames start with a Uppercase letter. Could imagine that GNU make makes a difference between main.cpp and Main.cpp even on Windows.
    Kurt

  8. #8
    Join Date
    Feb 2007
    Posts
    112

    Re: Makefile for windows

    Yeah, I have a file named main.cpp in that folder.

    if I compile by using "make -k"
    I get the fllowing:
    Code:
    g++ -g -O2 -Wall   -c Eulerian.cpp
    In file included from Eulerian.cpp:5:
    Turbulence.h:19: warning: `class turbulence' has virtual functions but non-virtual destructor
    In file included from Eulerian.cpp:6:
    LocalMixing.h:14: warning: `class localMixing' has virtual functions but non-virtual destructor
    Eulerian.cpp: In method `void eulerian::createEul(const class util &)':
    Eulerian.cpp:23: no matching function for call to `vector<double,__default_alloc_template<false,0> >::at (int &)'
    Eulerian.cpp: In method `void eulerian::uniform()':
    Eulerian.cpp:63: no matching function for call to `vector<eulerian::wind,__default_alloc_template<false,0> >::at (int &)'
    Eulerian.cpp:64: no matching function for call to `vector<eulerian::wind,__default_alloc_template<false,0> >::at (int &)'
    Which indicates that i have main.cpp.

    Thanks for your quick replies.

    Thanks

  9. #9
    Join Date
    Jan 2009
    Posts
    596

    Re: Makefile for windows

    This rule:

    Code:
    %.o : %.cpp %.h
    	$(CC)  -c $<
    will only work for main.o if you have both main.cpp and main.h. Presumably you don't have the latter.

  10. #10
    Join Date
    Oct 2002
    Location
    Austria
    Posts
    1,284

    Re: Makefile for windows

    Quote Originally Posted by pipa View Post
    Which indicates that i have main.cpp.
    Does it ?
    To me it only indicates that the first action was to compile the second file because you told to keep going even if there are errors ( -k )
    Kurt

  11. #11
    Join Date
    Feb 2007
    Posts
    112

    Re: Makefile for windows

    Thanks again.
    I don't have main.h. Is that a problem? What should I do in this situation?

    Thanks

  12. #12
    Join Date
    Jan 2009
    Posts
    596

    Re: Makefile for windows

    Quote Originally Posted by pipa View Post
    Thanks again.
    I don't have main.h. Is that a problem? What should I do in this situation?

    Thanks
    You do not need the %.h prerequisite for the %.o target rule.
    This is the rule you need:
    Code:
    %.o : %.cpp
    	$(CC)  -c $<
    Incidentally, this rule (or one functionally equivalent) is one of the built-in rules for GNU make, so you don't even need this in your makefile.

    Then, you need to add rules outlining the dependencies of the particular object files on the header files, e.g.

    Code:
    Eulerian.o : Eulerian.h Util.h // Or whatever header files Eulerian.cpp includes
    Util.o : Util.h
    advectPar.o : advectPar.h
    etc...
    You can also use g++ to calculate the dependencies on header files for you. The GNU Make manual explains all this much more thoroughly than I can:
    http://www.gnu.org/software/make/manual/

  13. #13
    Join Date
    Feb 2007
    Posts
    112

    Re: Makefile for windows

    Thanks Peter_B, I will try this out and read the manual.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured