#include <dolfinx.h>

Greetings all,

I am trying to install dolfinx --version 0.9.0 from source, aiming to use it as a cpp library i.e. #include <dolfinx.h>
I am using Ubuntu 22.04.2 LTS

##############################----INSTALLATION----##################################
I have followed these (self made) instructions, made from what could be found online:

  1. Install vcpkg: How to install vcpkg on Ubuntu - Followchain (check: sudo vcpkg list)

  2. [readlink -f $(which vcpkg) (/opt/vcpkg/)]

  3. Configure user settings.json:

    “cmake.configureOnOpen”: true,
    “cmake.configureSettings”: {
    “CMAKE_TOOLCHAIN_FILE”: “/opt/vcpkg/scripts/buildsystems/vcpkg.cmake”
    },

  4. Install fenicsx project (in order: ufl(4.2), ffcx(4.1, 4.2), basix(4.1 & 4.2), mpi(4.1), dolfinx(4.1 & 4.2)
    4.1 In repo of library with CMakeLists.txt
    [mkdir -p build]
    [cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=/opt/vcpkg/scripts/buildsystems/vcpkg.cmake]
    (note for dolfinx this might be needed: [cmake -B build -S . -DBasix_DIR=/usr/local/lib/cmake/basix])
    [cmake --build build]
    [sudo cmake --install build]

4.2 In repo with setup.py
[pip install .]
(note for dolfinx this is needed:
[pip install -r build-requirements.txt]
[pip install --check-build-dependencies --no-build-isolation .] )
##################################################################################

Up to this point there were no errors when building with cmake, as shown in the image attached [files].so where generated.
cmakes

However when running [g++ project.cpp -o project -I/usr/lib/x86_64-linux-gnu/openmpi/include/]
I get 2000+ compilation errors starting from:

I have searched the discourse but this issue was never discussed so I am posting it here. All help is appreciated and thank you for reading.

Compiling a C++ program that uses dolfinx requires much more compiler options than simply an additional include path to find openmpi. You certainly wouldn’t want to write your own makefile, or write the g++ command yourself: we use cmake for that. See for instance dolfinx/cpp/demo/poisson/CMakeLists.txt at main · FEniCS/dolfinx · GitHub for an example.

2 Likes

The CMakeLists.txt method did work, thank you very much.

For future reference if anyone tries the previous steps posted in the OC:

1. export LD_LIBRARY_PATH=/usr/lib:/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH

2. vcpkg install pybind11

3. Make CMakeLists.txt 
    (note: use poisson/CMakeLists.txt for reference and include [find_package(pybind11 CONFIG 
     REQUIRED)])

4. 
mkdir -p build
cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=/opt/vcpkg/scripts/buildsystems/vcpkg.cmake 
cmake --build build
sudo cmake --install build

5. Now in directory of e.g. [name_of_build].cpp_project.cpython-310-x86_64-linux-gnu.so:
	import [name_of_build]
            [name_of_build].__dir__() # check your methods are loaded