Jump to content

please help with the Makefile

- - - - -

  • Please log in to reply
4 replies to this topic

#1
alice06

alice06

    Newbie

  • Members
  • PipPip
  • 14 posts
Hi All

I am a Ph.D student in Physics and a newbie in programing. I am running a code made by someone else and now I am stuck badly at a point.
I have a set of C codes [A1.c, A2.c, A3.c, A4.c].
A2.c, A3.c and A4.c have different tasks and A1.c is the main program which is calling the other 3 codes as and when required.
To compile all of them togtether, I have a Makefile which is :

LIBS= -lm 

CPATHS= -L /usr/local/lib

ALL : prog

prog :	A1.c

	cc $(CPATHS) -O4 -Wall -o prog A1.c A2.c A3.c A4.c $(LIBS) 

clean :

	rm prog

To compile and run, I do the following :

alice@alice-laptop:~$ make clean
alice@alice-laptop:~$ make
alice@alice-laptop:~$ ./prog value1 value2


But now I have identified some problem in A4.c and need to use a package, SUNDIALS package.
To run a single code, say equations.c, INDEPENDENTLY (i.e. not being compiled simultaneously with other codes) in SUNDIALS, I have to run a command :

alice@alice-laptop:~$ cc -I/usr/local/sundials/include equations.c -L/usr/local/sundials/lib -lsundials_cvode -lsundials_nvecserial -lm

But now I have to run A4.c using SUNDIALS, along with the other codes (i.e. A1.c A2.c A3.c), as I was doing earlier.

What modifications should I make in my Makefile so that A1.c A2.c A3.c A4.c are all compiled together, as it was being done earlier, but A4.c can also use the package SUNDIALS ??


Please help.
Regards
Alice

#2
alice06

alice06

    Newbie

  • Members
  • PipPip
  • 14 posts
Hi All

I am a Ph.D student in Physics and a newbie in programing. I am running a code made by someone else and now I am stuck badly at a point.
I have a set of C codes [A1.c, A2.c, A3.c, A4.c].
A2.c, A3.c and A4.c have different tasks and A1.c is the main program which is calling the other 3 codes as and when required.
To compile all of them together, I have a Makefile which is :

LIBS= -lm 

CPATHS= -L /usr/local/lib

ALL : prog

prog :	A1.c

	cc $(CPATHS) -O4 -Wall -o prog A1.c A2.c A3.c A4.c $(LIBS) 

clean :

	rm prog


To compile and run, I do the following :

alice@alice-laptop:~$ make clean

alice@alice-laptop:~$ make

alice@alice-laptop:~$ ./prog value1 value2

But now I have identified some problem in A4.c and need to use a package, SUNDIALS package.

To run a single code, say equations.c, INDEPENDENTLY (i.e. not being compiled simultaneously with other codes) in SUNDIALS, I have to run a command :

alice@alice-laptop:~$ cc -I/usr/local/sundials/include [B]equations.c[/B] -L/usr/local/sundials/lib -lsundials_cvode -lsundials_nvecserial -lm

But now I have to run A4.c using SUNDIALS, along with the other codes (i.e. A1.c A2.c A3.c), as I was doing earlier.

I have made the modifications in A4.c so that it can use the SUNDIALS package and can be run simultaneously with the other 3 codes (A1.c A2.c A3.c). Bot I don't know how to compile it since A4.c needs the command somewhat like :
alice@alice-laptop:~$ cc -I/usr/local/sundials/include [B]A4.c[/B] -L/usr/local/sundials/lib -lsundials_cvode -lsundials_nvecserial -lm
and at the same time it has to be in the Makefile, as was earlier.

What modifications should I make in my Makefile so that A1.c, A2.c, A3.c and A4.c are all compiled together, as it was being done earlier, but A4.c can also use the package SUNDIALS ??


Please help.
Regards
Alice

#3
alice06

alice06

    Newbie

  • Members
  • PipPip
  • 14 posts
Please somebody help

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
I'm not strong on makefiles, but it seems that you're doing a "build all" vs "build none" approach. The strength of makefiles is you can specify file dependencies for each build, and it will check when each file was last made. You appear to be making a glorified batch script.

GNU `make'
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
alice06

alice06

    Newbie

  • Members
  • PipPip
  • 14 posts
The following Makefile, given to me by a friend brewbuck, solves the problem

LIBS= -lm -L/usr/local/sundials/lib -lsundials_cvode -lsundials_nvecserial

CPATHS= -L /usr/local/lib -I/usr/local/sundials/include

ALL : prog

prog :	A1.c

	cc $(CPATHS) -O4 -Wall -o prog A1.c A2.c A3.c A4.c $(LIBS) 

clean :

	rm prog

But Thank u all for helping me out. This forum is really helpful.

Alice




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users