LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 12-02-2011, 05:04 AM   #1
shamjs
Member
 
Registered: Sep 2011
Posts: 92

Rep: Reputation: Disabled
No rule to make target 'Markup.cpp', needed by `Markup.o'. Stop.


Hi All,
im not having enough knowledge about makefile

although i have tried to create a makefile but im getting error while creation

Code:
No rule to make target `Markingitup.cpp', needed by `Markingitup.o'.  Stop.
here is my make file

Code:
all: MainExe

MainExe: Markingitup.o pgm1.o   pgm2.o  pgm3.o pgm4.o pgm5.o  pgm6.o pgm7.o pgm8.o
        g++ -g -fno-for-scope  -w -o MainExe  MainExe.cpp Markingitup.o pgm1.o   pgm2.o  pgm3.o pgm4.o pgm5.o  pgm6.o pgm7.o pgm8.o -lrt -Xlinker -zmuldefs 2>&1 | less -S                                                                                              
Markingitup.o: Markingitup.cpp
        g++ -g -fPIC -c Markingitup.cpp

pgm1.o: pgm1.cpp
        g++ -g -fPIC -c pgm1.cpp

pgm2.o: pgm2.cpp
        g++ -g -fPIC -c pgm2.cpp

pgm3.o: pgm3.cpp
        g++ -g -fPIC -c pgm3.cpp

pgm4.o: pgm4.cpp
        g++ -g -fPIC -c pgm4.cpp

pgm5.o: pgm5.cpp
        g++ -g -fPIC -c pgm5.cpp

pgm6.o: pgm6.cpp
        g++ -g -fPIC -c pgm6.cpp

pgm7.o: pgm7.cpp
        g++ -g -fPIC -c pgm7.cpp

pgm8.o: pgm8.cpp
        g++ -g -fPIC -c pgm8.cpp

clean:
        rm -rf *o MainExe
Markingitup.cpp and all other .cpp file's are in different location from executable file MainExe

exe is in /home/shamjs/source
.cpp are in /home/shamjs/source/Main/src

i also tried by giving Markingitup.o: /Main/src/Markingitup.cpp
but no use........
i think becuase of the path problem im getting this error

plz guide me what should be done

waiting for your reply...............

Last edited by shamjs; 12-21-2011 at 10:15 AM.
 
Old 12-02-2011, 05:57 AM   #2
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.
Try using VPATH. Implicit rules (pattern rules) are also useful.
Example:
Code:
VPATH  = src
olupxtest: olupxtest.cpp  Markup.o olupx.o
	g++ -g -fno-for-scope -w -o $@ $^

%.o: %.cpp
	g++ -g -fPIC -c $<

clean:
	rm -f *.o olupxtest
Read `info make' for details.

Last edited by firstfire; 12-02-2011 at 05:59 AM.
 
Old 12-02-2011, 06:47 AM   #3
shamjs
Member
 
Registered: Sep 2011
Posts: 92

Original Poster
Rep: Reputation: Disabled
please let me know the meaning of $@ $^ and $< in line

g++ -g -fno-for-scope -w -o $@ $^

g++ -g -fPIC -c $<

respectively
 
Old 12-02-2011, 06:52 AM   #4
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.
Run `info make quick'
Quote:
Here is a summary of the automatic variables. *Note Automatic
Variables::, for full information.

`$@'
The file name of the target.

`$%'
The target member name, when the target is an archive member.

`$<'
The name of the first prerequisite.

`$?'
The names of all the prerequisites that are newer than the target,
with spaces between them. For prerequisites which are archive
members, only the member named is used (*note Archives:.

`$^'
`$+'
The names of all the prerequisites, with spaces between them. For
prerequisites which are archive members, only the member named is
used (*note Archives:. The value of `$^' omits duplicate
prerequisites, while `$+' retains them and preserves their order.
 
Old 12-02-2011, 07:02 AM   #5
shamjs
Member
 
Registered: Sep 2011
Posts: 92

Original Poster
Rep: Reputation: Disabled
Hi firstfire thanx for your replies ..............

please let me know whether this makefile is proper or not
Code:
VPATH  = src

MainExe: Markingitup.o pgm1.o   pgm2.o  pgm3.o pgm4.o pgm5.o  pgm6.o pgm7.o pgm8.o
        g++ -g -fno-for-scope  -w -o MainExe  MainExe.cpp Markingitup.o pgm1.o   pgm2.o  pgm3.o pgm4.o pgm5.o  pgm6.o pgm7.o pgm8.o -lrt -Xlinker -zmuldefs 2>&1 | less -S                         
       
%.o: %.cpp
        g++ -g -fPIC -c $<

clean:
        rm -f *.o MainExe

Last edited by shamjs; 12-21-2011 at 10:18 AM.
 
Old 12-02-2011, 07:07 AM   #6
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,539

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Something like this would also work:
Code:
APP      = olupxtest

SRCS     = $(wildcard *.cpp)
OBJS     = $(SRCS:.cpp=.o)

CXXFLAGS = -g -fPIC -c
LDFLAGS  =
LIBS     =

.PHONY: all clean


all: $(APP)

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

clean:
        $(RM) $(OBJS) $(APP)
There's no need to explicitly define the rule to make object files if things are kept simple (that is, object files will be created within the same directory as the source file). Just make sure that CXXFLAGS (or CFLAGS for C projects) is defined.

Also, avoid using hard-coded commands (e.g. g++, rm, etc). Try to use the built-in ones the Makefile already knows.
 
Old 12-02-2011, 07:25 AM   #7
shamjs
Member
 
Registered: Sep 2011
Posts: 92

Original Poster
Rep: Reputation: Disabled
i dont have any prior knowledge about makefile

but i need to link with object files right????

im getting undefined references when i executed the makefile that you have suggested and moreover my

executable i.e(MainExe) is in /home/shamjs/source
.cpp filles are in /home/shamjs/source/Main/src
as i have posted in earlier post

what should be done

Last edited by shamjs; 12-21-2011 at 10:19 AM.
 
Old 12-02-2011, 07:33 AM   #8
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,539

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by shamjs View Post
...
im getting undefined references when i executed the makefile that you have suggested and moreover my

executable i.e(olupxtest) is in /home/shamjs/source
.cpp filles are in /home/shamjs/source/olupx/src
as i have posted in earlier post

what should be done
Whoops! Add the following changes to the Makefile:
Code:
...
SRCDIR   = olupx/src
SRCS     = $(wildcard $(SRCDIR)/*.cpp)
...
or try something like:
Code:
SRCS     = $(shell find . -name '*.cpp')

Last edited by dwhitney67; 12-02-2011 at 07:35 AM.
 
Old 12-02-2011, 07:48 AM   #9
shamjs
Member
 
Registered: Sep 2011
Posts: 92

Original Poster
Rep: Reputation: Disabled
g++ -o MainExe
g++: no input files
make: *** [MainExe] Error 1

im getting above errors whether i have to replace src with /home/shamjs/Main/src
(i have included those changes)

Last edited by shamjs; 12-21-2011 at 10:20 AM.
 
Old 12-02-2011, 09:31 AM   #10
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,539

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by shamjs View Post
g++ -o olupxtest
g++: no input files
make: *** [olupxtest] Error 1

im getting above errors whether i have to replace src with /home/shamjs/olupx/src
(i have included those changes)
You indicated earlier that your "exe" is in /home/shamjs/source. Based on the Makefile you presented earlier, this would imply that the Makefile is also within this directory. You also stated that your source code is located within olupx/src, which is a series of sub-directories also within /home/shamjs/source.

The Makefile I suggested that you try out should be placed in /home/shamjs/source. If you want to place it elsewhere, then make (no pun) the appropriate changes to the Makefile.
 
Old 12-06-2011, 03:48 AM   #11
shamjs
Member
 
Registered: Sep 2011
Posts: 92

Original Poster
Rep: Reputation: Disabled
Hi dwhitney67,

1>i need to compile and link one more file pgm7.cpp ,but its in different directory
its location is /home/shamjs/file1/inc/ts/libry

how to adapt these changes in the makefile that you have given.......

2>And whether i have to give
LIBS = -lrt -Xlinker -zmuldefs
in order to link with library files in order to execute my program corectly.....


please guide me ....

waiting for your reply..........

Last edited by shamjs; 12-21-2011 at 10:22 AM.
 
Old 12-10-2011, 11:51 AM   #12
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,539

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by shamjs View Post
waiting for your reply..........
Sorry for the late reply; did you ever get the Makefile to work? Btw, it would be helpful to know how you have organized your header files too. Are they scattered around within the various source-code directories, or are they collected together within one directory?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Error in Makefile:No rule to make target `g++',needed by... stop karthik.c Programming 5 03-09-2009 01:55 AM
Help needed for make file problem : make: *** No rule to make target `flash', needed rameshsatyavaram Linux - Newbie 3 09-11-2008 03:13 AM
Belkin Wirless G RTL8185L make[1]: *** No rule to make target `Makefile'. Stop. SilverRock Linux - Wireless Networking 2 02-11-2007 08:25 AM
No rule to make target `/mkspecs/default/qmake.conf', needed by `Makefile'. Stop Julianus Linux - General 0 12-21-2003 08:17 AM

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

All times are GMT -5. The time now is 12:19 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration