Hello everyone,
I am currently working with Fenics c++ user expressions, like the one I attach. At the beginning, this routine works, however the problem comes when I include and use a large routine created by myself, called myClass. I really prefer calling this routine than including it into the expression itself because of its size. I do not receive any error from the include statement. However, when I try to use a class from it, I get an error. Could anyone help me with this? I guess that it could be a compilation problem since fenics classes and “myClass” are probably compiled differently. In fact, I only used g++ -c myClass.h to compile it.
The c++ user expression is:
code = “”"
#include <pybind11/pybind11.h>
#include <pybind11/eigen.h>
namespace py = pybind11;
#include <dolfin/function/Expression.h>
#include <dolfin/function/Function.h>#include <myClass.h>
class secondPK : public dolfin::Expression
{
public:
secondPK(): dolfin::Expression(3)
{
}// Function for evaluating expression on each cell
void eval(Eigen::RefEigen::VectorXd values, Eigen::Ref x, const ufc::cell& cell) const override
{
myClass f(1);// Define your expression
values[0] = 0;
values[1] = 1;
values[2] = 2;
}
};PYBIND11_MODULE(SIGNATURE, m)
{
py::class_<secondPK, std::shared_ptr, dolfin::Expression> (m, “secondPK”)
.def(py::init<>());
}
“”"
For compiling, I use:
compiled_constRel = dolfin.compile_cpp_code(cpp_code=constitutive_relation,include_dirs=[‘.’, DirectoryMyClass])
And the error is:
ImportError: dlopen(/anaconda3/envs/fenicsproject/.cache/dijitso/lib/dolfin_cpp_module_1e2c4e5c7557fbe981e146298048e973.so, 2): Symbol not found: __ZN6FunclaC1Ei
Referenced from: /anaconda3/envs/fenicsproject/.cache/dijitso/lib/dolfin_cpp_module_1e2c4e5c7557fbe981e146298048e973.so
Expected in: flat namespace
in /anaconda3/envs/fenicsproject/.cache/dijitso/lib/dolfin_cpp_module_1e2c4e5c7557fbe981e146298048e973.so
Thank you very much, I will really appreciate your help.