2

I'm trying to run MIT MEEP on ubuntu through its C++ lib but I've been widely unsuccessful. I have meep and g++ installed properly. I can run Scheme ctrl file but not the c++ libs.

I am trying the simple code from MEEP c++ tutorial. The meep.hpp is located where I have given. I am new to c++.

Could anyone give me a hint of what can be wrong?

These are the first lines of errors I get:

Building target: test2
Invoking: GCC C++ Linker
g++  -o "test2"  ./src/test2.o   
./src/test2.o: In function `main':
/home/mad/clipse_workspace/test2/Debug/../src/test2.cpp:20: undefined reference to `meep::initialize::initialize(int&, char**&)'
/home/mad/clipse_workspace/test2/Debug/../src/test2.cpp:22: undefined reference to `meep::vol2d(double, double, double)'

Here is the code I run:

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

#include </usr/include/meep/meep.hpp>
using namespace meep;
using namespace std;

double eps(const vec &p);

int main(int argc, char **argv) {
  initialize mpi(argc, argv); // do this even for non-MPI Meep
  double resolution = 10; // pixels per distance
  grid_volume v = vol2d(5,10, resolution); // 5x10 2d cell
  structure s(v, eps, pml(1.0));
  fields f(&s);

  f.output_hdf5(Dielectric, v.surroundings());

  double freq = 0.3, fwidth = 0.1;
  gaussian_src_time src(freq, fwidth);
  f.add_point_source(Ey, src, vec(1.1, 2.3));
  while (f.time() < f.last_source_time()) {
    f.step();
  }

  f.output_hdf5(Hz, v.surroundings());

  return 0;
}

double eps(const vec &p) {
  if (p.x() < 2 && p.y() < 3)
  return 12.0;
  return 1.0;
} 
hyperbull
  • 45
  • 4

1 Answers1

3

You have to link the MEEP library. I compiled your app like this:

g++ -o test2 test2.cpp -lmeep

MEEP development files can be installed like this on Ubuntu:

sudo apt-get install libmeep-dev

Also modify the include statement like this now:

#include <meep.hpp>

I tested this on Ubuntu 15.10 and your app worked fine.

juzzlin
  • 45,029
  • 5
  • 38
  • 50
  • yes ... that works. Where can I learn what 'you have to link the meep library' mean? Also I am still unable to run the code through eclipse IDE. That might need this linking as well. Am I right? – hyperbull Jan 13 '16 at 21:14
  • Yes, you're right. Eclipse (and all other IDEs) just run these same commands behind the scenes. In general the header file that you include contains only declarations of classes, functions etc, but the actual implementations are in source files (.cpp) or in libraries (.a, .so). You might want to google "c++ libraries on linux" or something like that. I also advice you to abandon Eclipse and use Qt Creator (and qmake) for C++ development. – juzzlin Jan 13 '16 at 21:58