f



How to compile sources file and save object files into a separate directory

Hi there,

I am building a make file to compile many .cpp files in different
directories, and save .o files into one directory. All source file
names are different.

For example:
/prj/cmn/cmn.cpp
/prj/prj1/prj1.cpp
/prj/prj1/main.cpp

Save .o files to 
/out/prj1/cmn.o
/out/prj1/prj1.o
/out/prj1/main.o

I trid to do it like this,

SOURCES := /prj/cmn/cmn.cpp /prj/prj1/prj1.cpp /prj/prj1/main.cpp
OBJECTS := $(addprefix $(OBJDIR)/, $(addsuffix .o, $(basename $(notdir
$(SOURCES)))))

all: /out/prj1/prj1

/out/prj1/prj1 : $(OBJECTS)
	$(LINK.cpp) $(DBG_OPTS) -o /out/prj1/prj1 $(OBJECTS)

/out/prj1/%.o : %.cpp
	$(COMPILE.cpp) $(DBG_OPTS) -o $@ $<

But it does not work. 
Please help me. Thanks in advance.
0
12/29/2003 3:19:00 PM
comp.unix.programmer 10848 articles. 0 followers. kokososo56 (350) is leader. Post Follow

2 Replies
1209 Views

Similar Articles

[PageSpeed] 51

rainbowfish888@yahoo.com (Rainbow Fish) wrote in
news:1e996f7d.0312290719.56d74edb@posting.google.com: 

> I am building a make file to compile many .cpp files in different
> directories, and save .o files into one directory. All source file
> names are different.
> 
> For example:
> /prj/cmn/cmn.cpp
> /prj/prj1/prj1.cpp
> /prj/prj1/main.cpp
> 
> Save .o files to 
> /out/prj1/cmn.o
> /out/prj1/prj1.o
> /out/prj1/main.o
> 
> I trid to do it like this,
> 
> SOURCES := /prj/cmn/cmn.cpp /prj/prj1/prj1.cpp /prj/prj1/main.cpp
> OBJECTS := $(addprefix $(OBJDIR)/, $(addsuffix .o, $(basename $(notdir
> $(SOURCES)))))

Use VPATH for to tell make where to find the sources. Then just set
SOURCES to the names of the files w/o the path. E.g. 

VPATH=/prj/cmn;/prj/prj1


Getting the .o files to go into some other directory, I have only done by
running make on the makefile in the dir that the .o files are to go into.
I'd like to see how to do this correctly too. 


-- 
- Mark ->
--
0
Mark
12/29/2003 3:29:34 PM
# I am building a make file to compile many .cpp files in different
# directories, and save .o files into one directory. All source file
# names are different.

I usually handle this in one of two ways, neither of which is very popular
because they don't depend on using every possible trick gnu make provides.

Solution 1: Go ahead and enumerate all the targets.

all: /out/prj1/prj1
/out/prj1/prj1: /out/prj1/cmn.o /out/prj1/prj1.o /out/prj1/main.o
	$(LINK.cpp) $(DBG_OPTS) -o /out/prj1/prj1 \
		/out/prj1/cmn.o /out/prj1/prj1.o /out/prj1/main.o
/out/prj1/cmn.o: /prj/cmn/cmn.cpp
	$(COMPILE.cpp) $(DBG_OPTS) -o /out/prj1/cmn.o /prj/cmn/cmn.cpp
/out/prj1/prj1.o: /prj/prj1/prj1.cpp
	$(COMPILE.cpp) $(DBG_OPTS) -o /out/prj1/prj1.o /prj/prj1/prj1.cpp
/out/prj1/main.o: /prj/prj1/main.cpp
	$(COMPILE.cpp) $(DBG_OPTS) -o /out/prj1/main.o /prj/prj1/main.cpp


Solution 2: Use a script to create the makefile and do the make

#!/bin/sh
sourceroot=$1
objroot=$2
executable=$3
shift 3
echo all: $executable >makefile
ofiles=""
for cfile in $(find $sourceroot -name '*.cpp' -print)
do
  ofile=$objroot/$(basename -s .cpp $cfile).o
  ofiles="$ofiles $ofile"
  echo $ofile: $cfile \
	'; $(COMPILE.cpp) $(DBG_OPTS) -o' $ofile $cfile\
	 >>makefile
done
echo $executable: $ofiles \
	'; $(LINK.cpp) $(DBG_OPTS) -o ' $executable $ofiles \
	>>makefile
make $*

--
Derk Gwen http://derkgwen.250free.com/html/index.html
You hate people.
But I love gatherings. Isn't it ironic.
0
Derk
12/29/2003 4:00:10 PM
Reply:

Similar Artilces:

object files, header files, source files?
I can't find any books describing the anatomy of C/C++ programs. What is an object file? Can it be generated from a header file?, what is linking?, why does a source file need an object file? etc. I have looked in The C programming Language, The C++ Programming Language, Accelerated C++, GNU make etc but they don't describe these basic subject. Any literature that covers these subjects? saneman wrote: > I can't find any books describing the anatomy of C/C++ programs. What is > an object file? Can it be generated from a header file?, what is > linking?, why does a s...

Saving a compiled source file with the "require"d files
Help. If I have file1 that loads (require file2 and files), is it possible save the content of file file after the load. example: file1 #!perl $a =12; require file2; $b = $z; require file3; $c = $y; print $a; file2 $z = 200; 1; file3 $y = "foo"; 1; So, is it possible to save file1 after loading file2 and file3 file1 becomes: #!perl $a =12; $z = 200; $b = $z; $y = "foo"; $c = $y; print $a; Thanks Ray "Ray Muforosky" <izombe@yahoo.com> wrote: > Help. Please pick one appropriate subject line, and then stick with it. Xho -- -----------...

Copying files from sub folders under source directories into sub folders with same names as source directory sub folders in destination directories without overwriting already existing files of same n
Hi, Consider /src/alias/a.c /src/alias/b.c /src/xml/p.xml /src/xml/c.xml /src/h.c as source directory=20 and=20 /dest/alias /dest/xml /dest as destination directory. These are given in a csv file like /src/alias/a.c, /dest/alias /src/alias/b.c, /dest/alias /src/xml/p.xml, /dest/xml /src/xml/c.xml, /dest/xml /src/h.c, /dest Python code should read csv file. Copy files from source to destination(fil= es in /src/alias should be copied to /dest/alias and not to /dest/xml i.e.,= directory names should be the same). If /dest contains same files as /src,= then they code shoul...

Unix files saved in a D3 file save are changed
Hello All: When I restore an account where the D3 file is actually a Q-pointed Linux directory, a line containing the name of the Linux file is inserted before the rest of the file item. Does anyone know why or how to avoid this? D3 item looks like this: :ED MD DS2.UQ.BIN top ..P 001 QS 002 003 /dsol/dscope/da/bin eoi 003 Linux file before restore: :ED DS2.UQ.BIN mvhttp-client top ..P 001 #!/usr/bin/perl 002 # 003 # Copyright (C) 2015... Linux file after restore: :ED DS2.UQ.BIN mvhttp-client top ..P 001 mvhttp-client 002 #!/usr/bin/perl 003 # 004 # Copyr...

files, directories, files, directories
Hi folks, I've been trying to make a decision and it's driving me crazy. Is a directory a file or is a directory NOT a file but a node? Should I have A) public interface IFile { IFileName FileName; IContent GetContent(); } public interface IDirectory extends IFile { } or B) public interface INode { INodeName NodeName; } public interface IFile extends INode { IContent GetContent(); } public interface IDirectory extends INode { } Method A is nice cause IFile becomes the base "Node" type and you can use names like "IFileName" which sound...

Are files in the same directory as a file being compiled automatically found by a standard following compiler?
Hi, Here's the thing: the Eternity persistence system does not provide its own compilation phase for its source code: the programmer simply has to copy some files to his codebase. Here's the thing though: the author has a .cpp in the "src" directory that contains the other .cpp files, "eternity.cpp", which basically contains: #include "dynamic.cpp" #include "persist.cpp" #include "persist_xml.cpp" #include "xmlscanner.cpp" The directory hierarchy of the package is something like this: $ ls include/ src/ doc/ ...

Getting source file from the object file
Dear Friend Can we get the source file from the object ? example : file a.c cc a.c Now I have a.out But I not have the a.c how could I get the source file using a.out thanks pavunkumar <pavun.bks@gmail.com> writes: > Dear Friend > > Can we get the source file from the object ? Generally, no. > example : > > file a.c > cc a.c > Now I have a.out > But I not have the a.c That's unfortunate. > how could I get the source file using a.out On most systems, it is impossible. Much information is lost in compilatio...

Source distribution, source file settings, files not goint to the desired destination directory
I am tring to set up a number of source distributions for a handful of unique but related programs in LabView 8.0.1.&nbsp; All of the programs&nbsp;have their own unique tasks to comple but they all use a set of basic sub vi's that I wrote.&nbsp; Basically I could have put all those sub vi's into a .lib file but chose not to for the sake of simplicity.&nbsp; Also each program calls a number of vi's from the set of LabView libraries.&nbsp; To summarize what I want to do with my distribution structure;&nbsp;I created four destination&nbsp;directories: Firs...

File could not be saved, no such file or directory exists (2)
"File could not be saved, no such file or directory exists (2)" Keep getting this popping up in a dialog box that won't go away until I clock on OK. If I download 50 emails I'll get circa 10 dialog boxes popping up with this message. I recently upgraded to Eudora 6.1 and paid to register for the first time. This removed the pop-ups for about 1 month. Now they're back. Any ideas? Thanks, Eric Just checked and the message is actually.... "Could not open the file for writing Cause: No such file or directory exists. (2)" "Eric" <Eric@nowhere.com> wrote in message news:c6nls5$ca1$1@newsg1.svr.pol.co.uk... > "File could not be saved, no such file or directory exists (2)" > > Keep getting this popping up in a dialog box that won't go away until I > clock on OK. If I download 50 emails I'll get circa 10 dialog boxes popping > up with this message. > > I recently upgraded to Eudora 6.1 and paid to register for the first time. > This removed the pop-ups for about 1 month. Now they're back. > > Any ideas? > > Thanks, > > > Eric > > The problem you posted about Eudora can be fixed by eliminating files from the Attachment directory of eudora. When eudora has files downloaded with the same name it appends a number file1, file2, file3, etc. it works fine until you have 999 of those files, then it starts...

Source files in JAR file are sometimes compiled
We are building a jar file which includes sources (.java) files for use with tools such as JBuilder that can use the source code for autocompletion etc. On most of our machines, we can use this jar file when building Java applications with no problems. On one machine, if we build the jar file and then add it to the classpath when building another application, the java compiler (1.4.1) tries to compile the java files in the jar (and fails). If we rebuild the jar and then recompile the application, things work fine. I've done a binary diff on the two jars and (as expected) only the timest...

FTP failes to transfer file to target directory; 0 byte file left in source directory
problem is as stated in the file - the file does not appear in the target directory after the running of the FTP script. any assistance is appreciated. Leads and follow up questions: #1) can the source host be the same as the target host? (I have tried the same and a different taget host) #2) from the FTP log: Starting FTP run ################################################################# Thursday June 22 14:10:31 EDT 2006 Connected to tomxg00. 220 [hostname] FTP server (Authorized uses only. All activity may be monitored and reported.) ready. 331 Password required for [username]. 230 ...

How to save the layout and objects from *.fig file to a *.m file?
Hi guys, I am using GUIDE to design a GUI. Now I wanna save the static text and all other objects on that GUI into an M file. I hope to get a file consisting of many uicontrol functions that corresponding to the objects on my GUI. With that M file, I can modify the GUI objects without starting GUIDE but just editing that M file. How can I make it? Sheng Bao wrote: > Hi guys, > > I am using GUIDE to design a GUI. > > Now I wanna save the static text and all other objects on that GUI > into an M file. > I hope to get a file consisting of many uicontrol functions that &g...

Trying to get 40 source files compiled for a mex-file
Trying to create a mex-file using gcc on a Mac. By using the -v option on the command line, I found out that my mexmac file is failing because only 11 files are being included in the compilation and link. Here is my comand line: >>mex -v -g myfile.c your*.c There are about 40 your*.c files. Can I accomplish this without merging the source files? LKD ...

libXm.so.2: cannot open shared object file: No such file or directory
I get the following: /tools/dfII/bin/32bit/libSelect.exe: error while loading shared libraries: libXm.so.2: cannot open shared object file: No such file or directory I therefore added /usr/local/lib to LD_LIBRARY_PATH as libXm.so.2 is there. I then get: Warning: XmeGetColorObjData(): not yet implemented! \o Incompatible Xm library detected! \o Label: 272 != 284 \o xmUseVersion: 2001 \o Motif version 2.1.-1717986918 must be installed. \o /tools/dfII/bin/32bit/libManager.exe is exiting with core file. \o Warning: XmeGetColorObjData(): not yet implemented! I think I am running openmoti...

Error: libgpc.so: cannot open shared object file: No such file or directory.
I usually compile m-files using deploytool and launch it on a grid server. However, at this time, I've got a weird error which is annoying me for several days. The code works fine and gives desired results when it is launched on the Matlab console as an m-file. But, if I try to launch it on the grid server after compiling, it provides the following error message (I tried uninstalling and reinstalling MCR 7.14 several times, but it didn't help): ----------------- ??? Invalid MEX-file '/home/wnam/.mcrCache7.14/CoMP_I1/toolbox/map/map/private/gpcmex.mexa64': libgpc.so: canno...

separating class declaration (header file) and implementation (source file)
Hello, As you will see from the following code snippets, I'm trying to declare a function object in an header file and implement it in a (different) source file, but my compiler complains (he cannot find the implementation I provided, apparently). (the -c option tells the compiler to don't try to link, just compile). $ g++ -c addition.cpp $ g++ -c program.cpp program.cpp: In function `int main()': program.cpp:5: error: no matching function for call to `addition::addition(int, int)' addition.h:2: note: candidates are: addition::addition() addition.h:2: note: ad...

File source for SQLRPGLE compiled object
Hello. i don't know if this has already asked. I do some google search but was unable to get a clue on it. We got a in-house written set of proc that allow selective recompile of our in-house developed app basing on PF/PGM/Mdule/SRVPGM modification. After a long period of nice work (we wrote it back in the 4.2.0 days), it suddendly stopped to recompile SQLRPGLE-generated programs. I was on the way of rewriting it using more 'elegant' approch when i notice that the souce data retrived from the "List program Informatio" API (QBNLPGMI/QBNLSPGM) didn't point to th...

Linkable object files and separate compilation
I think that Scheme really and truly needs the capability of doing separate compilation of files and producing linkable files in some standard format. Modern Kernels and applications are measured in millions of lines of code. You can't even hold the structures in memory to compile all of them at once; linkable object files are flatly a necessity if you're doing major applications. Do people have suggestions for a linkable object file format? Do any schemes with a full numeric tower and fully implemented call/cc produce linkable object files? If so how are the function sign...

Compiler--Compiling a Directory of files
Hi, I used the compiler demo a few months ago and I was able to create a stand-alone program from my MATLAB code. I just purchased a licence and have forgotten what I did to compile. Hopefully someone can help me... I have a directory of like 100 matlab and compiled c / mex files. All of the programs are linked somehow, many times indirectly, to a main matlab file called geomod.m I am trying to compile this directory into a stand-alone program. I've done the mbuild -setup command and chosen my compiler. I typed mcc -m geomod.m When I click on the geomod.exe that was created, the library...

gdm[####]: (null): cannot open shared object file: No such file or directory
I'm stumped by this gdm error/warning message in /var/log/messages. It doesn't specify what library is missing. However, I'm able to login to the desktop without any problems. I thought if I updated the gdm rpm the message would disappear but it did not. I've searched many a website and forum without finding a specific answer to this problem. The other strange thing I see is that gdm has two processes running once I enter the desktop. Maybe this could be the cause, I don't know, just a guess. How can I eliminate this second gdm process at startup? What coul...

file.exe file generation from file.m file
How to generate application (*.exe) file from *.m file, which has lots of graphics. Program was written for image watermarking by using image processing toolbox. I want to send this program some where else but with out sowing the program codes. By this *.exe no need to use matlab6.5 platform. Also tell me How to generate *.p file from *.m file Which is hide the code to user but for run this program need matlab6.5 Please give me some idea about it. it is very urgent for me. I will be very great full to you "Biswajit Kar" <hibiswajitkar@rediffmail.com> wrote in message ne...

iMPACT: "...cannot open shared object file: No such file or directory"
Hi there, I'm trying to run Xilinx iMPACT under slackware. Why can't it find a shared library that's in the executable's directory? root@Valine:/opt/Xilinx/bin/lin# impact impact: error while loading shared libraries: libImpactProcessor.so: cannot open shared object file: No such file or directory root@Valine:/opt/Xilinx/bin/lin# ls libImpactProcessor.so libImpactProcessor.so* root@Valine:/opt/Xilinx/bin/lin# root@Valine:~# echo $XILINX /opt/Xilinx root@Valine:~# echo $PATH /usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin: /usr/games:/opt/www/htdig...

if module file as one of the source files, compile is wrong? (using CVF6.6)
Hi First of all I'd like to say thanks to many guys here answering my questions about module. I started to use it. I name my module file as "mod.f90" included in the beginning of main program. I use Compaq Visual Fortran v6.6. When I compile the main program, the module file is automatically captured as an external dependencies (left dialogue box shows it). When I finished modifying mod.f90. I compile it and CVF ask if I want to insert it into the project. If I insert it, it appears as one source file (shown in left dialogue box). Then compiling is wrong. So everytime I ha...

Recovering .m file source code from -mcc compiled .exe or.ctf file
Hi, I recently had a machine failure and only have some .exe and .ctf files that were compiled from .m files that I would to recover. Is there a way to work backwards through the -mcc compiler process to recover this code? Thanks, Vinny On 18 Jun, 17:42, "Vincent" <atsocdv.fliplrstr...@ufl.edu> wrote: > Hi, > > I recently had a machine failure and only have some .exe and .ctf files that were compiled from .m files that I would to recover. Why didn't you make backup copys? > Is there a way to work backwards through the -mcc compiler process to recover this...

Web resources about - How to compile sources file and save object files into a separate directory - comp.unix.programmer

Wikipedia:Quick directory - Wikipedia, the free encyclopedia
This page is a handy directory to various locations of interest in Wikipedia. Only dynamic pages should be listed here, no policy pages etc. ...

Telephone directory - Wikipedia, the free encyclopedia
"Phone book" and "White pages" redirect here. For a contact list, see Contact list . For other uses, see White pages (disambiguation) . Subscriber ...

Business Directory Listings: Eight Smart Tips for You to Get Started
If you are considering a business directory listing for your small business, congratulations – you are on the right track. Local SEO, local customers, ...

Atlas Partner Directory Launched
... just for Facebook and Instagram –advertising platform Atlas has one, as well. On that note, Atlas Tuesday introduced the Atlas Partner Directory ...

Slack announces App Directory store
... create more apps for the store, and a new framework called Botkit which should simplify the process of creating apps. The Slack App Directory, ...

The British Library’s ‘Save Our Sounds’ Program Creates Directory of UK Sound Collections
The long-feared deterioration of the world's sound collections is a coming to a head with the British Library's last-ditch initiative called ...

Amazon brings Microsoft users into AWS with Active Directory service
Amazon has launched an AWS Directory Service for Active Directory , a fully managed implementation of Microsoft's authentication and user management ...

Hackers leak DHS staff directory, claim DOJ is next
On Sunday, an account on Twitter posted a Department of Homeland Security staff directory with 9,355 names. Shortly after the DHS data was posted, ...

'Twitch Plays' directory makes it easy to find new games
The huge success that is TwitchPlaysPokemon gave rise to a number of other Twitch Plays games, and the video platform wants to make sure you ...

Slack's New Directory And Venture Fund Aim To Make The Service Even More Indispensable
The workgroup wunderkind is helping users find useful tools within the service—and giving startups money to create new ones. Two key facts about ...

Resources last updated: 2/20/2016 9:02:31 PM