0

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.

Euklides
  • 564
  • 1
  • 10
  • 35
  • Also I should add that even when rebuilding the project the library is not updated since $(TARGET_OBJECTS) are ok. – Euklides Mar 28 '15 at 00:21
  • What version of GNU make are you using, and what platform are you using it on? I don't see any obvious errors here (although there are a few weird things), although this is clearly not your real makefile so perhaps there's something wrong in the real makefile that's not been transposed here. But if not perhaps it's a bug in GNU make; if you're not using the latest version (4.1) you might try that to see if it helps. – MadScientist Mar 28 '15 at 12:45
  • I was running GNU Make 3.81 but I tested 4.0 but with no success. I am running kernel 3.18.9 with RT patch. However, I deleted the entire project and rebuilded the project and then it was working again. Seems that there was something there that made Make want to rebuild. I dont know what though. Perhaps a bug. – Euklides Mar 28 '15 at 16:06
  • The kernel version is not relevant: by "what platform" I meant GNU/Linux, Windows, OSX, Solaris, AIX, VMS, etc. I'll assume from your response you are using GNU/Linux. Based on your description a clean build shouldn't have made any difference: if it really was the case that make was trying to construct the library before the objects had been built, and your makefile really looks like what you showed, then there's no way that could happen. – MadScientist Mar 28 '15 at 17:01
  • Looks like `$(TARGET_OBJECTS)` is empty. Could you please check that. – Dima Chubarov Mar 29 '15 at 06:52

0 Answers0