C++ 编译c++;使用g+的meep代码+;

C++ 编译c++;使用g+的meep代码+;,c++,linux,ubuntu,meep,C++,Linux,Ubuntu,Meep,这是我第一次用Stackoverflow提问。我一直在寻找解决方案,使用C++编译Ubuntu中的C++代码,找到了很多相关的内容,但是没有直接回答我的问题…我的目标是能够在C++中创建控制文件而不是方案,但是当我在Ubuntu终端编译时,它找不到MEEP .HPP文件。到目前为止,我已经使用apt get安装了meep,并且相信我已经拥有了所有必需的库。。。以下是我用作测试的代码,以及我尝试过的命令: #include <meep.hpp> using namespace std

这是我第一次用Stackoverflow提问。我一直在寻找解决方案,使用C++编译Ubuntu中的C++代码,找到了很多相关的内容,但是没有直接回答我的问题…我的目标是能够在C++中创建控制文件而不是方案,但是当我在Ubuntu终端编译时,它找不到MEEP .HPP文件。到目前为止,我已经使用apt get安装了meep,并且相信我已经拥有了所有必需的库。。。以下是我用作测试的代码,以及我尝试过的命令:

#include <meep.hpp>

using namespace std;
using namespace meep;

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

int main(int argc, char **argv) {
  initialize mpi(argc, argv); // do this even for non-MPI Meep
  double resolution = 20; // 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;
}
或者如其他线程中所述:

g++ -o FirstTest FirstTest.cpp -lmeep
如果有人能给我指出正确的方向,我将不胜感激!我对linux还是很陌生

正如在下面的评论中提到的,我最近安装了libmeep dev,现在获得了以下信息

/tmp/ccBM5Uuc.o: In function `main':
FirstTest.cpp:(.text+0xa6): undefined reference to `meep::initialize::initialize(int&, char**&)'
FirstTest.cpp:(.text+0x10e): undefined reference to `meep::vol2d(double, double, double)'
FirstTest.cpp:(.text+0x11d): undefined reference to `meep::identity()'
FirstTest.cpp:(.text+0x134): undefined reference to `meep::pml(double)'
FirstTest.cpp:(.text+0x1a1): undefined reference to `meep::structure::structure(meep::grid_volume const&, double (*)(meep::vec const&), meep::boundary_region const&, meep::symmetry const&, int, double, bool, double, int)'
FirstTest.cpp:(.text+0x1bf): undefined reference to `meep::symmetry::~symmetry()'
FirstTest.cpp:(.text+0x1e7): undefined reference to `meep::fields::fields(meep::structure*, double, bool, double, bool)'
FirstTest.cpp:(.text+0x200): undefined reference to `meep::grid_volume::surroundings() const'
FirstTest.cpp:(.text+0x234): undefined reference to `meep::fields::output_hdf5(meep::component, meep::volume const&, meep::h5file*, bool, bool, char const*)'
FirstTest.cpp:(.text+0x2b9): undefined reference to `meep::gaussian_src_time::gaussian_src_time(double, double, double)'
FirstTest.cpp:(.text+0x363): undefined reference to `meep::fields::add_point_source(meep::component, meep::src_time const&, meep::vec const&, std::complex<double>)'
FirstTest.cpp:(.text+0x383): undefined reference to `meep::fields::step()'
FirstTest.cpp:(.text+0x3a9): undefined reference to `meep::fields::last_source_time()'
FirstTest.cpp:(.text+0x3d1): undefined reference to `meep::grid_volume::surroundings() const'
FirstTest.cpp:(.text+0x405): undefined reference to `meep::fields::output_hdf5(meep::component, meep::volume const&, meep::h5file*, bool, bool, char const*)'
FirstTest.cpp:(.text+0x437): undefined reference to `meep::fields::~fields()'
FirstTest.cpp:(.text+0x446): undefined reference to `meep::structure::~structure()'
FirstTest.cpp:(.text+0x464): undefined reference to `meep::initialize::~initialize()'
FirstTest.cpp:(.text+0x491): undefined reference to `meep::structure::~structure()'
FirstTest.cpp:(.text+0x4a5): undefined reference to `meep::symmetry::~symmetry()'
FirstTest.cpp:(.text+0x4bc): undefined reference to `meep::structure::~structure()'
FirstTest.cpp:(.text+0x520): undefined reference to `meep::fields::~fields()'
FirstTest.cpp:(.text+0x534): undefined reference to `meep::structure::~structure()'
FirstTest.cpp:(.text+0x55c): undefined reference to `meep::initialize::~initialize()'
/tmp/ccBM5Uuc.o: In function `meep::gaussian_src_time::~gaussian_src_time()':
FirstTest.cpp:(.text._ZN4meep17gaussian_src_timeD2Ev[_ZN4meep17gaussian_src_timeD5Ev]+0x13): undefined reference to `vtable for meep::gaussian_src_time'
collect2: error: ld returned 1 exit status
/tmp/ccBM5Uuc.o:在函数'main'中:
FirstTest.cpp:(.text+0xa6):对“meep::initialize::initialize(int&,char**&)”的未定义引用
FirstTest.cpp:(.text+0x10e):对“meep::vol2d(double,double,double)”的未定义引用
FirstTest.cpp:(.text+0x11d):对'meep::identity()的未定义引用
FirstTest.cpp:(.text+0x134):对“meep::pml(double)”的未定义引用
FirstTest.cpp:(.text+0x1a1):对“meep::structure::structure(meep::grid_volume const&,double(*)(meep::vec const&),meep::boundary_region const&,meep::symmetry const&,int,double,bool,double,int)”的未定义引用
FirstTest.cpp:(.text+0x1bf):对“meep::symmetry::~symmetry()”的未定义引用
FirstTest.cpp:(.text+0x1e7):对“meep::fields::fields(meep::structure*,double,bool,double,bool)”的未定义引用
FirstTest.cpp:(.text+0x200):对'meep::grid\u volume::environment()const'的未定义引用
FirstTest.cpp:(.text+0x234):对“meep::fields::output”的未定义引用(meep::component,meep::volume const&,meep::h5file*,bool,bool,char const*)”
FirstTest.cpp:(.text+0x2b9):对“meep::gaussian_src_time::gaussian_src_time(double,double,double)”的未定义引用
FirstTest.cpp:(.text+0x363):对“meep::fields::add_point_source(meep::component,meep::src_time const&,meep::vec const&,std::complex)”的未定义引用
FirstTest.cpp:(.text+0x383):对'meep::fields::step()的未定义引用
FirstTest.cpp:(.text+0x3a9):对“meep::fields::last_source_time()”的未定义引用
FirstTest.cpp:(.text+0x3d1):对“meep::grid\u volume::environment()const”的未定义引用
FirstTest.cpp:(.text+0x405):未定义对“meep::fields::output_hdf5(meep::component,meep::volume const&,meep::h5file*,bool,bool,char const*)”的引用
FirstTest.cpp:(.text+0x437):对“meep::fields::~fields()”的未定义引用
FirstTest.cpp:(.text+0x446):对'meep::structure::~structure()的未定义引用
FirstTest.cpp:(.text+0x464):对“meep::initialize::~initialize()”的未定义引用
FirstTest.cpp:(.text+0x491):对“meep::structure::~structure()”的未定义引用
FirstTest.cpp:(.text+0x4a5):对“meep::symmetry::~symmetry()”的未定义引用
FirstTest.cpp:(.text+0x4bc):对'meep::structure::~structure()的未定义引用
FirstTest.cpp:(.text+0x520):对“meep::fields::~fields()”的未定义引用
FirstTest.cpp:(.text+0x534):对“meep::structure::~structure()”的未定义引用
FirstTest.cpp:(.text+0x55c):对“meep::initialize::~initialize()”的未定义引用
/tmp/ccBM5Uuc.o:在函数“meep::gaussian_src_time::~gaussian_src_time()”中:
FirstTest.cpp:(.text._ZN4meep17gaussian_src_timeD2Ev[_ZN4meep17gaussian_src_timeD5Ev]+0x13):未定义对“vtable for meep::gaussian_src_time”的引用
collect2:错误:ld返回了1个退出状态

尝试指向包含目录。 看起来像这样

g++ -o FirstTest FirstTest.cpp -lmeep -I/example/include/path -L/example/lib/path

可能是
-I/usr/include-L/usr/lib


这就是您要查找的内容

您显示的命令有什么问题?运行时会出现哪些错误(如果有)?请编辑您的问题以包含该信息(复制粘贴build命令的完整输出)。。。我安装了libmeep dev,它似乎克服了我以前的错误。。。然而,我得到了不同的错误,哈哈,终端是这么说的:您显示的错误可能来自第一个命令,您实际上没有链接到库。当您在末尾添加
-lmeep
时,会发生什么?
-I/usr/include-L/usr/lib
几乎总是与默认值冗余。meep/文件夹可能位于/usr/include中当我安装meep时,我使用apt get命令。。。所以说实话我不知道meep.hpp文件在哪里,然而,我从github下载了一个版本的meep,其中有一个meep.hpp文件,我把它移到了我的ubuntu虚拟机上,并将它放在了FirstTest.cpp所在的同一个文件夹中。meep.hpp取决于meep/vec.hpp和meep/mympi.hpp。那么我该如何/怎么做才能拥有这些。。。我刚刚将meep.hpp复制到usr/incude文件夹,这导致了下一个编译错误,即它需要vec.hpp
g++ -o FirstTest FirstTest.cpp -lmeep -I/example/include/path -L/example/lib/path