0

I am using makefile to build my code for boost cpp application. When makefile get executed it shows following message

g++ -c -Wall -I/c/MinGW/include/ -lboost_system -lws2_32 Timer_async.cpp -o Timer_async.o

and throws following error

#include <boost/asio.hpp>
                          ^
compilation terminated.
mingw32-make: *** [makefile:15: Timer_async.o] Error 1

but if I run this makefile generated command from shell prompt

g++ -c -Wall -I/c/MinGW/include/ -lboost_system -lws2_32 Timer_async.cpp -o Timer_async.o

Program builds properly.

My make file is as

CC=g++
CFLAGS=-c -Wall
LDFLAGS=-lboost_system -lws2_32
INCLUDES=-I/c/MinGW/include/
SOURCES=Timer_async.cpp
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=hello

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
    $(CC) $(SOURCES) $(INCLUDES) $(LDFLAGS) -o $@

.cpp.o:
    $(CC) $(CFLAGS) $(INCLUDES) $(LDFLAGS) $< -o $@
prasad
  • 219
  • 3
  • 17

2 Answers2

0

Why do you specify both $(SOURCES) and $(EXECUTABLE) as dependencies to all? What is that adding that the $(EXECUTABLE) rule isn't achieving?

The #include is failing (that's what the diagnostic message seems to indicate) because the target file cannot be found. You have used the -I flag incorrectly. That will only influence how includedFile.c is located; it has no effect on <includedFile.c>.

Your conclusion "Makefile command not executed" (and I have no idea what a "Makefile command" is) was unwarranted. make did exactly what it was supposed to.

Laurel
  • 5,965
  • 14
  • 31
  • 57
  • I used this standard makefile form http://mrbook.org/blog/tutorials/make/ and added my support for INCLUDE macro. – prasad Jul 13 '16 at 15:28
  • The error is executing same line from shell vs executing it from make. So i don't think this is due to -I flag. – prasad Jul 13 '16 at 15:38
0

I think the error is may be how conemu handles file paths. after changing make file to following more specific

CFLAGS = -c -I/c/MinGW/include
2
3  hello: Timer_async.o
4
5  Timer_async.o: Timer_async.cpp
6          g++ $(CFLAGS) Timer_async.cpp
7
8  clean:
9          rm Timer_async.o

I was still getting errors but after adding double quotes in path all errors were corrected.

My modified make file is

CFLAGS = -c -I"/c/MinGW/include"
2
3  hello: Timer_async.o
4
5  Timer_async.o: Timer_async.cpp
6          g++ $(CFLAGS) Timer_async.cpp
7
8  clean:
9          rm Timer_async.o
prasad
  • 219
  • 3
  • 17