Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile - Erro: file truncated

Tags:

c++

makefile

g++

i have a simple Makefile:

CC=g++

CFLAGS= -Wall -std=c++11 -M -MF dependencyFileName.d -c

objects = Table.o LimitedTable.o aDimension.o test.o

edit: $(objects)
    g++ -o edit $(objects)

test.o: LimitedTable.o Table.o aDimension.o test.cpp
    $(CC) $(CFLAGS) test.cpp -o test.o

LimitedTable.o: LimitedTable.cpp LimitedTable.hpp Table.o aDimension.o
    $(CC) $(CFLAGS) LimitedTable.cpp -o LimitedTable.o

aDimension.o: aDimension.cpp aDimension.cpp Table.o
    $(CC) $(CFLAGS) aDimension.cpp -o aDimension.o

Table.o: Table.cpp Table.hpp
    $(CC) $(CFLAGS) Table.cpp -o Table.o

clean:
    rm -f *.o

and I get this error:

marius@marius-Lenovo-Y50-70 ~/Documents $ make clean
rm -f *.o
marius@marius-Lenovo-Y50-70 ~/Documents $ make edit
g++ -Wall -std=c++11 -M -MF dependencyFileName.d -c Table.cpp -o Table.o
g++ -Wall -std=c++11 -M -MF dependencyFileName.d -c aDimension.cpp -o aDimension.o
g++ -Wall -std=c++11 -M -MF dependencyFileName.d -c LimitedTable.cpp -o LimitedTable.o
g++ -Wall -std=c++11 -M -MF dependencyFileName.d -c test.cpp -o test.o
g++ -o edit Table.o LimitedTable.o aDimension.o test.o
Table.o: file not recognized: File truncated
collect2: error: ld returned 1 exit status
make: *** [edit] Error 1

Can anyone tell me what is wrong ? Could a wrong include in one of the files be a reason for this error ?

like image 454
Marius Küpper Avatar asked May 07 '26 07:05

Marius Küpper


1 Answers

There are some problems with the way you handle your dependency file, but first:

I have a simple Makefile

No you don't. The amount of boilerplate code is way too high, and adding any file to your projet will require you to manually edit that makefile again.

Your Makefile should be boiled down to this:

SRC         :=  $(wildcard *.cpp)
OBJ         :=  $(SRC:.cpp=.o)
DEP         :=  $(OBJ:.o=.d)
CPPFLAGS    :=  -MMD -MP
CXXFLAGS    :=  -std=c++11 -Wall

edit: $(OBJ)
    $(CXX) $^ -o $@

-include $(DEP)

clean:
    $(RM) $(OBJ) $(DEP)

Here you :

  • avoid repeating yourself too much,
  • make good use of make's implicit rules to save time,
  • use the right built-in variables instead of overriding the wrong ones,
  • correctly handle dependency files creation and actually use them to prevent manual recompilation,
  • won't need to edit the makefile when adding a .cpp or .hpp file to your project.

Also, that should fix your problem. Don't forget to clean before trying to compile again after such an error ("file truncated") occurred.

like image 80
Chnossos Avatar answered May 09 '26 05:05

Chnossos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!