Bug in Makefile.shlib when compiling for the python wrapper

Submitted by AndresMM on Fri, 11/10/2017 - 13:26

Intro to the problem: https://www.cfdem.com/forums/python-interface-liggghts-using-auto-makefile

TL;DR: I want to compile the python wrapper for liggghts using the auto make file.
The commands:

make makeshlib
make -f Makefile.shlib auto

Do not work. The make tries to work in Obj_auto and not in Obj_shlib_auto as it should.

The bug itself lies in the Makefile.shlib, originally it reads:


clean:
rm -rf Obj_*
.DEFAULT:
@test -f MAKE/Makefile.$@
@if [ ! -d Obj_$(SUBTARGET) ]; then mkdir Obj_$(SUBTARGET); fi
@cp -p $(SRC) $(INC) Obj_$(SUBTARGET)
@cp MAKE/Makefile.$@ Obj_$(SUBTARGET)/Makefile
@if [ ! -e Makefile.package ]; \
then cp Makefile.package.empty Makefile.package; fi
@if [ ! -e Makefile.package.settings ]; \
then cp Makefile.package.settings.empty Makefile.package.settings; fi
@cp Makefile.package Makefile.package.settings Obj_$(SUBTARGET)
@cd Obj_$(SUBTARGET); \
$(MAKE) $(MFLAGS) "OBJ = $(OBJ)" \
"INC = $(INC)" "EXE = ../$(EXE)" shlib
@if [ -d Obj_$(SUBTARGET) ]; then cd Obj_$(SUBTARGET); \
rm -f $(SRC) $(INC) Makefile*; fi

The solution. Change Makefile.shlib to :


clean:
rm -rf Obj_shlib_*
.DEFAULT:
@test -f MAKE/Makefile.$@
@if [ ! -d Obj_shlib_$@ ]; then mkdir Obj_shlib_$@; fi
@cp -p $(SRC) $(INC) Obj_shlib_$@
@cp MAKE/Makefile.$@ Obj_shlib_$@/Makefile
@if [ ! -e Makefile.package ]; \
then cp Makefile.package.empty Makefile.package; fi
@if [ ! -e Makefile.package.settings ]; \
then cp Makefile.package.settings.empty Makefile.package.settings; fi
@cp Makefile.package Makefile.package.settings Obj_shlib_$@
@cd Obj_shlib_$@; \
$(MAKE) $(MFLAGS) "OBJ = $(OBJ)" \
"INC = $(INC)" "EXE = ../$(EXE)" shlib
@rm -f liblammps.so
@ln -s $(EXE) liblammps.so
@if [ -d Obj_shlib_$@ ]; then cd Obj_shlib_$@; \
rm -f $(SRC) $(INC) Makefile*; fi

And it should work now.

aaigner's picture

aaigner | Fri, 11/10/2017 - 21:37

Thanks for bringing this up. I change it during the next release (next 2-3 weeks).

arnom's picture

arnom | Mon, 11/13/2017 - 15:08

Hi Andres,

I don't understand your problem. Makefile.shlib should operate in Obj_auto and not Obj_shlib_auto. I also do not see any error that you posted, so please provide further details.

Best,
Arno

DCS team member & LIGGGHTS(R) core developer

Westbrink | Mon, 11/13/2017 - 15:09

Hi,

I tried your changes, but have still a problem. The compiling ends with:

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
Makefile:745: recipe for target 'shlib' failed
make[1]: *** [shlib] Error 1
make[1]: Leaving directory '/home/dem/LIGGGHTS-PUBLIC/src/Obj_shlib_auto'
Makefile.shlib:42: recipe for target 'auto' failed
make: *** [auto] Error 2

Do you have a solution?

Regards,
Westbrink

arnom's picture

arnom | Mon, 11/13/2017 - 17:55

Hi all,

I think I know where the confusion comes from.
make -f Makefile.shlib auto
creates a liblmp_auto.so file. Now in the help it currently states that you need to use
from lammps import *
So you need a liblammps.so file which you can create by using
ln -s liblmp_auto.s liblammps.so
Note that no modification to the Makefile.shlib should be necessary for this. Please let me know if this works. If this is true, then we will update the documentation to reflect this.

DCS team member & LIGGGHTS(R) core developer

AndresMM | Tue, 11/14/2017 - 10:34

Hi everyone,

Some more information, I compiled shared LIGGGHTS in three computers, in two (computer A and B) of them I had already compiled LIGGGHTS with a modified ubuntuVTK6 makefile, and on the third one (Computer C) I just used the auto makefile.

I then compiled shared LIGGGHTS in A and B without any problems, but I was not able to do so in computer C. I looked for differences between both cases and I noted that in A and B a folder called "Obj_shlib_ubuntuVTK6" was created, while this did not happen in computer C (I expected a Obj_shlib_auto folder), basically nothing happened (it was recompiled in Obj_Auto) in computer C when I executed

make makeshlib
make -f Makefile.shlib auto.

So I looked between the versions of makefile.shlib in computers A/B and computer C. In A/B, the makefile-shlib worked on Obj_shlib_XXXX, while in C, it worked on Obj_XXXX. I changed the makefile.shlib as explained above and it worked, I could use python to execute LIGGGHTS and I got the same results as in Computer A and B.

@Arno
You are probably right and it should work. However the instructions in the current documentation do not work when one uses the auto to make it shared. I know they work when used for other makes, since I also compiled shared LIGGGHTS in Computer D using an old fedora_VTK_fpic makefile.

I may have missed something obvious since I do not have a lot of experience with program compilation, and with the above fixed it just worked.

Anyway, thank you for your response

arnom's picture

arnom | Tue, 11/14/2017 - 15:47

I have reenabled the automatic linking and rewrote the documentation. There will be a few naming changes so please have a look as soon as the release is out. Thank you for reporting the issue.

DCS team member & LIGGGHTS(R) core developer