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

Fenics in a Xcode project

+1 vote

Hello everyone,

I'd like to create a Xcode project to develop some code in C++ depending on Fenics, but I'm finding some difficulties in the linker phase. What I've done right now is this:

  1. use the hyperelasticity demo to take a look at the command line
  2. create a Xcode project
  3. create a script to generate a dummy dylib with all prerequisites
  4. link the hyperelasticity demo with the dummy

However, it won't link. It seems as the dummy library won't "pull" the other shared objects. The details of the steps above are below.

Can you help me with this?

Thanks!

hyperelasticity demo

/usr/bin/g++   -DBOOST_UBLAS_NDEBUG [...] -std=c++11    -Wno-deprecated  -O2 -g -DNDEBUG -isystem /Applications/FEniCS.app/Contents/Resources/include [...]    -o CMakeFiles/demo_hyperelasticity.dir/main.cpp.o -c /Users/sensei/Public/hyperelasticity/cpp/main.cpp

/usr/bin/g++    -std=c++11    -Wno-deprecated  -O2 -g -DNDEBUG -Wl,-search_paths_first -Wl,-headerpad_max_install_names   CMakeFiles/demo_hyperelasticity.dir/main.cpp.o  -o demo_hyperelasticity  /Applications/FEniCS.app/Contents/Resources/lib/libdolfin.1.5.0.dylib /usr/lib/libxml2.dylib [...] /Applications/FEniCS.app/Contents/Resources/lib/vtk-5.10/libvtksys.5.10.1.dylib -lobjc -lm

dummy library creation

clang++ -dynamiclib -o libfenics_dummy.dylib /Applications/FEniCS.app/Contents/Resources/lib/libdolfin.1.5.0.dylib /usr/lib/libxml2.dylib /Applications/FEniCS.app/Contents/Resources/lib/libboost_filesystem.dylib /Applications/FEniCS.app/Contents/Resources/lib/libboost_program_options.dylib [...] /Applications/FEniCS.app/Contents/Resources/lib/vtk-5.10/libvtksys.5.10.1.dylib -lobjc -lm

linker error

Undefined symbols for architecture x86_64:
  "dolfin::Expression::Expression(unsigned long)", referenced from:
      Rotation::Rotation() in main.o
      Clamp::Clamp() in main.o
  "dolfin::Expression::~Expression()", referenced from:
      Clamp::~Clamp() in main.o
      Rotation::~Rotation() in main.o
  "dolfin::Parameters::Parameters(dolfin::Parameters const&)", referenced from:
      _main in main.o
  "dolfin::Parameters::~Parameters()", referenced from:
[...]
  "typeinfo for dolfin::SubDomain", referenced from:
      typeinfo for Right in main.o
      typeinfo for Left in main.o
  "VTT for dolfin::GenericMatrix", referenced from:
      dolfin::GenericMatrix::~GenericMatrix() in main.o
  "_ompi_mpi_comm_self", referenced from:
      dolfin::uBLASMatrix<boost::numeric::ublas::compressed_matrix<double, boost::numeric::ublas::basic_row_major<unsigned long, long>, 0ul, boost::numeric::ublas::unbounded_array<unsigned long, std::__1::allocator<unsigned long> >, boost::numeric::ublas::unbounded_array<double, std::__1::allocator<double> > > >::mpi_comm() const in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
asked May 7, 2015 by senseiwa FEniCS User (2,620 points)

UPDATE

I still cannot find a decent solution to this, but a very bad hack is as follows:

  1. add every library /Applications/FEniCS.app/Contents/Resources/lib/ and the vtk-5.10 subdirectory
  2. be sure to remove all python references
  3. enjoy with a caveat: you cannot run it in Xcode

So, you can compile and link, but to run your program you must open a fenics terminal and run there.

Did you try to first open a FEniCS terminal, and then to launch Xcode from that terminal?

Or also you could create a small script (xcode4fenics.sh) that contains the following two lines:

source /Applications/FEniCS.app/Contents/Resources/share/fenics/fenics.conf
open -a Xcode

I did something similar with Eclipse and the python interface of dolfin.

1 Answer

0 votes
 
Best answer

For me it works to use Xcode just as an python editor and to compile with the FEniCS terminal for i dont really know how to add the python-related FEniCS stuff to Xcode. I guess it might be the same with c++.

answered May 13, 2015 by MaxMeier FEniCS Novice (850 points)
selected May 27, 2015 by senseiwa

Well, yes, but that won't allow me to debug and inspect the code at runtime. I don't really like to use lldb/gdb on a command line.

You're right, but the terminal will also tell you what's wrong in your code.

Then I need to stick with my ugly Xcode hack. Better than looking at the console...

Executing Xcode from a Fenics terminal does the trick, both serial and with MPI. Awesome!

What does that mean? Until now I launched Xcode and the FEniCS terminal simultaneously but I would love to hear a better solution. Xcode doesnt support FEniCS fully, at least I didnt find a way how to implement FEniCS in Xcode.

...