I have a problem with the archiver not seeming to archive the object files fully correctly every time when building in parallel. I have built the project with make -j32
If I investigate the archive:
ar x mylib.a
ls -l myFile.o
-rw-rw-r-- 1 tester users 0 Mar 00:00:00 myFile.o
Also running the program nm
shows no symbols.
However, when I investigate the object file in the obj-directory the file has symbols and a nonzero size so it seems that the archiver has not archived the lib correctly.
My makefile for building the libs looks as follows:
AR := flock make.lock $(AR)
all: createLib
TARGET_OBJECTS = $(addprefix $(OBJDIR)/, $(OBJECTS))
createLib: $(TARGET_OBJECTS)
@echo "----- Archiving lib ($(LIB))"
mkdir -p $(LIBDIR)
$(AR) ru $(LIBDIR)/$(LIB) $^
$(OBJDIR)/%.o: %.cc
@echo "----- Compiling file $< for ($(LIB))"
$(VERB)mkdir -p $(@D)
$(VERB)mkdir -p $(OBJDIR)
$(VERB)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $($(*F)_CPPFLAGS) -c $(addprefix ${PWD}/, $<) -o $@
As you can see I even use a file lock to make sure that only one thread can archive the lib at the same time. So why is the object file empty? I have specified the lib to be archived only when the object file has finished building but it seems that there is a race condition with the archiver starting archiving before the last object file is fully built. So what could be the cause for this behaviour?
I should add that it mostly seems to be one file in the library which gets this problem but it can be other files aswell.