LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-13-2009, 06:15 AM   #1
karthik.c
LQ Newbie
 
Registered: Mar 2009
Distribution: linux-centos(Red Hat 3.4.6-10)
Posts: 7

Rep: Reputation: 0
problem in finding path of sourcefiles in makefile


hi guys im trying to write a makefile which contains :two cpp files and two header files.
now i've put cppfiles in a folder called source whose path is: /root/workspace/source

and header files in a folder called header whose path is:
/root/workspace/makedemo/header

my makefile is in the path:/root/workspace/makedemo

my makefile was like this:

Code:
HEADERS = $(shell /root/workspace/makedemo/header ls *.h)
SOURCES = $(shell /root/workspace/source ls *.cpp)

COMPILERFLAGS = -W -Wall
DEBUGFLAGS = -g
CPPCOMPILER = g++

INCLUDES = -I.


OBJS = $(SOURCES:.cpp=.o)

BINARY = output

all: $(BINARY)

$(BINARY): $(OBJS)
        $(CPPCOMPILER) $(COMPILERFLAGS) $(INCLUDES) -o $(BINARY) $(OBJS)
depend:
        makedepend -f- -- $(SOURCES) > .depend_file
clean:
        rm -rf *.o .depend_file $(BINARY) *~

#DO NOT DELETE
im sure that i've given the correct path but it is showing errors like this:

[root@localhost makedemo]# make
/bin/sh: /root/workspace/source: is a directory
/bin/sh: /root/workspace/source: is a directory
g++ -W -Wall -I. -o output
g++: no input files
make: *** [output] Error 1

any help appreciated...
 
Old 03-13-2009, 06:22 AM   #2
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
Quote:
Originally Posted by karthik.c View Post
hi guys im trying to write a makefile which contains :two cpp files and two header files.
now i've put cppfiles in a folder called source whose path is: /root/workspace/source

and header files in a folder called header whose path is:
/root/workspace/makedemo/header

my makefile is in the path:/root/workspace/makedemo

my makefile was like this:

Code:
HEADERS = $(shell /root/workspace/makedemo/header ls *.h)
SOURCES = $(shell /root/workspace/source ls *.cpp)

COMPILERFLAGS = -W -Wall
DEBUGFLAGS = -g
CPPCOMPILER = g++

INCLUDES = -I.


OBJS = $(SOURCES:.cpp=.o)

BINARY = output

all: $(BINARY)

$(BINARY): $(OBJS)
        $(CPPCOMPILER) $(COMPILERFLAGS) $(INCLUDES) -o $(BINARY) $(OBJS)
depend:
        makedepend -f- -- $(SOURCES) > .depend_file
clean:
        rm -rf *.o .depend_file $(BINARY) *~

#DO NOT DELETE
im sure that i've given the correct path but it is showing errors like this:

[root@localhost makedemo]# make
/bin/sh: /root/workspace/source: is a directory
/bin/sh: /root/workspace/source: is a directory
g++ -W -Wall -I. -o output
g++: no input files
make: *** [output] Error 1

any help appreciated...
It tries to run /root/workspace/source as a command (open shell, type name of any directory and see what happens). Either add cd, or use ls with full paths.
 
Old 03-13-2009, 06:44 AM   #3
karthik.c
LQ Newbie
 
Registered: Mar 2009
Distribution: linux-centos(Red Hat 3.4.6-10)
Posts: 7

Original Poster
Rep: Reputation: 0
hi erv thanks for your response,i did tried ls command after going to the particular directory and its giving me all .h and cpp files.but when i tried to print the value of SOURCES and HEADERS using echo it didnt print anything.im new to the concept of makefile and it would be better if u can say what is the correct way of giving the path of files then??

Last edited by karthik.c; 03-13-2009 at 06:51 AM.
 
Old 03-13-2009, 10:11 AM   #4
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
This should do the trick:
Code:
SOURCES  = $(shell ls /root/workspace/source/*.cpp)

DEBUG    = -g
CXXFLAGS = $(DEBUG) -Wall -ansi -pedantic
INCLUDES = -I/root/workspace/makedemo/header
LDFLAGS  =
LIBS     =
OBJS     = $(SOURCES:.cpp=.o)

BINARY = output

test:
        @echo $(OBJS)

all: $(BINARY)

$(BINARY): $(OBJS)
        $(CXX) $^ $(LDFLAGS) $(LIBS) -o $@

.cpp.o:
        $(CXX) $(CXXFLAGS) $(INCLUDES) -c $<

depend:
        makedepend -f- -- $(SOURCES) > .depend_file

clean:
        $(RM) $(OBJS) .depend_file $(BINARY)

# DO NOT DELETE
P.S. I am not familiar with 'makedepend'; is this a Solaris app?

On Linux, the dependencies can be built similar to the following:
Code:
        @$(CXX) -E -MM $(INCLUDES) $(SOURCES) > .depend_file

Last edited by dwhitney67; 03-13-2009 at 10:24 AM.
 
Old 03-14-2009, 12:20 AM   #5
karthik.c
LQ Newbie
 
Registered: Mar 2009
Distribution: linux-centos(Red Hat 3.4.6-10)
Posts: 7

Original Poster
Rep: Reputation: 0
>>P.S. I am not familiar with 'makedepend'; is this a Solaris app?

im not sure whether it is a solaris app,but it is a dependency tool in linux which creates dependencies using the source file.
you can check out man makedepend
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding path of library Ephracis Programming 6 01-08-2008 09:20 AM
From which path makefile is picked up when I say make <prog-name> piyush.kansal Programming 6 07-14-2007 01:24 PM
finding the PATH tahiche Linux - Software 7 10-12-2005 12:47 PM
Finding process path praj_linux Solaris / OpenSolaris 5 12-21-2004 10:01 AM
finding java path? pyropenguin Linux - Newbie 2 09-19-2002 01:02 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration