This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Undefined reference to 'dolfin::Mesh::Mesh(std::string)'

0 votes

Hi,

I've been working with FEniCS using Python untill now. Now I'm trying to rewrite the program in C++, but I encountered an error. My program is longer than this snippet, but gives the same error:

#include <dolfin.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <sys/types.h>
#include <sys/stat.h>

using namespace dolfin;

int main(int argc, char* argv[])
{
  std::string fileIN = "myMesh.xml";
  auto mesh = std::make_shared<Mesh>(fileIN);

  return 0;
}

I compile using command

g++ main.cpp -o main -std=c++11 -I/usr/include/eigen3 -lboost_system

This returns the following error:

/tmp/cckb47VS.o: In function `_ZN9__gnu_cxx13new_allocatorIN6dolfin4MeshEE9constructIS2_IPKcEEEvPT_DpOT0_':
main.cpp:(.text._ZN9__gnu_cxx13new_allocatorIN6dolfin4MeshEE9constructIS2_IPKcEEEvPT_DpOT0_[_ZN9__gnu_cxx13new_allocatorIN6dolfin4MeshEE9constructIS2_IPKcEEEvPT_DpOT0_]+0x6b): undefined reference to `dolfin::Mesh::Mesh(std::string)'
collect2: error: ld returned 1 exit status

I tried looking into directory /usr/include/dolfin/mesh/ and the file Mesh.h contains class Mesh
Also tried changing fileIN to fileIN.c_str() in the argument and the same error occured.
Also tried the Incompressible Navier-Stokes problem example here and it gave me even more errors.
My Dolfin version is 1.6.0

asked Jun 6, 2016 by pelcva FEniCS Novice (150 points)

1 Answer

0 votes
 
Best answer

Look at the C++ demos. Use the same approach as described there to build your C++ program.

answered Jun 6, 2016 by johannr FEniCS Expert (17,350 points)
selected Jun 6, 2016 by pelcva

Thank you very much

...