![]() |
|
#1
|
|||
|
|||
MAKE file assistanceBelow is my makefile
It works fine as it is I want to put all the .o files into the ../bin/ directory OBJDIR then upon a clean I want the .o's removed from that directory I was able to get the executable to go into the ../exe/ directory and it is removed upon a clean. I have over 80 .cpp files so far. The directory is crowded enough without all the .o's in the way. I cannot get it the .o's to go to the OBJDIR directory. Any help would be appreciated. Code:
Last edited by admin : 07-Feb-2008 at 17:40.
Reason: Please insert your example codes between [CODE] and [/CODE] tags
|
|||
|
#2
|
|||
|
|||
Re: MAKE file assistanceQuote:
Maybe something like: Code:
Regards, Dave |
|
#3
|
|||
|
|||
Re: MAKE file assistanceIn the make file below I now must change the SOURCES line from
SOURCES = a.cpp b.cpp c.cpp d.cpp e.cpp to SOURCES = a.cpp b.cpp c.cpp d.cpp e.cpp f.c I have to compile a .c file also. Can I do this, mixing c and c++. What additional syntax needs to be added? I am getting a "no rule to compile" error on the f.c file. My application will be running the main out of .c code (it is a real time application so .c is the only option for me) I will be calling functions in the c++ code. Thanks emp1953 |
|
#4
|
|||
|
|||
Re: MAKE file assistanceQuote:
In order to make your C++ object files linkable with your C main file, here's the drill. (There are almost surely other ways, but this is the simplest that I can think of off of the top of my pointed little head, just now.) Surround all of the code in your C++ files with extern "C" {} So, for example a.cpp can look like: CPP / C++ / C Code:
b.cpp would look like: CPP / C++ / C Code:
etc. for c.cpp, d.cpp, e.cpp Then the main file, f.c could look like: CPP / C++ / C Code:
Now, stop! Forget the makefile for now, and make absolutely sure that you can compile and execute all of these things. So, from the command line, compile all of your C++ files into object files with "g++ -c" and compile your C file into an object file with "gcc -c". Make sure your files have the proper extensions for that file's compiler. That is important. Code:
Now you should have six object files in the current directory: a.o, b.o, c.o, d.o, e.o and f.o Make an executable with gcc Code:
If you got no errors, then you can execute the program: Code:
If this doesn't work, then let us know. Don't even think about the Makefile unless and until you get this part working. (Obviously, you don't necessarily have to do the whole shebang; just a couple of .cpp files and your main .c file.) Now, are you ready for the next step? The problem with the Makefile approach is that you need a different rule for creating an object file from a C++ file than for creating an object file from a C file. Here's one way: Use a different name (other than the default "xxx.o") for one or the other case. Then you have one rule, using gcc. for the C object file(s) and another rule, using g++, for the C++ object files. Then the makefile (based on my previous example) could look something like: Code:
Regards, Dave Footnote: I have tested everything in my posts in this thread with GNU compilers and the GNU make program on various Linux and Windows/cygwin installations. Nothing is guaranteed by the C (or C++) standard or by me or by anything else that I know of. In other words: IWFM;YMMV (It Works For Me; Your Mileage May Vary) Last edited by davekw7x : 26-Feb-2008 at 18:52.
|
|
#5
|
|||
|
|||
Re: MAKE file assistanceI ran through your first exercise and all went well, no errors and I could execute the output file.
My implementation of the makefile caused the following error; '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''' g++ -c -Wall -g -W -pedantic a.cpp -o ../bin/a.opp Assembler messages: FATAL: can't create ../bin/a.opp: No such file or directory make: *** [../bin/a.opp] Error 1 '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''' My make file is below: CC = gcc CXX = g++ CFLAGS = -c -Wall -g -W -pedantic CXXFLAGS = -c -Wall -g -W -pedantic LDFLAGS = -lnsl OBJDIR = ../bin EXEDIR = ../exe PROG = msg_broker EXECUTABLE = $(EXEDIR)/$(PROG) CXXSOURCES = a.cpp b.cpp c.cpp d.cpp e.cpp CSOURCES = f.c CXXOBJECTS = $(CXXSOURCES:.cpp=.opp) COBJECTS = $(CSOURCES:.c=.o); OBJECTS = $(CXXOBJECTS) $(COBJECTS) OBJFILES = $(addprefix $(OBJDIR)/,$(OBJECTS)) all: $(EXECUTABLE) $(EXECUTABLE): $(OBJFILES) $(CXX) $(LDFLAGS) $^ -o $@ $(OBJDIR)/%.opp : %.cpp $(CXX) $(CXXFLAGS) $< -o $@ $(OBJDIR)/%.o: %.c $(CC) $(CFLAGS) $< -o $@ clean: -rm -rf $(OBJECTS) -rm -rf $(EXECUTABLE) clear |
|
#6
|
|||
|
|||
Re: MAKE file assistanceQuote:
Look at the clean: stuff. Quote:
This removes the directories as well as the files. Now, look at my latest post: Code:
This removes the files but not the directories. If you make it like my most recent post then: Before running the make for the first time, make sure directories ../bin and ../exe exist. (That's what your original Makefile assumed.) Better yet, put shell commands in the Makefile to make sure that those directories exist before trying to access them. Regards, Dave Regards, Dave Last edited by davekw7x : 27-Feb-2008 at 12:19.
|
|
#7
|
|||
|
|||
Re: MAKE file assistanceDave,
The directories are there, before and after. The permissions are wide open. I made the change in the clean: section. I continue to get the same error. g++ -c -Wall -g -W -pedantic a.cpp -o ../bin/a.opp Assembler messages: FATAL: can't create ../bin/a.opp: No such file or directory make: *** [../bin/a.opp] Error 1 |
|
#8
|
|||
|
|||
Re: MAKE file assistanceCould there be an issue with the ".opp" extension as opposed to just the ".o" extension.
|
|
#9
|
|||
|
|||
Re: MAKE file assistanceIf I change .opp to .o I get a "no rule to make it" error
|
|
#10
|
|||
|
|||
Re: MAKE file assistanceDave,
I found that if I changed the lines: OBJDIR = ../bin EXEDIR = ../exe to OBJDIR = . EXEDIR = . That it all compiled and ran fine, I think I know what is wrong. |
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 08:44 |
| Download files in c for windows operating system | oozsakarya | C Programming Language | 5 | 20-Jun-2006 04:33 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 11:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 12:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The