-
March 22nd, 2009, 12:01 AM
#1
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-
-
March 22nd, 2009, 01:14 AM
#2
Re: Makefile for windows
Can somebdy please help me?? Please.
-
March 22nd, 2009, 03:38 AM
#3
Re: Makefile for windows
I've never played with this myself, but is g++ in your path?
-
March 22nd, 2009, 12:05 PM
#4
Re: Makefile for windows
Originally Posted by Marc G
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!
-
March 22nd, 2009, 12:22 PM
#5
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.
-
March 22nd, 2009, 01:42 PM
#6
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!
-
March 22nd, 2009, 01:56 PM
#7
Re: Makefile for windows
Originally Posted by pipa
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
-
March 22nd, 2009, 02:06 PM
#8
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
-
March 22nd, 2009, 02:16 PM
#9
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.
-
March 22nd, 2009, 02:18 PM
#10
Re: Makefile for windows
Originally Posted by pipa
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
-
March 22nd, 2009, 02:42 PM
#11
Re: Makefile for windows
Thanks again.
I don't have main.h. Is that a problem? What should I do in this situation?
Thanks
-
March 23rd, 2009, 08:23 AM
#12
Re: Makefile for windows
Originally Posted by pipa
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/
-
March 23rd, 2009, 01:53 PM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|