LinuxQuestions.org
Help answer threads with 0 replies.
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 07-08-2011, 11:53 AM   #1
ejohns85
LQ Newbie
 
Registered: Jul 2011
Posts: 2

Rep: Reputation: Disabled
Makefiles...


Hello,

I am new to the whole concept of makefiles, and I'm trying to compile and build my program using a makefile template I have found. My project consists of three directories: "source", where my .cpp files are (source1.cpp, source2.cpp, source3.cpp), "include", where my .h files are (header1.h, header2.h, header3.h), and "obj", where the object files are to be stored (obj1.o, obj2.o, obj3.o). In the project root directory is my makefile, which is as follows:

Code:
EXEC = myexe
CC = g++
IDIR = include
SDIR = source
ODIR = obj
LDIR= -L
LIBS= -l
CFLAGS = -I$(IDIR1) $(LDIR) $(LIBS)

_DEPS = header1.h header2.h header3.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))

_OBJ = obj1.h obj2.h obj3.h
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))

$(ODIR)/%.o: $(SDIR)/%.cpp $(DEPS)
	$(CC) -c -o $@ $< $(CFLAGS)

$(EXEC): $(OBJ)
	$(CC) -o $@ $^ $(CFLAGS) $(LDIR) $(LIBS)

clean:
	rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
However, when I try to "make" my program, I get the following error:

"make: *** No rule to make target `obj/obj1.o', needed by `myexe'. Stop."

But as far as I can see, this rule is present, in the line
Code:
$(ODIR)/%.o: $(SDIR)/%.cpp $(DEPS)
	$(CC) -c -o $@ $< $(CFLAGS)
Have I made some errors in the makefile, or is it a different problem?

Thanks!
 
Old 07-09-2011, 05:42 AM   #2
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,979

Rep: Reputation: Disabled
Hello ejohns85, welcome to LQ,

your question is more related to the "Programming"-forum here at LQ, http://www.linuxquestions.org/questions/programming-9/
I'd recommend that you use the "Report"-button and ask a Moderator to move your thread to the Programming-forum.

You will find several members there who can help you with this question.

Markus
 
Old 07-09-2011, 06:18 AM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Writing a Makefile, etc. etc.

http://www.linuxquestions.org/questi...file-883925/#5
( post # 5.)

http://www.eng.hawaii.edu/Tutor/Make/
 
Old 07-10-2011, 08:05 AM   #4
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Your OBJ variable is a list of include files. This seems wrong. Maybe you are missing a substitution of .o for .h?
 
Old 07-11-2011, 06:50 AM   #5
JZL240I-U
Senior Member
 
Registered: Apr 2003
Location: Germany
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,629

Rep: Reputation: Disabled
Ooops. Posted in wrond thread, my apologies.
 
  


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
makefiles... DEF. Programming 2 04-20-2009 01:46 PM
makefiles wmoti Programming 5 09-21-2005 03:26 AM
Those makefiles... boku Programming 10 03-01-2005 08:19 AM
Makefiles and Me dpottinger Linux - Newbie 5 07-24-2004 11:14 PM
MAKEFILEs shinpadsmt Linux - Newbie 3 02-21-2004 02:52 AM

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

All times are GMT -5. The time now is 02:31 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