pradipto
03-09-2008, 11:49 PM
Hi,
Can I obtain a makefile to compile a sample example program like the xsvdcmp.cpp under cygwin? Even a makefile for unix will do.
In general how do I compile my cpp files that uses the nr files?
Thanks.
p.s. - I have NR C++ 2nd edition.
davekw7x
03-10-2008, 09:46 AM
...compile a sample example program like the xsvdcmp.cpp under cygwin?...
Here's what I did:
The recipes directory could be anywhere. For my installation it is at E:\nr2\cpp. I run the Windows cmd.exe shell on my windows platforms (not bash). I think things work pretty much the same for bash users on Windows platforms.
cd into nr2\cpp\recipes
Execute the following:
E:\nr2\cpp\recipes>g++ -c -I../other *.cpp
It may take a few minutes. With gcc/g++ version 3.4.4 on my Windows XP box and version 2.11 recipe files there were no significant compiler complaints.
Then:
E:\nr2\cpp\recipes>ar cr libnr2cpp.a *.o
(After this, you can delete the .o files if you want to. All you need is the library file)
Now cd into the nr2\examples directory
Here's a GNU Makefile that you can use from the examples directory:
#
# invoke this makefile with something like
# make TARGET=xtwofft
#
CXX = g++
CXXFLAGS = -Wall -W
LD = g++
INCLUDEDIR = ../other
LIBDIR = ../recipes
LIBFILE = nr2cpp
INCLUDES = -I$(INCLUDEDIR)
LIBS = -L$(LIBDIR) -l$(LIBFILE)
EXEEXT = .exe
TARGET = test
EXECUTABLE = $(TARGET)$(EXEEXT)
OBJS = $(TARGET).o
$(EXECUTABLE): $(OBJS)
$(LD) $(OBJS) $(LIBS) -o $(TARGET)
.cpp.o:
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
clean:
rm -f $(OBJS) $(TARGET)$(EXEEXT)
At this point you should be able to compile a file by doing something like
E:\nr2\cpp\examples>make TARGET=xsvdcmp
I like really short command lines, so I made a little batch file, m.bat:
@make TARGET=%*
Then:
E:\nr2\cpp\examples>m xsvdcmp
g++ -Wall -W -I../other -c xsvdcmp.cpp -o xsvdcmp.o
g++ xsvdcmp.o -L../recipes -lnr2cpp -o xsvdcmp
E:\nr2\cpp\examples>
To run the files as-is, you can copy the various data files (matrx1.dat, etc.) into the examples directory. Or you could modify the source files to show the path to the data files (#include "../data/matrx3.dat", for example).
Note that, depending on how you installed cygwin, you might have to run dos2unix on the data files to get results. (For example: matrx1.dat for xgaussj didn't work until I converted it.)
Regards,
Dave
Footnote: Of course you can copy the library and header files to somewhere under your cygwin\lib and cygwin\include directories and modify the INCLUDEDIR and LIBDIR variables in Makefile accordingly. Then you can make it from anywhere, not just the examples directory. Of course you would (probably) also customize the Makefile for your project files, then just run make with no arguments.