How to compile c++ dolfinx code?

I have installed dolfinx using ubuntu PPA

add-apt-repository ppa:fenics-packages/fenics 
apt update 
apt install fenicsx

and I did not have any issue for using it in python. But what should I do to compile a C++ demo of dolfinx (like this Poisson example?

When I do

cmake .
make

I get this error

AttributeError: 'BasixElement' object has no attribute '_variant'
make[2]: *** [CMakeFiles/demo_poisson.dir/build.make:62: poisson.c] Error 1
make[1]: *** [CMakeFiles/Makefile2:75: CMakeFiles/demo_poisson.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

It seems like your installation is picking up the wrong basix.

have you tried installing basix in any other way than with apt install fenicsx?

Because I cannot reproduce this on a clean ubuntu 22.04 machine:

 docker run -ti --network=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $(pwd):/root/shared -w /root/shared --rm --shm-size=512m ubuntu:22.04
apt-get update
apt-get install -y software-properties-common
add-apt-repository ppa:fenics-packages/fenics 
apt update 
apt install fenicsx
apt-get install -y git
git clone --branch v0.5.2 --single-branch https://github.com/fenics/dolfinx.git
cd dolfinx/cpp/demo/poisson
cmake .
make
./demo_poisson 
1 Like

Thank you very much! It works like this on my clean ubuntu 22.04 machine. So, I will continue with it.

But on my ubuntu 20.04, it still does not work. Do you have any idea why it is so?

Also, on my ubuntu 22, when I remove —branch v0.5.2 from the git command, I still have an error.

The ubuntu installation on ubuntu 22.04 is DOLFINx v0.5.2, and thus you need to use code compatible with that release.

On ubuntu 20.04, the latest release of DOLFINx is v0.4.1, see: Install FEniCS via WSL for Ubuntu 20.04 - #10 by dokken
Thus on ubuntu 20.04 you need to the v0.4.1 branch if you want to use apt to install the code (and not conda)

1 Like