python - ortools/linear_solver/_pywraplp.so: undefined symbol

144 views
Skip to first unread message

김민

unread,
Sep 20, 2021, 3:52:00 AM9/20/21
to or-tools-discuss
Hi 

My system is using OrTools, installed by following the steps in this page https://developers.google.com/optimization/install/python/linux.

I encountered this error. I tried to solve it many days, but I cannot find the solution.
Traceback (most recent call last):
  File "libopt/solve.py", line 9, in libopt.solve
  File "/root/.local/lib/python3.6/site-packages/ortools/linear_solver/pywraplp.py", line 13, in <module>
    from . import _pywraplp
ImportError: /root/.local/lib/python3.6/site-packages/ortools/linear_solver/_pywraplp.so: undefined symbol: _ZN19operations_research22ExportModelAsMpsFormatERKNS_12MPModelProtoERKNS_20MPModelExportOptionsE

Here is our system setting.
------- Dockerfile ----------

FROM centos:8
...
RUN dnf -y groupinstall 'Development Tools'
RUN yum -y install pkgconfig
...
RUN yum install -y python36-devel python3-wheel
--------------------------------------
Golang code is calling a shared file (xxx.so: our program calling ortools, written in python), via c file by using cgo.

// #cgo pkg-config: python3
// #cgo CFLAGS : -I./ -I/usr/include/python3.6m
// #cgo LDFLAGS: -L/usr/local/lib64/python3.6/site-packages/ortools/linear_solver -L${SRCDIR}/lib/model -lmodelpython -L${SRCDIR}/lib/libopt -loptimisationpython -L${SRCDIR}/lib -lcython -L/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu -L/usr/lib -lpython3.6m -lpthread -ldl -lutil -lm

* When I call the xxx.so file, called from python code, it was working properly.
but if we call xxx.so file from c code, then it returns the above error.
------------------------------------------
I found similar issues.
https://groups.google.com/g/or-tools-discuss/c/YtXsfIJvK04/m/mhNNUuPs2pIJ

Did anyone encounter similar issue, and managed to solve it? 
Appreciated your help.

Thank you.
Regards,
Min

Mizux Seiha

unread,
Sep 20, 2021, 4:56:06 AM9/20/21
to or-tools-discuss
0. For the record
c++filt _ZN19operations_research22ExportModelAsMpsFormatERKNS_12MPModelProtoERKNS_20MPModelExportOptionsE
operations_research::ExportModelAsMpsFormat(operations_research::MPModelProto const&, operations_research::MPModelExportOptions const&)

1. Did you try the LD_PRELOAD trick to load libortools.so ?
should be located in /usr/local/lib64/python3.6/site-packages/ortools/.lib/libortools.so and/or (see 3) /usr/local/lib64/python3.6/site-packages/ortools/.lib/libortools.so

2. If you `ldd /root/.local/lib/python3.6/site-packages/ortools/linear_solver/_pywraplp.so` what do you see 

3. in your trace we can see `ImportError: /root/.local/lib/python3.6/site-packages/ortools/linear_solver/_pywraplp.so` aka ortools is installed in the user root site-package BUT in your cgo LDFLAGS we can see `cgo LDFLAGS: -L/usr/local/lib64/python3.6/site-packages/ortools/linear_solve` aka you are looking for ortools as a pip system wide install
-> this may explain your issue...

4. "When I call the xxx.so file, called from python code, it was working properly." don't get it who is the "i" and what is the "xxx.so"... Did you mean when I test using: python3.6 -c "from ortools.linear_solver import pywraplp" ?

김민

unread,
Sep 20, 2021, 5:38:55 AM9/20/21
to or-tools-discuss
Thank you very much for the answer.

#3 I managed to set it up, but it still gives the error.
Screenshot 2021-09-20 at 6.23.27 PM.png

#2 I typed this command "ldd /usr/local/lib64/python3.6/site-packages/ortools/linear_solver/_pywraplp.so", here is the output.
Screenshot 2021-09-20 at 6.30.10 PM.png

#4. If I type "from ortools.linear_solver import pywraplp", there is no error. 
Screenshot 2021-09-20 at 6.33.40 PM.png 
 1) I created a shared library from python code, which calls OrTools. 
 2) Call this python library from Python code -> It was working. 
 3) Call this python library from C++ code -> it was not working, with the error I listed out.

Look forward for the new answers.

Thank you.
Regards,
Min
Reply all
Reply to author
Forward
0 new messages