Failed to link python when cross compiling with cmake

I tried to cross compile lammps but there are some link problems.

/usr/lib64/libpng.so: error adding symbols: File in wrong format
/usr/lib64/libpython3.6m.so: error adding symbols: File in wrong format

I successfully deal with png linking problem by commenting out all png related codes. But python dependencies are hard to comment all out. Is there a elegant way?

There is not enough information here to give any meaningful advice:

  • what platform are you cross-compiling on and what is your target platform?
  • what compiler toolkit do you use and what is your host OS and version?
  • what is your LAMMPS version?
  • which of the two build systems (CMake or GNU make based) do you use?
    • in case of the former: what is your CMake command line?
    • in case of the latter: what is your “machine” makefile?
  • do you use any of the scripts posted in the lammps-packages repository that are used for building the Linux-to-Windows cross-compiled installer packages for Windows?

All optional features (and PNG support as well as embedded Python support are certainly optional) can be avoided through the correct settings during configuration and by avoiding to install/include the python package.

Thank you. It’s a little bit complex. I try to compile LAMMPS in fugaku. The cross-compiling machine is an x86 Redhat 8 Linux(login node), the target platform is an arm Linux(compute node). The compiler is a clang7-based compiler FCC. LAMMPS version is lammps-2Aug2023. I use cmake, here are all the custom commands:

set(GLIBCXX_USE_CXX11_ABI 1)
add_compile_options(-D_GLIBCXX_USE_CXX11_ABI=1)
set(CMAKE_CXX_COMPILER /opt/FJSVxtclanga/tcsds-1.2.38/bin/mpiFCCpx)
set(CMAKE_C_COMPILER /opt/FJSVxtclanga/tcsds-1.2.38/bin/mpifccpx)

The root cause is /usr/lib64/libpython3.6m.so is x86 format library, but my object files need a arm format library. So there are two ways:

  1. disable python dependencies in cmake
  2. specify a correct python path

Consider I didn’t need python in lammps at all. So is there a way to remove python dependencies in cmake?

I am well versed in cross-compiling. I’ve even built my own cross-compiling environments for a variety of platforms and even wrote my own CMake toolkit files (last for a Linux-to-Linux cross compiler to build fully static Linux-x86_64 executables with MUSL-libc on a GNU-libc host).

Is there such a toolkit file for your platform? That would make sure it doesn’t pick up the wrong libraries.

This is not helping. I need to know everything you do to compile. The issue is most likely due to the basic compilation and configuration choices.

This game works the other way around. By default LAMMPS will build a very frugal executable with no dependencies on external libraries beyond what is needed for MPI and OpenMP; and even those can be turned off with -D BUILD_MPI=no and -D BUILD_OMP=no.

PNG (and JPG) support can be turned off in a similar fashion: 3.5. Optional build settings — LAMMPS documentation
But with a proper CMake toolkit file, CMake would not even look in the build host folders.

…and then you have add-on packages:
https://docs.lammps.org/Build_package.html

Why did you include the PYTHON package in the first place?
That is the only way I can think of that would import that dependency.

Sorry for the delay. I found it had nothing to do with lammps. I added libtorch to the lammps cmake file too, the error was thrown by libtorch. Thank you.

This is very irritating and disappointing to read.

When I asked you about the LAMMPS version, you should have mentioned that you didn’t use a plain LAMMPS package, but had applied modifications. I had explicitly asked you to tell me “everything”. You wasted a significant chunk of my time.