# How to compile c++ dolfinx code?

**URL:** <https://fenicsproject.discourse.group/t/how-to-compile-c-dolfinx-code/10201>\
**Category:** dolfinx\
**Created:** [January 19, 2023, 10:57pm UTC](https://fenicsproject.discourse.group/t/how-to-compile-c-dolfinx-code/10201 "2023-01-19T22:57:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hamedZaker](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/hamedzaker/32/4563_2.png) [@hamedZaker](https://fenicsproject.discourse.group/u/hamedZaker)\
**Post date:** [January 19, 2023, 10:57pm UTC](https://fenicsproject.discourse.group/t/how-to-compile-c-dolfinx-code/10201/1 "2023-01-19T22:57:53Z")

</div>

I have installed dolfinx using ubuntu PPA

```auto
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](https://github.com/FEniCS/dolfinx/tree/main/cpp/demo/poisson)?

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/a/a5da841a9eaad4e2743c1ebd2d97db68503277fa.png)

When I do

```auto
cmake .
make

```

I get this error

```auto
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

```

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/4/4bbc02ecce0fe1e7ada04bdb7af52a30ebb69b16.png)

---

<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:** [January 20, 2023, 1:35pm UTC](https://fenicsproject.discourse.group/t/how-to-compile-c-dolfinx-code/10201/2 "2023-01-20T13:35:04Z")

</div>

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:

```bash
 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

```

```bash
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 

```

---

<div class="post-metadata">

**Author:** ![hamedZaker](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/hamedzaker/32/4563_2.png) [@hamedZaker](https://fenicsproject.discourse.group/u/hamedZaker)\
**Post date:** [January 20, 2023, 2:17pm UTC](https://fenicsproject.discourse.group/t/how-to-compile-c-dolfinx-code/10201/3 "2023-01-20T14:17:03Z")

</div>

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?

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/2/25c2732f5b4065647be3b115acc9ee46e5f1d607.png)

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

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/6/6a5629a478724cda69437236db3747d7c1b3d2aa.png)

```auto

```

---

<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:** [January 20, 2023, 2:53pm UTC](https://fenicsproject.discourse.group/t/how-to-compile-c-dolfinx-code/10201/4 "2023-01-20T14:53:14Z")

</div>

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](https://fenicsproject.discourse.group/t/install-fenics-via-wsl-for-ubuntu-20-04/3288/10)  
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)
