thermohub / thermofun

A code for calculating the standard state thermodynamic properties at a given temperature and pressure.
https://thermohub.org/thermofun/thermofun/
GNU Lesser General Public License v2.1
26 stars 8 forks source link

Successful ChemicalFun build ARM64 Android Termux #39

Closed defencedog closed 1 year ago

defencedog commented 2 years ago

I have successfully build & installed chemicalfun git version but there is a weird issue

cmake .. -DPYTHON_EXECUTABLE=/data/data/com.termux/files/usr/bin/python3.9 -DCMAKE_INSTALL_PREFIX=/data/data/com.termux/files/usr

The final output

Install the project...
-- Install configuration: "RelWithDebInfo"
-- Installing: /data/data/com.termux/files/usr/lib/cmake/ChemicalFun/ChemicalFunTargets.cmake
-- Installing: /data/data/com.termux/files/usr/lib/cmake/ChemicalFun/ChemicalFunTargets-relwithdebinfo.cmake
-- Installing: /data/data/com.termux/files/usr/lib/cmake/ChemicalFun/ChemicalFunConfig.cmake
-- Installing: /data/data/com.termux/files/usr/lib/cmake/ChemicalFun/ChemicalFunConfigVersion.cmake
-- Installing: /data/data/com.termux/files/usr/lib/[libChemicalFun.so](http://libchemicalfun.so/)
-- Set runtime path of "/data/data/com.termux/files/usr/lib/[libChemicalFun.so](http://libchemicalfun.so/)" to ""
-- Installing: /data/data/com.termux/files/usr/include/ChemicalFun
-- Installing: /data/data/com.termux/files/usr/include/ChemicalFun/FormulaParser.h
-- Installing: /data/data/com.termux/files/usr/include/ChemicalFun/FormulaParser
-- Installing: /data/data/com.termux/files/usr/include/ChemicalFun/FormulaParser/ChemicalData.h
-- Installing: /data/data/com.termux/files/usr/include/ChemicalFun/FormulaParser/ChemicalFormulaParser.h
-- Installing: /data/data/com.termux/files/usr/include/ChemicalFun/FormulaParser/MoietyParser.h
-- Installing: /data/data/com.termux/files/usr/include/ChemicalFun/ReactionsGenerator.h
-- Installing: /data/data/com.termux/files/usr/include/ChemicalFun/ReactionsGenerator
-- Installing: /data/data/com.termux/files/usr/include/ChemicalFun/ReactionsGenerator/ChemicalReactions.h
-- Installing: /data/data/com.termux/files/usr/include/ChemicalFun/ReactionsGenerator/Combiner.h
-- Installing: /data/data/com.termux/files/usr/include/ChemicalFun/ReactionsGenerator/Generator.h
-- Installing: /data/data/com.termux/files/usr/include/ChemicalFun/ReactionsGenerator/MatrixUtils.h
-- Installing: /data/data/com.termux/files/usr/include/ChemicalFun/ReactionsGenerator/Reaction.h
running install
running build
running build_py
running install_lib
creating /data/data/com.termux/files/usr/lib/python3.9/site-packages/chemicalfun
copying build/lib/chemicalfun/__init__.py -> /data/data/com.termux/files/usr/lib/python3.9/site-packages/chemicalfun
copying build/lib/chemicalfun/[PyChemicalFun.cpython-39.so](http://pychemicalfun.cpython-39.so/) -> /data/data/com.termux/files/usr/lib/python3.9/site-packages/chemicalfun
byte-compiling /data/data/com.termux/files/usr/lib/python3.9/site-packages/chemicalfun/__init__.py to __init__.cpython-39.pyc
running install_egg_info
Writing /data/data/com.termux/files/usr/lib/python3.9/site-packages/chemicalfun-0.1.4-py3.9.egg-info

Running under python throws error, but shows installed

~ $ pip list | grep chemical
chemicalfun          0.1.4
~ $ python -c "import chemicalfun; print(chemicalfun.__version__)"                                 Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/data/data/com.termux/files/usr/lib/python3.9/site-packages/chemicalfun/__init__.py", line 1, in <module>
    from chemicalfun.PyChemicalFun import *
ImportError: dlopen failed: cannot locate symbol "_Py_FalseStruct" referenced by "/data/data/com.termux/files/usr/lib/python3.9/site-packages/chemicalfun/PyChemicalFun.cpython-39.so"...
gdmiron commented 2 years ago

@defencedog i have yet to see what could be the issue. Something with the python packaging step maybe. Do you have any idea where to look. I am not an expert in this.

gdmiron commented 2 years ago

@defencedog There are some new fixes in chemicalfun related to linking to spdlog. https://bitbucket.org/gems4/chemicalfun/pull-requests/8 - see if chemical fun now works for you?

defencedog commented 2 years ago

make.log.txt install.log.txt cmake.log.txt

Its builds OK but when importing in python it fails. I think its a problem specific to Android platform. Perhaps other users can lend hand in debugging

Python 3.9.13 (main, Jul  5 2022, 04:09:08)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import chemicalfun as cf
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 import chemicalfun as cf

File /data/data/com.termux/files/usr/lib/python3.9/site-packages/chemicalfun/__init__.py:1, in <module>
----> 1 from chemicalfun.PyChemicalFun import *

ImportError: dlopen failed: cannot locate symbol "_Py_FalseStruct" referenced by "/data/data/com.termux/files/usr/lib/python3.9/site-packages/chemicalfun/PyChemicalFun.cpython-39.so"...
defencedog commented 2 years ago

@gdmiron On Android I uninstalled libspdlog which provided necessary libspdlog.so I compiled spdlog using git. This will produce static library libspdlog.a instead of .so

Before building edit CMakeLists.txt & make this switch ON option(SPDLOG_BUILD_PIC "Build position independent code (-fPIC)" OFF) or else you will receive such errors while building chemicalfun (git version as well)

ld.lld: error: relocation R_AARCH64_ADD_ABS_LO12_NC cannot be used against symbol 'spdlog::details::registry::~registry()'; recompile with -fPIC
>>> defined in /data/data/com.termux/files/usr/lib/libspdlog.a(spdlog.cpp.o)
>>> referenced by registry-inl.h:286 (/data/data/com.termux/files/home/spdlog/include/spdlog/details/registry-inl.h:286)
>>>               spdlog.cpp.o:(spdlog::dump_backtrace()) in archive /data/data/com.termux/files/usr/lib/libspdlog.a

https://github.com/gabime/spdlog/blob/v1.x/CMakeLists.txt#L65

Build command for spdlog: cmake .. -DCMAKE_INSTALL_PREFIX=$PREFIX Build command for chemicalfun: export LDFLAGS=-lpython3.9 && MATHLIB=m cmake .. -DCMAKE_INSTALL_PREFIX=$PREFIX

gdmiron commented 1 year ago

Hi @defencedog, I recently made an update to chemicalfun trying to fix the link with spdlog. Now uses spdlog=1.11.0 and external fmt=9.1.0. Hopefully this fixes all these linking problems. You can try to recompile chemicalfun using spdlog=1.11.0 and external fmt=9.1.0 - master branch https://bitbucket.org/gems4/chemicalfun/src/master/ . I am currently updating ThermoFun with latest changes.