Technical records
January 29, 2020

[# ERROR FIXING] LAMMPS writing movie failure & undefined reference to `png_create_write_struct'

/*Remark: This is the first ERROR FIXING record of this blog.*/

platform information: raspberrypi 4.


Error report:

ERROR on proc 0: Support for writing movies not included (../dump_movie.cpp:52)
/usr/bin/ld: image.o: in function `LAMMPS_NS::Image::write_PNG(_IO_FILE*)':
/home/pi/lammps/lammps-7Aug19/src/Obj_serial/../image.cpp:1032: undefined reference to `png_create_write_struct'
/usr/bin/ld: /home/pi/lammps/lammps-7Aug19/src/Obj_serial/../image.cpp:1036: undefined reference to `png_create_info_struct'
/usr/bin/ld: /home/pi/lammps/lammps-7Aug19/src/Obj_serial/../image.cpp:1042: undefined reference to `png_set_longjmp_fn'
/usr/bin/ld: /home/pi/lammps/lammps-7Aug19/src/Obj_serial/../image.cpp:1043: undefined reference to `png_destroy_write_struct'
/usr/bin/ld: /home/pi/lammps/lammps-7Aug19/src/Obj_serial/../image.cpp:1038: undefined reference to `png_destroy_write_struct'
/usr/bin/ld: /home/pi/lammps/lammps-7Aug19/src/Obj_serial/../image.cpp:1047: undefined reference to `png_init_io'
/usr/bin/ld: /home/pi/lammps/lammps-7Aug19/src/Obj_serial/../image.cpp:1048: undefined reference to `png_set_compression_level'
/usr/bin/ld: /home/pi/lammps/lammps-7Aug19/src/Obj_serial/../image.cpp:1049: undefined reference to `png_set_IHDR'
/usr/bin/ld: /home/pi/lammps/lammps-7Aug19/src/Obj_serial/../image.cpp:1066: undefined reference to `png_set_text'
/usr/bin/ld: /home/pi/lammps/lammps-7Aug19/src/Obj_serial/../image.cpp:1067: undefined reference to `png_write_info'
/usr/bin/ld: /home/pi/lammps/lammps-7Aug19/src/Obj_serial/../image.cpp:1073: undefined reference to `png_write_image'
/usr/bin/ld: /home/pi/lammps/lammps-7Aug19/src/Obj_serial/../image.cpp:1074: undefined reference to `png_write_end'
/usr/bin/ld: /home/pi/lammps/lammps-7Aug19/src/Obj_serial/../image.cpp:1076: undefined reference to `png_destroy_write_struct'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:89: ../lmp_serial] Error 1
make[1]: Leaving directory '/home/pi/lammps/lammps-7Aug19/src/Obj_serial'
make: *** [Makefile:217: serial] Error 2

As seen from above, there are two errors. Actually, the second error occur while trying to fix the first error.


ERROR DESCRIPTION

1. According to MANUAL (Aug 06, 2019, p.365), the first error:

Support for writing images in JPEG format not included LAMMPS was not built with the -DLAMMPS_JPEG switch in the Makefile.
Support for writing images in PNG format not included LAMMPS was not built with the -DLAMMPS_PNG switch in the Makefile.
Support for writing movies not included LAMMPS was not built with the -DLAMMPS_FFMPEG switch in the Makefile

2. According to Internet resources, the second error:

https://blog.csdn.net/yaoyefengchen/article/details/20012723

https://www.linuxidc.com/Linux/2014-02/97344.htm


ERROR FIXING

The fixing process of the first error should follow MANUAL (Aug 06, 2019, p.38).

  1. open the corresponding Makefile document, under /src/MAKE. I only edited the makefile for lmp_serial.
  2. find the string 'LMP_INC ='.
  3. add the switch: '-DLAMMPS_FFMPEG' to the end of that expression.
  4. save and exist.

[Remark]: since here I didn't turn on the switch for generating JPEG and PNG images, some other configurations are omitted (as pointed out on p.38, writing paths of libraries for images etc.). Though only part of the task had finished and presented here, I believe the rest (lmp_mpi, image) should be easy.

The second error looks tricky. We should notice that, the real error message is not the ones directly shown at the end:

collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:89: ../lmp_serial] Error 1
make[1]: Leaving directory '/home/pi/lammps/lammps-7Aug19/src/Obj_serial'
make: *** [Makefile:217: serial] Error 2

These are not real error messages, which fooled me into finding out reasons on the Internet and took a long time. Albeit some interesting posts are found online:

https://stackoverflow.com/questions/15273904/make-error-make1-directories-error-1

The real solution should follow from the links mentioned in the previous section. However, I would reform it in my way:

  1. find where is the library for png: '$locate libpng'. The first returned result should be the package we want. In my case '/lib/arm-linux-gnueabihf/libpng12.so.0'.
  2. open the corresponding Makefile. Add the package found in step 1 & ' -lpng' to the 'LIB = '. In this case of LAMMPS, the final result should be 'LIB = /lib/arm-linux-gnueabihf/libpng12.so.0 -lpng.
  3. save and exist.

[Remark]: it is slightly different from the links. I think the links would also work.


Reflection

The two errors here are quite strange, which haven't occured on the Cluster and Lab-Desktop. Moreover, the reason for the second error is opaque to me. It is very weird that an error that never happened before suddenly appear, under very similiar conditions. Whether there is any connections between the two is also unknown.