How to properly use -MD flag in Makefile





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm trying to create a Makefile where make only recompiles necessary .cpp files.



By default, it works well if I edit .cpp, however, when I edit .h files, it just ignores the changes.



So I've read of -MD flag and its friend -MP (used to avoid bugs when typing make).



However, I can't seem to make it working, if I use -MMD, it works perfectly but I rely on system includes too as I'm writing a library too that is evolving along with the project. Thus, if I update the libary header and reinstall the library, typing make in the main project should recompiles files that includes the changed header.



When using -MMD flag, it - as expected - does not recompile the project, however, using -MD flag, it does recompile everything. In fact, -MD recompiles everything every time, even when nothing changed.



Here is a minimal project structure that reproduce the issue:



./Makefile:



all: build

re: clean build

build: build_lib install_lib build_client

build_lib:
$(MAKE) -C lib
$(MAKE) install -C lib

build_client:
$(MAKE) -C client

install_lib:
$(MAKE) install -C lib


.PHONY: clean
clean: clean_lib clean_client

clean_lib:
$(MAKE) clean -C lib

clean_client:
$(MAKE) clean -C client


./client/Makefile:



CC = g++
INC = -I../lib
CXXFLAGS = -Wall $(INC) -g -MD -MP
EXEC_NAME = ../test

src = $(shell find $(SOURCEDIR) -name '*.cpp')
obj = $(src:.cpp=.o)

LIBRARIES = -ltest_lib
LDFLAGS = -rdynamic $(LIBRARIES)

all: $(EXEC_NAME)

re: clean $(EXEC_NAME)

$(EXEC_NAME): $(obj)
$(CC) -o $@ $^ $(LDFLAGS)
-include $(obj:.o=.d)

.PHONY: clean
clean:
rm -f $(obj) $(EXEC_NAME)


./lib/Makefile:



.PHONY : clean

CXXFLAGS= -fPIC -g -Itest_lib/include -MMD -MP
LDFLAGS= -shared

SOURCES = $(shell find $(SOURCEDIR) -name '*.cpp')
HEADERS = $(shell find $(SOURCEDIR) -name '*.h')
OBJECTS=$(SOURCES:.cpp=.o)

TARGET=libtest_lib.so
INC_FOLDER=test_lib/include
CUR_DIR = $(shell pwd)

all: $(TARGET)

install:
sudo rm -rf /usr/local/lib/libtest_lib.so && sudo ln -s $(CUR_DIR)/$(TARGET) /usr/local/lib/libtest_lib.so
sudo rm -rf /usr/local/include/test_lib && sudo cp -r $(INC_FOLDER) /usr/local/include/test_lib

clean:
rm -f $(OBJECTS) $(TARGET)

$(TARGET) : $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) -o $@ $(LDFLAGS)
-include $(OBJECTS:.o=.d)


./client/main.cpp:



#include "bar.h"

int main()
{
Bar b;

b.sayHello();
b.sayBye();

return 0;
}


./client/bar.h



#ifndef __BAR__
#define __BAR__

#include <test_lib/foo.h>
#include <iostream>

struct Bar : public Foo
{
Bar() {};
~Bar() {};

void sayBye() const {
std::cout << "Bye " << name << "..." << std::endl;
};
};

#endif


./lib/test_lib/include/foo.h



#ifndef __FOO__
#define __FOO__

struct Foo
{
const char *name;

Foo(const char *name = "world");
~Foo();

void sayHello() const;
};

#endif


./lib/test_lib/src



#include "foo.h"
#include <iostream>

Foo::Foo(const char *name) : name(name) {}
Foo::~Foo() {}

void Foo::sayHello() const
{
std::cout << "Hello " << name << " !" << std::endl;
}









share|improve this question




















  • 1





    Please post a Minimal, Complete, and Verifiable example that still shows the issue, you need to show an example of your include directives and folder structure.

    – user657267
    Nov 24 '18 at 6:44











  • We can't help given this info. I think you can debug this yourself. First, find the .d files that are generated and look at them. Are they in the right place? That is for every srcdir/foo.c is there a srcdir/foo.d file? Do the contents seem sane? Are the target names correct for the .o files? Are the prerequisite paths correct? If that seems fine, then run make -d (redirect the voluminous output to a file). Locate the process make goes through to decide to rebuild a sample .o. It will tell you exactly what files were out of date. Is it right?

    – MadScientist
    Nov 24 '18 at 14:43











  • @MadScientist make -d indeed helped here. and I understand what's going on here, see my edit, I'm actually reinstalling the library everytime so it thinks the file has changed based on its date. I think I can figure out a better way to update the library

    – Masadow
    Nov 26 '18 at 11:36


















0















I'm trying to create a Makefile where make only recompiles necessary .cpp files.



By default, it works well if I edit .cpp, however, when I edit .h files, it just ignores the changes.



So I've read of -MD flag and its friend -MP (used to avoid bugs when typing make).



However, I can't seem to make it working, if I use -MMD, it works perfectly but I rely on system includes too as I'm writing a library too that is evolving along with the project. Thus, if I update the libary header and reinstall the library, typing make in the main project should recompiles files that includes the changed header.



When using -MMD flag, it - as expected - does not recompile the project, however, using -MD flag, it does recompile everything. In fact, -MD recompiles everything every time, even when nothing changed.



Here is a minimal project structure that reproduce the issue:



./Makefile:



all: build

re: clean build

build: build_lib install_lib build_client

build_lib:
$(MAKE) -C lib
$(MAKE) install -C lib

build_client:
$(MAKE) -C client

install_lib:
$(MAKE) install -C lib


.PHONY: clean
clean: clean_lib clean_client

clean_lib:
$(MAKE) clean -C lib

clean_client:
$(MAKE) clean -C client


./client/Makefile:



CC = g++
INC = -I../lib
CXXFLAGS = -Wall $(INC) -g -MD -MP
EXEC_NAME = ../test

src = $(shell find $(SOURCEDIR) -name '*.cpp')
obj = $(src:.cpp=.o)

LIBRARIES = -ltest_lib
LDFLAGS = -rdynamic $(LIBRARIES)

all: $(EXEC_NAME)

re: clean $(EXEC_NAME)

$(EXEC_NAME): $(obj)
$(CC) -o $@ $^ $(LDFLAGS)
-include $(obj:.o=.d)

.PHONY: clean
clean:
rm -f $(obj) $(EXEC_NAME)


./lib/Makefile:



.PHONY : clean

CXXFLAGS= -fPIC -g -Itest_lib/include -MMD -MP
LDFLAGS= -shared

SOURCES = $(shell find $(SOURCEDIR) -name '*.cpp')
HEADERS = $(shell find $(SOURCEDIR) -name '*.h')
OBJECTS=$(SOURCES:.cpp=.o)

TARGET=libtest_lib.so
INC_FOLDER=test_lib/include
CUR_DIR = $(shell pwd)

all: $(TARGET)

install:
sudo rm -rf /usr/local/lib/libtest_lib.so && sudo ln -s $(CUR_DIR)/$(TARGET) /usr/local/lib/libtest_lib.so
sudo rm -rf /usr/local/include/test_lib && sudo cp -r $(INC_FOLDER) /usr/local/include/test_lib

clean:
rm -f $(OBJECTS) $(TARGET)

$(TARGET) : $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) -o $@ $(LDFLAGS)
-include $(OBJECTS:.o=.d)


./client/main.cpp:



#include "bar.h"

int main()
{
Bar b;

b.sayHello();
b.sayBye();

return 0;
}


./client/bar.h



#ifndef __BAR__
#define __BAR__

#include <test_lib/foo.h>
#include <iostream>

struct Bar : public Foo
{
Bar() {};
~Bar() {};

void sayBye() const {
std::cout << "Bye " << name << "..." << std::endl;
};
};

#endif


./lib/test_lib/include/foo.h



#ifndef __FOO__
#define __FOO__

struct Foo
{
const char *name;

Foo(const char *name = "world");
~Foo();

void sayHello() const;
};

#endif


./lib/test_lib/src



#include "foo.h"
#include <iostream>

Foo::Foo(const char *name) : name(name) {}
Foo::~Foo() {}

void Foo::sayHello() const
{
std::cout << "Hello " << name << " !" << std::endl;
}









share|improve this question




















  • 1





    Please post a Minimal, Complete, and Verifiable example that still shows the issue, you need to show an example of your include directives and folder structure.

    – user657267
    Nov 24 '18 at 6:44











  • We can't help given this info. I think you can debug this yourself. First, find the .d files that are generated and look at them. Are they in the right place? That is for every srcdir/foo.c is there a srcdir/foo.d file? Do the contents seem sane? Are the target names correct for the .o files? Are the prerequisite paths correct? If that seems fine, then run make -d (redirect the voluminous output to a file). Locate the process make goes through to decide to rebuild a sample .o. It will tell you exactly what files were out of date. Is it right?

    – MadScientist
    Nov 24 '18 at 14:43











  • @MadScientist make -d indeed helped here. and I understand what's going on here, see my edit, I'm actually reinstalling the library everytime so it thinks the file has changed based on its date. I think I can figure out a better way to update the library

    – Masadow
    Nov 26 '18 at 11:36














0












0








0








I'm trying to create a Makefile where make only recompiles necessary .cpp files.



By default, it works well if I edit .cpp, however, when I edit .h files, it just ignores the changes.



So I've read of -MD flag and its friend -MP (used to avoid bugs when typing make).



However, I can't seem to make it working, if I use -MMD, it works perfectly but I rely on system includes too as I'm writing a library too that is evolving along with the project. Thus, if I update the libary header and reinstall the library, typing make in the main project should recompiles files that includes the changed header.



When using -MMD flag, it - as expected - does not recompile the project, however, using -MD flag, it does recompile everything. In fact, -MD recompiles everything every time, even when nothing changed.



Here is a minimal project structure that reproduce the issue:



./Makefile:



all: build

re: clean build

build: build_lib install_lib build_client

build_lib:
$(MAKE) -C lib
$(MAKE) install -C lib

build_client:
$(MAKE) -C client

install_lib:
$(MAKE) install -C lib


.PHONY: clean
clean: clean_lib clean_client

clean_lib:
$(MAKE) clean -C lib

clean_client:
$(MAKE) clean -C client


./client/Makefile:



CC = g++
INC = -I../lib
CXXFLAGS = -Wall $(INC) -g -MD -MP
EXEC_NAME = ../test

src = $(shell find $(SOURCEDIR) -name '*.cpp')
obj = $(src:.cpp=.o)

LIBRARIES = -ltest_lib
LDFLAGS = -rdynamic $(LIBRARIES)

all: $(EXEC_NAME)

re: clean $(EXEC_NAME)

$(EXEC_NAME): $(obj)
$(CC) -o $@ $^ $(LDFLAGS)
-include $(obj:.o=.d)

.PHONY: clean
clean:
rm -f $(obj) $(EXEC_NAME)


./lib/Makefile:



.PHONY : clean

CXXFLAGS= -fPIC -g -Itest_lib/include -MMD -MP
LDFLAGS= -shared

SOURCES = $(shell find $(SOURCEDIR) -name '*.cpp')
HEADERS = $(shell find $(SOURCEDIR) -name '*.h')
OBJECTS=$(SOURCES:.cpp=.o)

TARGET=libtest_lib.so
INC_FOLDER=test_lib/include
CUR_DIR = $(shell pwd)

all: $(TARGET)

install:
sudo rm -rf /usr/local/lib/libtest_lib.so && sudo ln -s $(CUR_DIR)/$(TARGET) /usr/local/lib/libtest_lib.so
sudo rm -rf /usr/local/include/test_lib && sudo cp -r $(INC_FOLDER) /usr/local/include/test_lib

clean:
rm -f $(OBJECTS) $(TARGET)

$(TARGET) : $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) -o $@ $(LDFLAGS)
-include $(OBJECTS:.o=.d)


./client/main.cpp:



#include "bar.h"

int main()
{
Bar b;

b.sayHello();
b.sayBye();

return 0;
}


./client/bar.h



#ifndef __BAR__
#define __BAR__

#include <test_lib/foo.h>
#include <iostream>

struct Bar : public Foo
{
Bar() {};
~Bar() {};

void sayBye() const {
std::cout << "Bye " << name << "..." << std::endl;
};
};

#endif


./lib/test_lib/include/foo.h



#ifndef __FOO__
#define __FOO__

struct Foo
{
const char *name;

Foo(const char *name = "world");
~Foo();

void sayHello() const;
};

#endif


./lib/test_lib/src



#include "foo.h"
#include <iostream>

Foo::Foo(const char *name) : name(name) {}
Foo::~Foo() {}

void Foo::sayHello() const
{
std::cout << "Hello " << name << " !" << std::endl;
}









share|improve this question
















I'm trying to create a Makefile where make only recompiles necessary .cpp files.



By default, it works well if I edit .cpp, however, when I edit .h files, it just ignores the changes.



So I've read of -MD flag and its friend -MP (used to avoid bugs when typing make).



However, I can't seem to make it working, if I use -MMD, it works perfectly but I rely on system includes too as I'm writing a library too that is evolving along with the project. Thus, if I update the libary header and reinstall the library, typing make in the main project should recompiles files that includes the changed header.



When using -MMD flag, it - as expected - does not recompile the project, however, using -MD flag, it does recompile everything. In fact, -MD recompiles everything every time, even when nothing changed.



Here is a minimal project structure that reproduce the issue:



./Makefile:



all: build

re: clean build

build: build_lib install_lib build_client

build_lib:
$(MAKE) -C lib
$(MAKE) install -C lib

build_client:
$(MAKE) -C client

install_lib:
$(MAKE) install -C lib


.PHONY: clean
clean: clean_lib clean_client

clean_lib:
$(MAKE) clean -C lib

clean_client:
$(MAKE) clean -C client


./client/Makefile:



CC = g++
INC = -I../lib
CXXFLAGS = -Wall $(INC) -g -MD -MP
EXEC_NAME = ../test

src = $(shell find $(SOURCEDIR) -name '*.cpp')
obj = $(src:.cpp=.o)

LIBRARIES = -ltest_lib
LDFLAGS = -rdynamic $(LIBRARIES)

all: $(EXEC_NAME)

re: clean $(EXEC_NAME)

$(EXEC_NAME): $(obj)
$(CC) -o $@ $^ $(LDFLAGS)
-include $(obj:.o=.d)

.PHONY: clean
clean:
rm -f $(obj) $(EXEC_NAME)


./lib/Makefile:



.PHONY : clean

CXXFLAGS= -fPIC -g -Itest_lib/include -MMD -MP
LDFLAGS= -shared

SOURCES = $(shell find $(SOURCEDIR) -name '*.cpp')
HEADERS = $(shell find $(SOURCEDIR) -name '*.h')
OBJECTS=$(SOURCES:.cpp=.o)

TARGET=libtest_lib.so
INC_FOLDER=test_lib/include
CUR_DIR = $(shell pwd)

all: $(TARGET)

install:
sudo rm -rf /usr/local/lib/libtest_lib.so && sudo ln -s $(CUR_DIR)/$(TARGET) /usr/local/lib/libtest_lib.so
sudo rm -rf /usr/local/include/test_lib && sudo cp -r $(INC_FOLDER) /usr/local/include/test_lib

clean:
rm -f $(OBJECTS) $(TARGET)

$(TARGET) : $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) -o $@ $(LDFLAGS)
-include $(OBJECTS:.o=.d)


./client/main.cpp:



#include "bar.h"

int main()
{
Bar b;

b.sayHello();
b.sayBye();

return 0;
}


./client/bar.h



#ifndef __BAR__
#define __BAR__

#include <test_lib/foo.h>
#include <iostream>

struct Bar : public Foo
{
Bar() {};
~Bar() {};

void sayBye() const {
std::cout << "Bye " << name << "..." << std::endl;
};
};

#endif


./lib/test_lib/include/foo.h



#ifndef __FOO__
#define __FOO__

struct Foo
{
const char *name;

Foo(const char *name = "world");
~Foo();

void sayHello() const;
};

#endif


./lib/test_lib/src



#include "foo.h"
#include <iostream>

Foo::Foo(const char *name) : name(name) {}
Foo::~Foo() {}

void Foo::sayHello() const
{
std::cout << "Hello " << name << " !" << std::endl;
}






makefile






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 11:28







Masadow

















asked Nov 24 '18 at 0:24









MasadowMasadow

462212




462212








  • 1





    Please post a Minimal, Complete, and Verifiable example that still shows the issue, you need to show an example of your include directives and folder structure.

    – user657267
    Nov 24 '18 at 6:44











  • We can't help given this info. I think you can debug this yourself. First, find the .d files that are generated and look at them. Are they in the right place? That is for every srcdir/foo.c is there a srcdir/foo.d file? Do the contents seem sane? Are the target names correct for the .o files? Are the prerequisite paths correct? If that seems fine, then run make -d (redirect the voluminous output to a file). Locate the process make goes through to decide to rebuild a sample .o. It will tell you exactly what files were out of date. Is it right?

    – MadScientist
    Nov 24 '18 at 14:43











  • @MadScientist make -d indeed helped here. and I understand what's going on here, see my edit, I'm actually reinstalling the library everytime so it thinks the file has changed based on its date. I think I can figure out a better way to update the library

    – Masadow
    Nov 26 '18 at 11:36














  • 1





    Please post a Minimal, Complete, and Verifiable example that still shows the issue, you need to show an example of your include directives and folder structure.

    – user657267
    Nov 24 '18 at 6:44











  • We can't help given this info. I think you can debug this yourself. First, find the .d files that are generated and look at them. Are they in the right place? That is for every srcdir/foo.c is there a srcdir/foo.d file? Do the contents seem sane? Are the target names correct for the .o files? Are the prerequisite paths correct? If that seems fine, then run make -d (redirect the voluminous output to a file). Locate the process make goes through to decide to rebuild a sample .o. It will tell you exactly what files were out of date. Is it right?

    – MadScientist
    Nov 24 '18 at 14:43











  • @MadScientist make -d indeed helped here. and I understand what's going on here, see my edit, I'm actually reinstalling the library everytime so it thinks the file has changed based on its date. I think I can figure out a better way to update the library

    – Masadow
    Nov 26 '18 at 11:36








1




1





Please post a Minimal, Complete, and Verifiable example that still shows the issue, you need to show an example of your include directives and folder structure.

– user657267
Nov 24 '18 at 6:44





Please post a Minimal, Complete, and Verifiable example that still shows the issue, you need to show an example of your include directives and folder structure.

– user657267
Nov 24 '18 at 6:44













We can't help given this info. I think you can debug this yourself. First, find the .d files that are generated and look at them. Are they in the right place? That is for every srcdir/foo.c is there a srcdir/foo.d file? Do the contents seem sane? Are the target names correct for the .o files? Are the prerequisite paths correct? If that seems fine, then run make -d (redirect the voluminous output to a file). Locate the process make goes through to decide to rebuild a sample .o. It will tell you exactly what files were out of date. Is it right?

– MadScientist
Nov 24 '18 at 14:43





We can't help given this info. I think you can debug this yourself. First, find the .d files that are generated and look at them. Are they in the right place? That is for every srcdir/foo.c is there a srcdir/foo.d file? Do the contents seem sane? Are the target names correct for the .o files? Are the prerequisite paths correct? If that seems fine, then run make -d (redirect the voluminous output to a file). Locate the process make goes through to decide to rebuild a sample .o. It will tell you exactly what files were out of date. Is it right?

– MadScientist
Nov 24 '18 at 14:43













@MadScientist make -d indeed helped here. and I understand what's going on here, see my edit, I'm actually reinstalling the library everytime so it thinks the file has changed based on its date. I think I can figure out a better way to update the library

– Masadow
Nov 26 '18 at 11:36





@MadScientist make -d indeed helped here. and I understand what's going on here, see my edit, I'm actually reinstalling the library everytime so it thinks the file has changed based on its date. I think I can figure out a better way to update the library

– Masadow
Nov 26 '18 at 11:36












1 Answer
1






active

oldest

votes


















0














Problem was that I copied the library headers all the time in /usr/local so the files got newer and the client make then thought every header of the library had changed.



A simple fix to this problem was to replace in the library Makefile the following line:



sudo rm -rf /usr/local/include/test_lib && sudo cp -r $(INC_FOLDER) /usr/local/include/test_lib



by



sudo rm -rf /usr/local/include/test_lib && sudo ln -s $(CUR_DIR)/$(INC_FOLDER) /usr/local/include/test_lib



On a side note, provided example is missing the removal of .d files on the clean rule.






share|improve this answer
























    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%2f53454174%2fhow-to-properly-use-md-flag-in-makefile%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














    Problem was that I copied the library headers all the time in /usr/local so the files got newer and the client make then thought every header of the library had changed.



    A simple fix to this problem was to replace in the library Makefile the following line:



    sudo rm -rf /usr/local/include/test_lib && sudo cp -r $(INC_FOLDER) /usr/local/include/test_lib



    by



    sudo rm -rf /usr/local/include/test_lib && sudo ln -s $(CUR_DIR)/$(INC_FOLDER) /usr/local/include/test_lib



    On a side note, provided example is missing the removal of .d files on the clean rule.






    share|improve this answer




























      0














      Problem was that I copied the library headers all the time in /usr/local so the files got newer and the client make then thought every header of the library had changed.



      A simple fix to this problem was to replace in the library Makefile the following line:



      sudo rm -rf /usr/local/include/test_lib && sudo cp -r $(INC_FOLDER) /usr/local/include/test_lib



      by



      sudo rm -rf /usr/local/include/test_lib && sudo ln -s $(CUR_DIR)/$(INC_FOLDER) /usr/local/include/test_lib



      On a side note, provided example is missing the removal of .d files on the clean rule.






      share|improve this answer


























        0












        0








        0







        Problem was that I copied the library headers all the time in /usr/local so the files got newer and the client make then thought every header of the library had changed.



        A simple fix to this problem was to replace in the library Makefile the following line:



        sudo rm -rf /usr/local/include/test_lib && sudo cp -r $(INC_FOLDER) /usr/local/include/test_lib



        by



        sudo rm -rf /usr/local/include/test_lib && sudo ln -s $(CUR_DIR)/$(INC_FOLDER) /usr/local/include/test_lib



        On a side note, provided example is missing the removal of .d files on the clean rule.






        share|improve this answer













        Problem was that I copied the library headers all the time in /usr/local so the files got newer and the client make then thought every header of the library had changed.



        A simple fix to this problem was to replace in the library Makefile the following line:



        sudo rm -rf /usr/local/include/test_lib && sudo cp -r $(INC_FOLDER) /usr/local/include/test_lib



        by



        sudo rm -rf /usr/local/include/test_lib && sudo ln -s $(CUR_DIR)/$(INC_FOLDER) /usr/local/include/test_lib



        On a side note, provided example is missing the removal of .d files on the clean rule.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 11:47









        MasadowMasadow

        462212




        462212
































            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%2f53454174%2fhow-to-properly-use-md-flag-in-makefile%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







            這個網誌中的熱門文章

            Tangent Lines Diagram Along Smooth Curve

            Yusuf al-Mu'taman ibn Hud

            Zucchini