# Undefined symbol error during importing dolfinx

**URL:** <https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195>\
**Category:** installation\
**Created:** [December 1, 2021, 5:46pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195 "2021-12-01T17:46:52Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ekrem\_Ekici](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@Ekrem\_Ekici](https://fenicsproject.discourse.group/u/Ekrem_Ekici)\
**Post date:** [December 1, 2021, 5:46pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/1 "2021-12-01T17:46:52Z")

</div>

Hi,

I installed all the libraries(basix, ffcx, ufl, petsc and slepc) and they are working very well. But when I want to import dolfinx, it is giving this error;

```auto
Python 3.8.10 (default, Sep 28 2021, 16:10:42) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dolfinx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages/dolfinx/ __init__.py", line 31, in <module>
    from dolfinx.cpp import __version__
ImportError: /home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages/dolfinx/cpp.cpython-38-x86_64-
linux-gnu.so: undefined symbol: 
_ZN7dolfinx3fem18create_matrix_nestERKSt6vectorIS1_IPKNS0_4FormIdEESaIS5_EESaIS7_EERKS1_IS1_INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaISH_EESaISJ_EE

```

I am using ubuntu 20.04. I checked this [question](https://fenicsproject.discourse.group/t/dolfinx-install/6831) but it didn’t help. I have installed last version of libraries.

Can you please guide me about how to fix this error?

---

<div class="post-metadata">

**Author:** ![dparsons](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dparsons](https://fenicsproject.discourse.group/u/dparsons)\
**Post date:** [December 2, 2021, 2:55pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/2 "2021-12-02T14:55:57Z")

</div>

It says you’re using a local installation of dolfinx from /home/ekrem/Development/Fenicsx/dolfinx-complex, not the ubuntu package. I guess you’ve made your own local build? In that case you’ll need to make sure your local path is included in your python path, `PYTHONPATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages`. You’ll probably need to do something similar with LD\_LIBRARY\_PATH so the linker can find your libdolfinx.so libraries.

---

<div class="post-metadata">

**Author:** ![Ekrem\_Ekici](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@Ekrem\_Ekici](https://fenicsproject.discourse.group/u/Ekrem_Ekici)\
**Post date:** [December 2, 2021, 5:06pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/3 "2021-12-02T17:06:21Z")

</div>

Thanks for your reply. I have built dolfinx from source. The real build works fine. But, I need complex build. Here is the script I am using for environment variables;

```auto
export PKG_CONFIG_PATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/pkgconfig:$PKG_CONFIG_PATH
export PETSC_ARCH=linux-gnu-complex-32
export PYTHONPATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages:$PYTHONPATH
export LD_LIBRARY_PATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib:$LD_LIBRARY_PATH

```

By the way, do we have complex build in conda environment for Ubuntu 20.04?

---

<div class="post-metadata">

**Author:** ![dparsons](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dparsons](https://fenicsproject.discourse.group/u/dparsons)\
**Post date:** [December 2, 2021, 6:15pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/4 "2021-12-02T18:15:11Z")

</div>

You’ve got PETSC\_ARCH set there. Have you tried setting PETSC\_DIR instead?

> [@Ekrem\_Ekici](#):
>
> By the way, do we have complex build in conda environment for Ubuntu 20.04?

I’m not sure about conda. I assume you don’t have admin access so as to just install the Ubuntu packages?

---

<div class="post-metadata">

**Author:** ![Ekrem\_Ekici](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@Ekrem\_Ekici](https://fenicsproject.discourse.group/u/Ekrem_Ekici)\
**Post date:** [December 2, 2021, 9:33pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/5 "2021-12-02T21:33:51Z")

</div>

I have tried the PETSC\_DIR and it still persists the same error. I have upgraded my cmake during PETSc installation. Does that effect the complex dolfinx? Very interesting that the real build works like a charm…

---

<div class="post-metadata">

**Author:** ![dparsons](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dparsons](https://fenicsproject.discourse.group/u/dparsons)\
**Post date:** [December 2, 2021, 11:56pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/6 "2021-12-02T23:56:30Z")

</div>

If real build is working then it’s almost certainly something to do with PETSC\_DIR. What value did you use?

---

<div class="post-metadata">

**Author:** ![Ekrem\_Ekici](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@Ekrem\_Ekici](https://fenicsproject.discourse.group/u/Ekrem_Ekici)\
**Post date:** [December 6, 2021, 1:01pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/7 "2021-12-06T13:01:13Z")

</div>

I am not specifying the PETSC\_DIR? I have installed dolfinx to virtual environment. First, I am activating venv by just sourcing;

```auto
source /home/ekrem/Development/Fenicsx/dolfinx/bin/activate 

```

Then activating complex-mode;

```auto
export PKG_CONFIG_PATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/pkgconfig:$PKG_CONFIG_PATH
export PETSC_ARCH=linux-gnu-complex-32
export PYTHONPATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages:$PYTHONPATH
export LD_LIBRARY_PATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib:$LD_LIBRARY_PATH

```

My real mode script has exact same procedure with the one above;

```auto
export PKG_CONFIG_PATH=/home/ekrem/Development/Fenicsx/dolfinx-real/lib/pkgconfig:$PKG_CONFIG_PATH
export PETSC_ARCH=linux-gnu-real-32
export PYTHONPATH=/home/ekrem/Development/Fenicsx/dolfinx-real/lib/python3.8/dist-packages:$PYTHONPATH
export LD_LIBRARY_PATH=/home/ekrem/Development/Fenicsx/dolfinx-real/lib:$LD_LIBRARY_PATH

```

What to do with PETSC\_DIR?

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [December 6, 2021, 1:16pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/8 "2021-12-06T13:16:23Z")

</div>

> [@Ekrem\_Ekici](#):
>
> `export PYTHONPATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages:$PYTHONPATH`

Could you produce the output of `echo $PYTHONPATH` and `echo $LD_LIBRARY_PATH` when you try to run this in your complex mode?

Most likely you will find that both the real and complex mode is present in these paths.

---

<div class="post-metadata">

**Author:** ![Ekrem\_Ekici](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@Ekrem\_Ekici](https://fenicsproject.discourse.group/u/Ekrem_Ekici)\
**Post date:** [December 6, 2021, 2:01pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/9 "2021-12-06T14:01:59Z")

</div>

> [@Ekrem\_Ekici](#):
>
> export PYTHONPATH=/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages:$PYTHONPATH

My python path is;

```auto
/home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages:

```

And LD\_LIBRARY\_PATH is;

```auto
/home/ekrem/Development/Fenicsx/dolfinx-complex/lib:

```

---

<div class="post-metadata">

**Author:** ![dparsons](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dparsons](https://fenicsproject.discourse.group/u/dparsons)\
**Post date:** [December 6, 2021, 2:04pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/10 "2021-12-06T14:04:54Z")

</div>

If you’re building dolfinx from source, then you need to set PETSC\_DIR to the directory containing the petsc installation that you want to use. If you don’t set it, then the dolfinx config scripts will find the default petsc, which evidently is petsc-real. You’ll need to set it to the location of your petsc-complex installation to get dolfinx building with complex numbers.

---

<div class="post-metadata">

**Author:** ![Ekrem\_Ekici](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@Ekrem\_Ekici](https://fenicsproject.discourse.group/u/Ekrem_Ekici)\
**Post date:** [December 6, 2021, 2:07pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/11 "2021-12-06T14:07:20Z")

</div>

My complex PETSC is working perfectly fine without setting PETSC\_DIR directly;

```auto
>>> from petsc4py import PETSc
>>> print(PETSc.ScalarType)
<class 'numpy.complex128'>
>>> from slepc4py import SLEPc
>>> print(SLEPc.ScalarType)
<class 'numpy.complex128'>

```

---

<div class="post-metadata">

**Author:** ![dparsons](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dparsons](https://fenicsproject.discourse.group/u/dparsons)\
**Post date:** [December 6, 2021, 2:15pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/12 "2021-12-06T14:15:48Z")

</div>

That’s using python. dolfinx does not use python or petsc4py to configure its build.

---

<div class="post-metadata">

**Author:** ![Ekrem\_Ekici](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@Ekrem\_Ekici](https://fenicsproject.discourse.group/u/Ekrem_Ekici)\
**Post date:** [December 6, 2021, 2:35pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/13 "2021-12-06T14:35:18Z")

</div>

I was wrong, thanks. I was exporting all the environment variables in a script.And script has PETSC\_DIR as;

```auto
export GMSH_VERSION=4_8_4
export HDF5_SERIES=1.12
export HDF5_PATCH=1
export PYBIND11_VERSION=2.8.1
export PETSC_VERSION=3.16.1
export SLEPC_VERSION=3.16.0
export ADIOS2_VERSION=2.7.1
export PYVISTA_VERSION=0.32.1
export NUMPY_VERSION=1.20.3
export KAHIP_VERSION=3.12
export XTENSOR_VERSION=0.24.0
export XTL_VERSION=0.7.3

export MPICH_VERSION=3.4.2
export OPENMPI_SERIES=4.1
export OPENMPI_PATCH=1

export PETSC_SLEPC_OPTFLAGS="-O2"
# PETSc and SLEPc number of make processes (--with-make-np)
export PETSC_SLEPC_MAKE_NP=2
# Turn on PETSc and SLEPc debugging. "yes" or "no".
export PETSC_SLEPC_DEBUGGING="no"

# MPI variant. "mpich" or "openmpi".
export MPI="mpich"
export MPICH_CONFIGURE_OPTIONS="--with-device=ch3"

# Number of build threads to use with make
export BUILD_NP=2

export OPENBLAS_NUM_THREADS=1 
export OPENBLAS_VERBOSE=0

export PETSC_DIR=/home/ekrem/Development/Fenicsx/petsc 
export DOLFINX_CMAKE_BUILD_TYPE="RelWithDebInfo"

export SLEPC_DIR=/home/ekrem/Development/Fenicsx/slepc
export ADIOS2_DIR=/home/ekrem/Development/Fenicsx/adios2-v2.7.1/cmake
#export DOLFINX_DIR=/home/ekrem/Development/Fenicsx/dolfinx-real/lib/cmake/dolfinx
export COMPLEX_PREFIX=/home/ekrem/Development/Fenicsx/dolfinx-complex

```

For building it I am using;

```auto
mkdir -p build-complex
cd build-complex
PETSC_ARCH=linux-gnu-complex-32 cmake -G Ninja -DCMAKE_INSTALL_PREFIX=$COMPLEX_PREFIX -DCMAKE_BUILD_TYPE=${DOLFINX_CMAKE_BUILD_TYPE} -DCMAKE_CXX_FLAGS=${DOLFIN_CMAKE_CXX_FLAGS} ../cpp
ninja install
source /home/ekrem/Development/Fenicsx/dolfinx-complex/lib/dolfinx/dolfinx.conf
cd ../python
CXXFLAGS=${DOLFINX_CMAKE_CXX_FLAGS} PETSC_ARCH=linux-gnu-complex-32 pip3 install --target /home/ekrem/Development/Fenicsx/dolfinx-complex/lib/python3.8/dist-packages --no-dependencies .

```

I am still having the same error.

---

<div class="post-metadata">

**Author:** ![dparsons](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dparsons](https://fenicsproject.discourse.group/u/dparsons)\
**Post date:** [December 6, 2021, 4:26pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/14 "2021-12-06T16:26:35Z")

</div>

`/home/ekrem/Development/Fenicsx/petsc` is the location of your petsc-real installation, is that correct?

---

<div class="post-metadata">

**Author:** ![Ekrem\_Ekici](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@Ekrem\_Ekici](https://fenicsproject.discourse.group/u/Ekrem_Ekici)\
**Post date:** [December 6, 2021, 4:27pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/15 "2021-12-06T16:27:41Z")

</div>

Yes it is the location of my petsc installation. In that folder, I have;

```auto
ekrem@ekrem-TP501UB:~/Development/Fenicsx/petsc$ ls 
CODE_OF_CONDUCT.md gmakefile linux-gnu-complex-64 setup.py
config gmakefile.test linux-gnu-real-32 share
configtest.mod GNUmakefile linux-gnu-real-64 src
configure include makefile systems
configure.log interfaces make.log TAGS
configure.log.bkp lib petscdir.mk
CONTRIBUTING LICENSE PKG-INFO
CTAGS linux-gnu-complex-32 RDict.log

```

---

<div class="post-metadata">

**Author:** ![dparsons](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dparsons](https://fenicsproject.discourse.group/u/dparsons)\
**Post date:** [December 6, 2021, 5:30pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/16 "2021-12-06T17:30:28Z")

</div>

Not exactly. `~/Development/Fenicsx/petsc` is a PETSc source dir, not an installation as such. You’ve got 4 builds there, the `linux-gnu-*` variants. You need PETSC\_DIR to point to one of them.

To be fair, your combination of PETSC\_DIR and PETSC\_ARCH ought to work. But since it’s not, you have to try other permutations (like setting PETSC\_DIR and _not_ setting PETSC\_ARCH). What is inside the linux-gnu-\* dirs? Does the linux-gnu-complex-32 subdir contain a full build of petsc-complex? What is returned by

```auto
grep PETSC_SCALAR ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscvariables

```

or by

```auto
grep PETSC_SCALAR ${PETSC_DIR}/lib/petsc/conf/petscvariables

```

with PETSC\_DIR set as needed (with or without PETSC\_ARCH)

What did cmake report during the configuration step with respect to PETSc?

---

<div class="post-metadata">

**Author:** ![Ekrem\_Ekici](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@Ekrem\_Ekici](https://fenicsproject.discourse.group/u/Ekrem_Ekici)\
**Post date:** [December 6, 2021, 5:45pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/17 "2021-12-06T17:45:14Z")

</div>

> [@dparsons](#):
>
> `grep PETSC_SCALAR ${PETSC_DIR}/lib/petsc/conf/petscvariables`

Thanks for your responses. Actually I followed all the steps in [here.](https://github.com/FEniCS/dolfinx/blob/fc84adbce7903aef1d3e37f0a556727fb24705df/docker/Dockerfile#L247-L332)

The first command gives;

```auto
(dolfinx) ekrem@ekrem-TP501UB:~/Development/Fenicsx/petsc$ grep PETSC_SCALAR ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscvariables
PETSC_SCALAR = complex
PETSC_SCALAR_SIZE = 64

```

I think these installations are seperate installations for PETSC variables. By setting PETSC\_ARCH and PETSC\_DIR, they are just flagging which scalars will be used during petsc use.

I’m not so good with cmake commands, builds and outputs. Can you recommend and other way of installing dolfinx with complex scalars other than the above link that I have provided?

---

<div class="post-metadata">

**Author:** ![dparsons](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dparsons](https://fenicsproject.discourse.group/u/dparsons)\
**Post date:** [December 6, 2021, 6:05pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/18 "2021-12-06T18:05:20Z")

</div>

Focusing on the original error, python seems to be finding the complex module. What it’s missing is the libdolfinx.so library that contains the missing symbol. What is your current value of LD\_LIBRARY\_PATH when you run python? Your undefined symbol does not contain “complex” which is odd since it does on my system. Again, what did cmake report when you ran it?

> [@Ekrem\_Ekici](#):
>
> Can you recommend and other way of installing dolfinx with complex scalars other than the above link that I have provided?

Do you have admin rights to your machine? Can you install ubuntu packages?

---

<div class="post-metadata">

**Author:** ![Ekrem\_Ekici](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@Ekrem\_Ekici](https://fenicsproject.discourse.group/u/Ekrem_Ekici)\
**Post date:** [December 6, 2021, 6:09pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/19 "2021-12-06T18:09:34Z")

</div>

The LD\_LIBRARY\_PATH returns;

```auto
(dolfinx) ekrem@ekrem-TP501UB:~/Development/Fenicsx$ echo $LD_LIBRARY_PATH 
/home/ekrem/Development/Fenicsx/dolfinx-complex/lib:

```

What cmake report does? Where should I run it?

I can install ubuntu packages, but for some packages, I need additional features which are not exist in v0.3.0. So I need to upgrade them to dev-version for each library (basix, dolfinx…)

---

<div class="post-metadata">

**Author:** ![dparsons](https://avatars.discourse-cdn.com/v4/letter/d/5e9695/32.png) [@dparsons](https://fenicsproject.discourse.group/u/dparsons)\
**Post date:** [December 6, 2021, 6:42pm UTC](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195/20 "2021-12-06T18:42:58Z")

</div>

When you ran cmake, what did it output?

The next thing for you to check is your lib dir,

```auto
$ ls -l /home/ekrem/Development/Fenicsx/dolfinx-complex/lib
$ nm -D /home/ekrem/Development/Fenicsx/dolfinx-complex/lib/libdolfinx*.so | grep create_matrix_nest

```

[Next page](https://fenicsproject.discourse.group/t/undefined-symbol-error-during-importing-dolfinx/7195.md?page=2)
