2

I have a problem when I compile my program, I have been trying some solutions on Questions but it doesnt work for me, so here is my problem

INCLUDE = include
LIB     = lib
OBJ     = obj
SRC     = src
BIN     = bin
CXX     = g++
CPPFLAGS = -Wall -g -c 

$(BIN)/pruebacronologia : $(OBJ)/pruebacronologia.o 
    $(CXX) -o $(BIN)/pruebacronologia $(OBJ)/EventoHistorico.o $(SRC)/EventoHistorico.cpp -I$(INCLUDE)
$(OBJ)/EventoHistorico.o : $(SRC)/EventoHistorico.cpp
    $(CXX) $(CPPFLAGS)  -o $(OBJ)/EventoHistorico.o $(SRC)/EventoHistorico.cpp -I$(INCLUDE)

$(OBJ)/cronologia.o : $(SRC)/cronologia.cpp $(OBJ)/EventoHistorico.o
    $(CXX) $(CPPFLAGS) -o $(OBJ)/cronologia.o $(SRC)/cronologia.cpp $(OBJ)/EventoHistorico.o -I$(INCLUDE)

$(OBJ)/pruebacronologia.o : $(SRC)/pruebacronologia.cpp $(OBJ)/cronologia.o 
    $(CXX) $(CPPFLAGS) -o $(OBJ)/pruebacronologia.o $(SRC)/pruebacronologia.cpp $(OBJ)/cronologia.o $(OBJ)/EventoHistorico.o -I$(INCLUDE)

Then i get this error on bash:

g++: warning: obj/cronologia.o: linker input file unused because linking not done
g++: warning: obj/EventoHistorico.o: linker input file unused because linking not done
g++ -o obj/EventoHistorico.o -Iinclude
g++: fatal error: no input files
compilation terminated.
make: *** [bin/pruebacronologia] Error 4

1 Answer 1

1

Your makefile seems to be not well construct. For each target .o, just set a .o compiled from the corresponding .c file. To contruct the executable, just append all .o generated. I think something like this will work better :

INCLUDE = include
LIB     = lib
OBJ     = obj
SRC     = src
BIN     = bin
CXX     = g++
CPPFLAGS = -Wall -g -c 

$(BIN)/pruebacronologia : $(OBJ)/cronologia.o $(OBJ)/pruebacronologia.o $(OBJ)/EventoHistorico.o 
    $(CXX) -o $(BIN)/pruebacronologia $^ $(LDFLAGS)

$(OBJ)/EventoHistorico.o : $(SRC)/EventoHistorico.cpp
    $(CXX) $(CPPFLAGS)  -o $(OBJ)/EventoHistorico.o $(SRC)/EventoHistorico.cpp -I$(INCLUDE)

$(OBJ)/cronologia.o : $(SRC)/cronologia.cpp 
    $(CXX) $(CPPFLAGS) -o $(OBJ)/cronologia.o $(SRC)/cronologia.cpp -I$(INCLUDE)

$(OBJ)/pruebacronologia.o : $(SRC)/pruebacronologia.cpp  
    $(CXX) $(CPPFLAGS) -o $(OBJ)/pruebacronologia.o $(SRC)/pruebacronologia.cpp -I$(INCLUDE)
Sign up to request clarification or add additional context in comments.

2 Comments

You have to add the -c option to the compiler when you want to generate object files. Otherwise it will try to link a program and fail.
Tanks, now Im getting some program errors, and still dont know why.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.