View topic - Makefile Dependancies

Makefile Dependancies

anything that doesn't fit to other groups.

Makefile Dependancies

Postby cciarleg » Fri Apr 15, 2011 2:51 pm

Hi,

So I'm having a silly issue-when I run my makefile I am getting "no rule to make target buildfiles/bin/serial.o as needed by /buildfiles/bin/abv' (may have wording a little off) but the usual problem that the file seems no to be able to find my serial.cpp.

Makefile is fairly simple:

SRC_DIR = exospheres/src
INC_DIR = exospheres/include
BIN_OBJ_DIR = buildfiles/bin

CXX = qcc -V

CPPFLAGS += -Wno-deprecated
CXXFLAGS += -Wno-deprecated

INCLUDES += -I$(INC_DIR) \
-I.

SENSORS = $(SRC_DIR)/serial.cpp

SOURCES_cpp = $(SENSORS) \
$(SRC_DIR)/main.cpp

OBJECTS_COMMON = $(SENSORS:$(SRC_DIR)/%.cpp=$(BIN_OBJ_DIR)/%.o)

$(BIN_OBJ_DIR)/abv: $(OBJECTS_COMMON) \
$(BIN_OBJ_DIR)/main.o \
$(CXX) -o $@ $(CXXFLAGS) $^


I guess it has to do with the OBJECTS_COMMON line?

Thanks in advance.

Connie C.
cciarleg
Active Member
 
Posts: 23
Joined: Sat Jan 29, 2011 1:15 am

Postby Tim » Fri Apr 15, 2011 3:25 pm

Connie,

I'm no expert on Make but I don't see where you tell Make that you want to compile your .cpp files.

You define a SOURCES_cpp but you never use it.

So the $@ on your compilation line:

$(CXX) -o $@ $(CXXFLAGS) $^

has no way to equate that your .o's depend on your .cpp files.

Tim
Tim
Senior Member
 
Posts: 1419
Joined: Wed Mar 10, 2004 12:28 am

Postby cciarleg » Fri Apr 15, 2011 8:50 pm

okay-thanks. I think I got the dependencies with

SRC_DIR = exospheres/src
INC_DIR = exospheres/include
BIN_OBJ_DIR = buildfiles/bin

CXX = qcc -Vgcc_ntox86_cpp

CPPFLAGS += -Wno-deprecated
CXXFLAGS += -Wno-deprecated

INCLUDES += -I$(INC_DIR) \
-I.

SENSORS = $(SRC_DIR)/serial.cpp

SOURCES_cpp = $(SENSORS) \
$(SRC_DIR)/main.cpp

OBJECTS_COMMON = $(SENSORS:$(SRC_DIR)/%.cpp=$(BIN_OBJ_DIR)/%.o)

$(BIN_OBJ_DIR)/abv: $(OBJECTS_COMMON) \
$(BIN_OBJ_DIR)/main.o
$(CXX) -o $@ $(CXXFLAGS) $^


$(BIN_OBJ_DIR)/serial.o: $(SRC_DIR)/serial.cpp $(INC_DIR)/serial.h

$(BIN_OBJ_DIR)/main.o: $(SRC_DIR)/main.cpp $(INC_DIR)/serial.h

Now Im getting a no such file or directory for serial.o though it looks like to me the path is there.
cciarleg
Active Member
 
Posts: 23
Joined: Sat Jan 29, 2011 1:15 am

Postby cciarleg » Fri Apr 15, 2011 9:32 pm

Sweet! Got everything working! Thanks for the help!

SRC_DIR = exospheres/src
INC_DIR = exospheres/include
BIN_OBJ_DIR = buildfiles/bin

CXX = qcc -Vgcc_ntox86_cpp

CPPFLAGS += -Wno-deprecated
CXXFLAGS += -Wno-deprecated

INCLUDES += -I$(INC_DIR) \
-I.

SENSORS = $(SRC_DIR)/serial.cpp

SOURCES_cpp = $(SENSORS) \
$(SRC_DIR)/main.cpp

OBJECTS_COMMON = $(SOURCES_cpp:$(SRC_DIR)/%.cpp=$(BIN_OBJ_DIR)/%.o)

$(BIN_OBJ_DIR)/abv: $(SRC_DIR)/serial.o \
$(SRC_DIR)/main.o
$(CXX) -o $@ $(CXXFLAGS) $^

$(BIN_OBJ_DIR)/serial.o: $(SRC_DIR)/serial.cpp $(INC_DIR)/serial.h

$(BIN_OBJ_DIR)/main.o: $(SRC_DIR)/main.cpp $(INC_DIR)/serial.h
cciarleg
Active Member
 
Posts: 23
Joined: Sat Jan 29, 2011 1:15 am

Postby cciarleg » Sun Apr 17, 2011 1:44 am

okay-still having issues with this. I need to compile now with a file containing an extern variable, defined in its corresponding .cpp file.

I've also tried to clean up the makefile but I am still getting that "buildfiles/bin/serial.o file does not exist error"

SRC_DIR = exospheres/src
INC_DIR = exospheres/include
BIN_OBJ_DIR = buildfiles/bin

CXX = QCC

CPPFLAGS += -Wno-deprecated
CXXFLAGS += -Wno-deprecated

INCLUDES += -I$(INC_DIR) \
-I.

SENSORS = $(SRC_DIR)/serial.cpp

CONTROL = $(SRC_DIR)/ABVCtrl.cpp \
$(SRC_DIR)/ABVstate.cpp \
$(SRC_DIR)/ABV.cpp \
$(SRC_DIR)/global.cpp \
$(SRC_DIR)/ABVControl.cpp

SOURCES_cpp = $(SENSORS) \
$(CONTROL) \
$(SRC_DIR)/main.cpp

OBJECTS_CONTROL = $(SOURCES_cpp:$(SRC_DIR)/%.cpp=$(BIN_OBJ_DIR)/%.o)

$(BIN_OBJ_DIR)/abv: $(OBJECTS_CONTROL)
$(CXX) -o $@ $(CXXFLAGS) $^

$(OBJECTS_CONTROL): $(INC_DIR)

.PHONY : clean
clean :
-rm $(BIN_OBJ_DIR)/abv $(OBJECTS_CONTROL)

I have my .h file dependencies in there. To my understanding, the compiler should automatically associate the .cpp file with the same name. And My syntax for creation of the ,o files seems to be correct from examples I've looked at. What syntax am I missing?
cciarleg
Active Member
 
Posts: 23
Joined: Sat Jan 29, 2011 1:15 am

Postby Tim » Mon Apr 18, 2011 5:25 pm

Connie,

I'm not sure what's wrong now or what you are trying to fix.

Is the Makefile compiling your executable or not?
Is it the dependencies that aren't working?
Is it just the error message you are trying to fix?

Hard to know where you are with this.

Tim
Tim
Senior Member
 
Posts: 1419
Joined: Wed Mar 10, 2004 12:28 am

Postby cciarleg » Sat Apr 23, 2011 8:17 pm

Hi Tim,

Sorry-the development process is going so fast with this I can be very unclear.

My current issue is that:

1. My makefile builds the .o files in the correct directory
2. My makefile also builds .s files in the directory containing the makefile-I assume this is not supposed to happen

At this point the makefile fails and gives the error

serial.o: file format not recognized.

The main executable never gets built completely-which is what I want.

Makefile looks like:
SRC_DIR = exospheres/src
INC_DIR = exospheres/include
BIN_OBJ_DIR = buildfiles/bin

$(BIN_OBJ_DIR)/abv: $(BIN_OBJ_DIR)/serial.o $(BIN_OBJ_DIR)/ABVstate.o $(BIN_OBJ_DIR)/ABV.o $(BIN_OBJ_DIR)/global.o \
$(BIN_OBJ_DIR)/ABVCtrl.o $(BIN_OBJ_DIR)/ABVControl.o $(BIN_OBJ_DIR)/actuator.o $(BIN_OBJ_DIR)/thruster.o $(BIN_OBJ_DIR)/main.o
$(CXX) -o $@ $(CXXFLAGS) $^

$(BIN_OBJ_DIR)/serial.o: $(SRC_DIR)/serial.cpp $(INC_DIR)/serial.h
QCC -o $@ $(CXXFLAGS) $^

$(BIN_OBJ_DIR)/ABVstate.o: $(SRC_DIR)/ABVstate.cpp $(INC_DIR)/ABVstate.h
QCC -o $@ $(CXXFLAGS) $^

$(BIN_OBJ_DIR)/ABV.o: $(SRC_DIR)/ABV.cpp $(INC_DIR)/ABV.h $(INC_DIR)/serial.h $(INC_DIR)/ABVstate.h $(INC_DIR)/actuator.h
QCC -o $@ $(CXXFLAGS) $^

$(BIN_OBJ_DIR)/global.o: $(INC_DIR)/ABV.h $(INC_DIR)/ABVstate.h $(SRC_DIR)/global.cpp $(INC_DIR)/global.h
QCC -o $@ $(CXXFLAGS) $^

$(BIN_OBJ_DIR)/ABVCtrl.o: $(INC_DIR)/ABV.h $(INC_DIR)/ABVstate.h $(INC_DIR)/global.h $(INC_DIR)/ABVControl.h $(INC_DIR)/ABVCtrl.h $(SRC_DIR)/ABVCtrl.cpp
QCC -o $@ $(CXXFLAGS) $^

$(BIN_OBJ_DIR)/ABVControl.o: $(SRC_DIR)/ABVControl.cpp $(INC_DIR)/ABVControl.h $(INC_DIR)/ABV.h $(INC_DIR)/ABVstate.h $(INC_DIR)/global.h $(INC_DIR)/ABVstate.h
QCC -o $@ $(CXXFLAGS) $^

$(BIN_OBJ_DIR)/actuator.o: $(SRC_DIR)/actuator.cpp $(INC_DIR)/actuator.h $(INC_DIR)/ABVControl.h $(INC_DIR)/global.h $(INC_DIR)/serial.h $(INC_DIR)/ABV.h $(INC_DIR)/ABVstate.h
QCC -o $@ $(CXXFLAGS) $^

$(BIN_OBJ_DIR)/thruster.o: $(SRC_DIR)/thruster.cpp $(INC_DIR)/thruster.h $(INC_DIR)/global.h $(INC_DIR)/serial.h $(INC_DIR)/ABV.h $(INC_DIR)/ABVstate.h
QCC -o $@ $(CXXFLAGS) $^

$(BIN_OBJ_DIR)/main.o: $(SRC_DIR)/main.cpp $(INC_DIR)/serial.h $(INC_DIR)/global.h $(INC_DIR)/ABVCtrl.h $(INC_DIR)/ABV.h $(INC_DIR)/ABVstate.h
QCC -o $@ $(CXXFLAGS) $^
cciarleg
Active Member
 
Posts: 23
Joined: Sat Jan 29, 2011 1:15 am

Postby Tim » Mon Apr 25, 2011 5:28 pm

Connie,

This line is your problem (obviously)

$(BIN_OBJ_DIR)/abv: $(BIN_OBJ_DIR)/serial.o $(BIN_OBJ_DIR)/ABVstate.o $(BIN_OBJ_DIR)/ABV.o $(BIN_OBJ_DIR)/global.o \
$(BIN_OBJ_DIR)/ABVCtrl.o $(BIN_OBJ_DIR)/ABVControl.o $(BIN_OBJ_DIR)/actuator.o $(BIN_OBJ_DIR)/thruster.o $(BIN_OBJ_DIR)/main.o
$(CXX) -o $@ $(CXXFLAGS) $^

As a non-make expert it doesn't jump right out at me what's wrong. I'd say it's the compilation line and how the $@ and $^ are getting interpreted (one or the other of those symbols is wrong or not needed).

Here's a very simply Makefile which works. It will give you an idea of what yours should look like:

Code: Select all
OBJECTS = passivesock.o passiveTCP.o connectTCP.o  connectsock.o

CC = qcc -V3.3.5,gcc_ntox86_cpp
CXX = qcc -V3.3.5,gcc_ntox86_cpp
LD = qcc -V3.3.5,gcc_ntox86_cpp


all: $(OBJECTS) TCPdaytimed $(LINK)


TCPdaytimed: TCPdaytimed.c $(OBJECTS)
   $(CC) -c TCPdaytimed.c $(OBJECTS)

LINK: TCPdaytimed.o $(OBJECTS)
   $(CC) -o TCPDaytimed TCPdaytimed.o $(OBJECTS) -lsocket

clean:
   rm -fv *.o $(PROJLIB) TCPdaytimed


It's the LINK directive that you are having problems with in your Makefile. Somehow that line of $(CXX) -o $@ $(CXXFLAGS) $^ isn't evaluating correctly (it appears to be trying to compile Serial.o). I'd try simplifying your line to what's in the LINK directive and see if that solves the problem.

Incidentally I have no idea what .s files are.

Tim

P.S. This is not how I do my makefiles but should be enough to get you working.
Tim
Senior Member
 
Posts: 1419
Joined: Wed Mar 10, 2004 12:28 am


Return to General Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron