Compiling and linking subfolders using different Makefiles












1















I have a client/server application in C. The server has its own folder dserver, the same for the client dclient. Using both of them some files containing utility functions, I created another directory at the same level of the previously ones, named common.



My idea is to create each Makefile in each subfolder (one in dserver, one in dclient and another in common) and then one Makefile in the main directory which will run the other Makefiles which looks like:



all:
+$(MAKE) -C common
+$(MAKE) -C dserver
+$(MAKE) -C dclient


The first problem is that the common/Makefile should not create an executable but only create the object files that will be needed to create the executable for the client and for the server. In my case it is:



CXX = gcc

SOURCEDIR := ./
SOURCES := $(wildcard $(SOURCEDIR)/*.c)
OBJDIR=$(SOURCEDIR)/obj

OBJECTS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.o, $(SOURCES))
DEPENDS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.d, $(SOURCES))

# ADD MORE WARNINGS!
WARNING := -Wall -Wextra

$(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
$(CXX) $(WARNING) -MMD -MP -c $< -o $@

$(OBJDIR):
mkdir -p $(OBJDIR)


My problem is that it is creating the object directory specified by OBJDIR but not the object files *.o: how should it be?



Secondly in the client and server Makefiles I should both include path to the files in common and then referencing the object files in the resulting from the compilation of common to build the executables. So taking for example the dserver/Makefile I added the line INC_PATH = -I../common/ and referencing it in the compilation as $(CXX) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@. However in the code I had to do #include "../common/utilities.h".



Is there a way to include the path in the Makefile so that in the code it allows to do just: #include "utilities.h"?



And also, supposing that common has its own object directory containing the object files needed both by the client and server, how build, for example the server executable referencing the object files both in the common directory and the ones specific and contained in the server directory?



The dserver/Makefile is something like (and the dclient/Makefile has the same structure):



CXX = gcc

INC_PATH = -I../common/

SOURCEDIR := ./
SOURCES := $(wildcard $(SOURCEDIR)/*.c)
OBJDIR=./obj

OBJECTS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.o, $(SOURCES))
DEPENDS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.d, $(SOURCES))

# ADD MORE WARNINGS!
WARNING := -Wall -Wextra

# .PHONY means these rules get executed even if
# files of those names exist.
.PHONY: all clean

# The first rule is the default, ie. "make",
# "make all" and "make parking" mean the same
all: server

clean:
$(RM) $(OBJECTS) $(DEPENDS) server

# Linking the executable from the object files
# $^ # "src.c src.h" (all prerequisites)
../server: $(OBJECTS)
$(CXX) $(WARNING) $(INC_PATH) $^ -o $@
#$(CXX) $(WARNING) $(CXXFLAGS) $(INC_PATH) $^ -o $@ $(LIBS)

-include $(DEPENDS)

$(OBJDIR):
mkdir -p $(OBJDIR)

$(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
$(CXX) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@









share|improve this question

























  • An example non-recursive make for you: stackoverflow.com/a/7321954/412080

    – Maxim Egorushkin
    Jan 2 at 16:17
















1















I have a client/server application in C. The server has its own folder dserver, the same for the client dclient. Using both of them some files containing utility functions, I created another directory at the same level of the previously ones, named common.



My idea is to create each Makefile in each subfolder (one in dserver, one in dclient and another in common) and then one Makefile in the main directory which will run the other Makefiles which looks like:



all:
+$(MAKE) -C common
+$(MAKE) -C dserver
+$(MAKE) -C dclient


The first problem is that the common/Makefile should not create an executable but only create the object files that will be needed to create the executable for the client and for the server. In my case it is:



CXX = gcc

SOURCEDIR := ./
SOURCES := $(wildcard $(SOURCEDIR)/*.c)
OBJDIR=$(SOURCEDIR)/obj

OBJECTS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.o, $(SOURCES))
DEPENDS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.d, $(SOURCES))

# ADD MORE WARNINGS!
WARNING := -Wall -Wextra

$(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
$(CXX) $(WARNING) -MMD -MP -c $< -o $@

$(OBJDIR):
mkdir -p $(OBJDIR)


My problem is that it is creating the object directory specified by OBJDIR but not the object files *.o: how should it be?



Secondly in the client and server Makefiles I should both include path to the files in common and then referencing the object files in the resulting from the compilation of common to build the executables. So taking for example the dserver/Makefile I added the line INC_PATH = -I../common/ and referencing it in the compilation as $(CXX) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@. However in the code I had to do #include "../common/utilities.h".



Is there a way to include the path in the Makefile so that in the code it allows to do just: #include "utilities.h"?



And also, supposing that common has its own object directory containing the object files needed both by the client and server, how build, for example the server executable referencing the object files both in the common directory and the ones specific and contained in the server directory?



The dserver/Makefile is something like (and the dclient/Makefile has the same structure):



CXX = gcc

INC_PATH = -I../common/

SOURCEDIR := ./
SOURCES := $(wildcard $(SOURCEDIR)/*.c)
OBJDIR=./obj

OBJECTS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.o, $(SOURCES))
DEPENDS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.d, $(SOURCES))

# ADD MORE WARNINGS!
WARNING := -Wall -Wextra

# .PHONY means these rules get executed even if
# files of those names exist.
.PHONY: all clean

# The first rule is the default, ie. "make",
# "make all" and "make parking" mean the same
all: server

clean:
$(RM) $(OBJECTS) $(DEPENDS) server

# Linking the executable from the object files
# $^ # "src.c src.h" (all prerequisites)
../server: $(OBJECTS)
$(CXX) $(WARNING) $(INC_PATH) $^ -o $@
#$(CXX) $(WARNING) $(CXXFLAGS) $(INC_PATH) $^ -o $@ $(LIBS)

-include $(DEPENDS)

$(OBJDIR):
mkdir -p $(OBJDIR)

$(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
$(CXX) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@









share|improve this question

























  • An example non-recursive make for you: stackoverflow.com/a/7321954/412080

    – Maxim Egorushkin
    Jan 2 at 16:17














1












1








1


1






I have a client/server application in C. The server has its own folder dserver, the same for the client dclient. Using both of them some files containing utility functions, I created another directory at the same level of the previously ones, named common.



My idea is to create each Makefile in each subfolder (one in dserver, one in dclient and another in common) and then one Makefile in the main directory which will run the other Makefiles which looks like:



all:
+$(MAKE) -C common
+$(MAKE) -C dserver
+$(MAKE) -C dclient


The first problem is that the common/Makefile should not create an executable but only create the object files that will be needed to create the executable for the client and for the server. In my case it is:



CXX = gcc

SOURCEDIR := ./
SOURCES := $(wildcard $(SOURCEDIR)/*.c)
OBJDIR=$(SOURCEDIR)/obj

OBJECTS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.o, $(SOURCES))
DEPENDS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.d, $(SOURCES))

# ADD MORE WARNINGS!
WARNING := -Wall -Wextra

$(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
$(CXX) $(WARNING) -MMD -MP -c $< -o $@

$(OBJDIR):
mkdir -p $(OBJDIR)


My problem is that it is creating the object directory specified by OBJDIR but not the object files *.o: how should it be?



Secondly in the client and server Makefiles I should both include path to the files in common and then referencing the object files in the resulting from the compilation of common to build the executables. So taking for example the dserver/Makefile I added the line INC_PATH = -I../common/ and referencing it in the compilation as $(CXX) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@. However in the code I had to do #include "../common/utilities.h".



Is there a way to include the path in the Makefile so that in the code it allows to do just: #include "utilities.h"?



And also, supposing that common has its own object directory containing the object files needed both by the client and server, how build, for example the server executable referencing the object files both in the common directory and the ones specific and contained in the server directory?



The dserver/Makefile is something like (and the dclient/Makefile has the same structure):



CXX = gcc

INC_PATH = -I../common/

SOURCEDIR := ./
SOURCES := $(wildcard $(SOURCEDIR)/*.c)
OBJDIR=./obj

OBJECTS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.o, $(SOURCES))
DEPENDS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.d, $(SOURCES))

# ADD MORE WARNINGS!
WARNING := -Wall -Wextra

# .PHONY means these rules get executed even if
# files of those names exist.
.PHONY: all clean

# The first rule is the default, ie. "make",
# "make all" and "make parking" mean the same
all: server

clean:
$(RM) $(OBJECTS) $(DEPENDS) server

# Linking the executable from the object files
# $^ # "src.c src.h" (all prerequisites)
../server: $(OBJECTS)
$(CXX) $(WARNING) $(INC_PATH) $^ -o $@
#$(CXX) $(WARNING) $(CXXFLAGS) $(INC_PATH) $^ -o $@ $(LIBS)

-include $(DEPENDS)

$(OBJDIR):
mkdir -p $(OBJDIR)

$(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
$(CXX) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@









share|improve this question
















I have a client/server application in C. The server has its own folder dserver, the same for the client dclient. Using both of them some files containing utility functions, I created another directory at the same level of the previously ones, named common.



My idea is to create each Makefile in each subfolder (one in dserver, one in dclient and another in common) and then one Makefile in the main directory which will run the other Makefiles which looks like:



all:
+$(MAKE) -C common
+$(MAKE) -C dserver
+$(MAKE) -C dclient


The first problem is that the common/Makefile should not create an executable but only create the object files that will be needed to create the executable for the client and for the server. In my case it is:



CXX = gcc

SOURCEDIR := ./
SOURCES := $(wildcard $(SOURCEDIR)/*.c)
OBJDIR=$(SOURCEDIR)/obj

OBJECTS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.o, $(SOURCES))
DEPENDS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.d, $(SOURCES))

# ADD MORE WARNINGS!
WARNING := -Wall -Wextra

$(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
$(CXX) $(WARNING) -MMD -MP -c $< -o $@

$(OBJDIR):
mkdir -p $(OBJDIR)


My problem is that it is creating the object directory specified by OBJDIR but not the object files *.o: how should it be?



Secondly in the client and server Makefiles I should both include path to the files in common and then referencing the object files in the resulting from the compilation of common to build the executables. So taking for example the dserver/Makefile I added the line INC_PATH = -I../common/ and referencing it in the compilation as $(CXX) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@. However in the code I had to do #include "../common/utilities.h".



Is there a way to include the path in the Makefile so that in the code it allows to do just: #include "utilities.h"?



And also, supposing that common has its own object directory containing the object files needed both by the client and server, how build, for example the server executable referencing the object files both in the common directory and the ones specific and contained in the server directory?



The dserver/Makefile is something like (and the dclient/Makefile has the same structure):



CXX = gcc

INC_PATH = -I../common/

SOURCEDIR := ./
SOURCES := $(wildcard $(SOURCEDIR)/*.c)
OBJDIR=./obj

OBJECTS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.o, $(SOURCES))
DEPENDS := $(patsubst $(SOURCEDIR)/%.c,$(OBJDIR)/%.d, $(SOURCES))

# ADD MORE WARNINGS!
WARNING := -Wall -Wextra

# .PHONY means these rules get executed even if
# files of those names exist.
.PHONY: all clean

# The first rule is the default, ie. "make",
# "make all" and "make parking" mean the same
all: server

clean:
$(RM) $(OBJECTS) $(DEPENDS) server

# Linking the executable from the object files
# $^ # "src.c src.h" (all prerequisites)
../server: $(OBJECTS)
$(CXX) $(WARNING) $(INC_PATH) $^ -o $@
#$(CXX) $(WARNING) $(CXXFLAGS) $(INC_PATH) $^ -o $@ $(LIBS)

-include $(DEPENDS)

$(OBJDIR):
mkdir -p $(OBJDIR)

$(OBJDIR)/%.o: $(SOURCEDIR)/%.c Makefile | $(OBJDIR)
$(CXX) $(WARNING) -MMD -MP -c $(INC_PATH) $< -o $@






c makefile compilation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 15:29







Francesco Boi

















asked Jan 2 at 15:18









Francesco BoiFrancesco Boi

2,74022643




2,74022643













  • An example non-recursive make for you: stackoverflow.com/a/7321954/412080

    – Maxim Egorushkin
    Jan 2 at 16:17



















  • An example non-recursive make for you: stackoverflow.com/a/7321954/412080

    – Maxim Egorushkin
    Jan 2 at 16:17

















An example non-recursive make for you: stackoverflow.com/a/7321954/412080

– Maxim Egorushkin
Jan 2 at 16:17





An example non-recursive make for you: stackoverflow.com/a/7321954/412080

– Maxim Egorushkin
Jan 2 at 16:17












1 Answer
1






active

oldest

votes


















0














You don't specify any rules for building the objects in your "common" Makefile - this is the only rule you have.



$(OBJDIR):
mkdir -p $(OBJDIR)


You want to put a rule before that to all get it to build the objects, maybe something along the lines of:



all: $(OBJDIR) $(OBJECTS)


It has to go before the original rule as if you don't specify what is being built, make will do the first rule it finds.



Including header files from "common" in your other directories should be working just fine by using -I../common/.



Using the objects from "common" should just be a case of adding them to the list of objects ie:



COMMON_OBJECTS=../common/obj/utilities.o

../server: $(OBJECTS) $(COMMON_OBJECTS)


Or having them built into a library so you don't need to know what object files there are.



Also it's worth noting that $(CXX) is the variable used to store the C++ compiler - for building with the C compiler you want to be using $(CC) and $(CFLAGS).






share|improve this answer
























  • all: $(OBJDIR) $(OBJECTS) breaks in parallel builds. The robust way is to have object files depend order-only on their directories. e.g. %.o : %.cc | $$(@D) (requires .SECONDEXPANSION).

    – Maxim Egorushkin
    Jan 2 at 16:15













  • ../server: $(OBJECTS) $(COMMON_OBJECTS) is not working: it seems it is not linking properly: the error is undefined reference to FunctionInCommonFile

    – Francesco Boi
    Jan 2 at 17:33











  • You are right about the rule in common/Makefile though

    – Francesco Boi
    Jan 2 at 17:33











  • @MaximEgorushkin That is already in the OP's Makefile

    – Chris Turner
    Jan 2 at 17:40











  • @FrancescoBoi that implies you've missed out one (or more) of the object files from common, or there is some code you've not yet written

    – Chris Turner
    Jan 2 at 17:42











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008827%2fcompiling-and-linking-subfolders-using-different-makefiles%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You don't specify any rules for building the objects in your "common" Makefile - this is the only rule you have.



$(OBJDIR):
mkdir -p $(OBJDIR)


You want to put a rule before that to all get it to build the objects, maybe something along the lines of:



all: $(OBJDIR) $(OBJECTS)


It has to go before the original rule as if you don't specify what is being built, make will do the first rule it finds.



Including header files from "common" in your other directories should be working just fine by using -I../common/.



Using the objects from "common" should just be a case of adding them to the list of objects ie:



COMMON_OBJECTS=../common/obj/utilities.o

../server: $(OBJECTS) $(COMMON_OBJECTS)


Or having them built into a library so you don't need to know what object files there are.



Also it's worth noting that $(CXX) is the variable used to store the C++ compiler - for building with the C compiler you want to be using $(CC) and $(CFLAGS).






share|improve this answer
























  • all: $(OBJDIR) $(OBJECTS) breaks in parallel builds. The robust way is to have object files depend order-only on their directories. e.g. %.o : %.cc | $$(@D) (requires .SECONDEXPANSION).

    – Maxim Egorushkin
    Jan 2 at 16:15













  • ../server: $(OBJECTS) $(COMMON_OBJECTS) is not working: it seems it is not linking properly: the error is undefined reference to FunctionInCommonFile

    – Francesco Boi
    Jan 2 at 17:33











  • You are right about the rule in common/Makefile though

    – Francesco Boi
    Jan 2 at 17:33











  • @MaximEgorushkin That is already in the OP's Makefile

    – Chris Turner
    Jan 2 at 17:40











  • @FrancescoBoi that implies you've missed out one (or more) of the object files from common, or there is some code you've not yet written

    – Chris Turner
    Jan 2 at 17:42
















0














You don't specify any rules for building the objects in your "common" Makefile - this is the only rule you have.



$(OBJDIR):
mkdir -p $(OBJDIR)


You want to put a rule before that to all get it to build the objects, maybe something along the lines of:



all: $(OBJDIR) $(OBJECTS)


It has to go before the original rule as if you don't specify what is being built, make will do the first rule it finds.



Including header files from "common" in your other directories should be working just fine by using -I../common/.



Using the objects from "common" should just be a case of adding them to the list of objects ie:



COMMON_OBJECTS=../common/obj/utilities.o

../server: $(OBJECTS) $(COMMON_OBJECTS)


Or having them built into a library so you don't need to know what object files there are.



Also it's worth noting that $(CXX) is the variable used to store the C++ compiler - for building with the C compiler you want to be using $(CC) and $(CFLAGS).






share|improve this answer
























  • all: $(OBJDIR) $(OBJECTS) breaks in parallel builds. The robust way is to have object files depend order-only on their directories. e.g. %.o : %.cc | $$(@D) (requires .SECONDEXPANSION).

    – Maxim Egorushkin
    Jan 2 at 16:15













  • ../server: $(OBJECTS) $(COMMON_OBJECTS) is not working: it seems it is not linking properly: the error is undefined reference to FunctionInCommonFile

    – Francesco Boi
    Jan 2 at 17:33











  • You are right about the rule in common/Makefile though

    – Francesco Boi
    Jan 2 at 17:33











  • @MaximEgorushkin That is already in the OP's Makefile

    – Chris Turner
    Jan 2 at 17:40











  • @FrancescoBoi that implies you've missed out one (or more) of the object files from common, or there is some code you've not yet written

    – Chris Turner
    Jan 2 at 17:42














0












0








0







You don't specify any rules for building the objects in your "common" Makefile - this is the only rule you have.



$(OBJDIR):
mkdir -p $(OBJDIR)


You want to put a rule before that to all get it to build the objects, maybe something along the lines of:



all: $(OBJDIR) $(OBJECTS)


It has to go before the original rule as if you don't specify what is being built, make will do the first rule it finds.



Including header files from "common" in your other directories should be working just fine by using -I../common/.



Using the objects from "common" should just be a case of adding them to the list of objects ie:



COMMON_OBJECTS=../common/obj/utilities.o

../server: $(OBJECTS) $(COMMON_OBJECTS)


Or having them built into a library so you don't need to know what object files there are.



Also it's worth noting that $(CXX) is the variable used to store the C++ compiler - for building with the C compiler you want to be using $(CC) and $(CFLAGS).






share|improve this answer













You don't specify any rules for building the objects in your "common" Makefile - this is the only rule you have.



$(OBJDIR):
mkdir -p $(OBJDIR)


You want to put a rule before that to all get it to build the objects, maybe something along the lines of:



all: $(OBJDIR) $(OBJECTS)


It has to go before the original rule as if you don't specify what is being built, make will do the first rule it finds.



Including header files from "common" in your other directories should be working just fine by using -I../common/.



Using the objects from "common" should just be a case of adding them to the list of objects ie:



COMMON_OBJECTS=../common/obj/utilities.o

../server: $(OBJECTS) $(COMMON_OBJECTS)


Or having them built into a library so you don't need to know what object files there are.



Also it's worth noting that $(CXX) is the variable used to store the C++ compiler - for building with the C compiler you want to be using $(CC) and $(CFLAGS).







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 2 at 15:49









Chris TurnerChris Turner

7,31211118




7,31211118













  • all: $(OBJDIR) $(OBJECTS) breaks in parallel builds. The robust way is to have object files depend order-only on their directories. e.g. %.o : %.cc | $$(@D) (requires .SECONDEXPANSION).

    – Maxim Egorushkin
    Jan 2 at 16:15













  • ../server: $(OBJECTS) $(COMMON_OBJECTS) is not working: it seems it is not linking properly: the error is undefined reference to FunctionInCommonFile

    – Francesco Boi
    Jan 2 at 17:33











  • You are right about the rule in common/Makefile though

    – Francesco Boi
    Jan 2 at 17:33











  • @MaximEgorushkin That is already in the OP's Makefile

    – Chris Turner
    Jan 2 at 17:40











  • @FrancescoBoi that implies you've missed out one (or more) of the object files from common, or there is some code you've not yet written

    – Chris Turner
    Jan 2 at 17:42



















  • all: $(OBJDIR) $(OBJECTS) breaks in parallel builds. The robust way is to have object files depend order-only on their directories. e.g. %.o : %.cc | $$(@D) (requires .SECONDEXPANSION).

    – Maxim Egorushkin
    Jan 2 at 16:15













  • ../server: $(OBJECTS) $(COMMON_OBJECTS) is not working: it seems it is not linking properly: the error is undefined reference to FunctionInCommonFile

    – Francesco Boi
    Jan 2 at 17:33











  • You are right about the rule in common/Makefile though

    – Francesco Boi
    Jan 2 at 17:33











  • @MaximEgorushkin That is already in the OP's Makefile

    – Chris Turner
    Jan 2 at 17:40











  • @FrancescoBoi that implies you've missed out one (or more) of the object files from common, or there is some code you've not yet written

    – Chris Turner
    Jan 2 at 17:42

















all: $(OBJDIR) $(OBJECTS) breaks in parallel builds. The robust way is to have object files depend order-only on their directories. e.g. %.o : %.cc | $$(@D) (requires .SECONDEXPANSION).

– Maxim Egorushkin
Jan 2 at 16:15







all: $(OBJDIR) $(OBJECTS) breaks in parallel builds. The robust way is to have object files depend order-only on their directories. e.g. %.o : %.cc | $$(@D) (requires .SECONDEXPANSION).

– Maxim Egorushkin
Jan 2 at 16:15















../server: $(OBJECTS) $(COMMON_OBJECTS) is not working: it seems it is not linking properly: the error is undefined reference to FunctionInCommonFile

– Francesco Boi
Jan 2 at 17:33





../server: $(OBJECTS) $(COMMON_OBJECTS) is not working: it seems it is not linking properly: the error is undefined reference to FunctionInCommonFile

– Francesco Boi
Jan 2 at 17:33













You are right about the rule in common/Makefile though

– Francesco Boi
Jan 2 at 17:33





You are right about the rule in common/Makefile though

– Francesco Boi
Jan 2 at 17:33













@MaximEgorushkin That is already in the OP's Makefile

– Chris Turner
Jan 2 at 17:40





@MaximEgorushkin That is already in the OP's Makefile

– Chris Turner
Jan 2 at 17:40













@FrancescoBoi that implies you've missed out one (or more) of the object files from common, or there is some code you've not yet written

– Chris Turner
Jan 2 at 17:42





@FrancescoBoi that implies you've missed out one (or more) of the object files from common, or there is some code you've not yet written

– Chris Turner
Jan 2 at 17:42




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008827%2fcompiling-and-linking-subfolders-using-different-makefiles%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith