running meep c++ basics - c++

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;
}

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.

Related

How to compile a c++ code using libtorrent?

I am testing the example code posted on the official libtorrent website (https://www.libtorrent.org/tutorial-ref.html). I pasted the code here:
#include <libtorrent/session.hpp>
#include <libtorrent/add_torrent_params.hpp>
#include <libtorrent/torrent_handle.hpp>
#include <libtorrent/magnet_uri.hpp>
int main(int argc, char const* argv[])
{
if (argc != 2) {
fprintf(stderr, "usage: %s <magnet-url>\n");
return 1;
}
lt::session ses;
lt::add_torrent_params atp = lt::parse_magnet_uri(argv[1]);
atp.save_path = "."; // save in current dir
lt::torrent_handle h = ses.add_torrent(atp);
// ...
}
I have already installed the libtorrent:
ldconfig -v | grep libtorrent
libtorrent-rasterbar.so.9 -\> libtorrent-rasterbar.so.9.0.0
I used the following command to compile the code:
g++ main.cpp -o run -ltorrent-rasterbar -lboost_filesystem-mt
However, I got errors:
main.cpp: In function 'int main(int, const char\*\*)':
main.cpp:12:3: error: 'lt' has not been declared
lt::session ses;
I also saw another solution, but it does not resolve the issue I am facing: How to compile a libtorrent(rasterbar) code ?
Does anyone know what caused this failure?

Problems with building OpenCv with Xcode. Cannot find opencv2/opencv.hpp file

I have installed OpenCv with Homebrew on my MacOs. I have added libopencv 4.0.1.dylib in Xcode. When I try to build, Xcode cannot find the files. Any suggestions?
I changed my path but still have problems.
Main code:
#include <iostream>
#include <opencv4/opencv2/opencv.hpp>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
Build settings including path:
Error messages:

Undifined reference to espeak-ng headers in Ubuntu

I have downloaded espeak-ng 1.1.49 and ./configure make make install it, and tested it by espeak --stdout "this is a test" | paplay successfully and it worked. Then I tried to use it inside my C++ code(testSpeak.cpp) that I found on the internet as you can see below:
#include <string.h>
#include <vector>
#include </usr/local/include/espeak-ng/speak_lib.h>
int samplerate; // determined by espeak, will be in Hertz (Hz)
const int buflength = 200; // passed to espeak, in milliseconds (ms)
std::vector<short> sounddata;
int SynthCallback(short *wav, int numsamples, espeak_EVENT *events) {
if (wav == NULL)
return 1; // NULL means done.
/* process your samples here, let's just gather them */
sounddata.insert(sounddata.end(), wav, wav + numsamples);
return 0; // 0 continues synthesis, 1 aborts
}
int main(int argc, char* argv[] ) {
char text[] = {"my name is espeak"};
samplerate = espeak_Initialize(AUDIO_OUTPUT_RETRIEVAL, buflength, NULL, 0);
espeak_SetSynthCallback(&SynthCallback);
espeak_SetVoiceByName("en");
unsigned int flags=espeakCHARS_AUTO | espeakENDPAUSE;
size_t size = strlen(text);
espeak_Synth(text, size + 1, 0, POS_CHARACTER, 0, flags, NULL, NULL);
espeak_Synchronize();
/* in theory sounddata holds your samples now... */
return 0;
}
But after trying to make executable by this command: g++ testSpeak.cpp -o speaks I got these error messages:
/tmp/ccR9O0vw.o: In function `main':
testSpeak.cpp:(.text+0x78): undefined reference to `espeak_Initialize'
testSpeak.cpp:(.text+0x90): undefined reference to `espeak_SetSynthCallback'
testSpeak.cpp:(.text+0x9c): undefined reference to `espeak_SetVoiceByName'
testSpeak.cpp:(.text+0xce): undefined reference to `espeak_Synth'
testSpeak.cpp:(.text+0xd2): undefined reference to `espeak_Synchronize'
collect2: error: ld returned 1 exit status
I know the problem is about linking but as I am new to Linux, don't know how can I fix it! Also I searched a lot but couldn't understand the solutions :(
I got it to compile correctly try installing
sudo apt-get install espeak-data libespeak-dev espeak-ng
your include is
#include </usr/local/include/espeak-ng/speak_lib.h>
make it
#include <espeak-ng/speak_lib.h>
your compile command is
g++ testSpeak.cpp -o speaks
try this one instead
g++ -W -o speaks myEspeak.cpp -lespeak
reference from i wouldn't compile it tough tried and it doesn't work probably an old version but with the code you provided and installing those programs and changing out your include your code will compile. I doesn't do much I would find a way to store that into a a .wav file.
http://apexlogic.net/code-bank/c-2/espeak-basic-usage-example/
when ever you compile from a shared library you need to link it with something that looks like
-lespeak

Processing png in c++ with opencv and png++

Here is link for png++ :http://savannah.nongnu.org/projects/pngpp/
What I'm doing wrong?
I installed opencv for OS X by command in terminal:"brew install opencv" and I have problems with using library png++.
#include <iostream>
#include "png++/png.hpp"
using namespace std;
int main(int argc, const char * argv[])
{
png::image< png::rgb_pixel > image("74");
for(int i=0;i<image.get_width();i++)
{
for(int j=0;j<image.get_height();j++)
{
image[i][j]=png::rgb_pixel(255-image[i][j].red, 255-image[i][j].green, 255-image[i][j].blue);
}
}
image.write("output.png");
return 0;
}
And I have next errors:
error messages
Problem was, that I install opencv with brew, which I installed on Yosemite. When I updated brew on ElCapitan and reinstalled opencv, errors disappeared.

cannot compile rinside with armadillo examples

I am trying to compile the Rarmadillo example with Rinside and I keep getting:
In file included from rinside_arma0.cpp:8:0:
/usr/local64/opt/R-2.15.2/lib/R/library/RcppArmadillo/include/RcppArmadillo.h:26:6: error: #error "The file 'Rcpp.h' should not be included. Please correct to include only 'RcppArmadillo.h'."
I googled it but I keep getting the source code per se. Any ideas ?
The code is :
// -*- c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//
// Simple example using Armadillo classes
//
// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
#include <RInside.h> // for the embedded R via RInside
#include <RcppArmadillo.h>
int main(int argc, char *argv[]) {
RInside R(argc, argv); // create an embedded R instance
std::string cmd = "diag(3)"; // create a Matrix in r
arma::mat m = Rcpp::as<arma::mat>(R.parseEval(cmd)); // parse, eval + return result
std::cout << m << std::endl; // and use Armadillo i/o
exit(0);
}
and compiled it using:
g++ -I/usr/local64/opt/R-2.15.2/lib/R/include -I/usr/local64/opt/R-2.15.2/lib/R/library/Rcpp/include -I"/usr/local64/opt/R-2.15.2/lib/R/library/RcppArmadillo/include" -I/usr/local64/opt/R-2.15.2/lib/R/library/RInside/include -g -O2 -Wall -I/usr/local/include rinside_arma0.cpp -L/usr/local64/opt/R-2.15.2/lib/R/lib -lR -lf77blas -latlas -llapack -L/usr/local64/opt/R-2.15.2/lib/R/library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/local64/opt/R-2.15.2/lib/R/library/Rcpp/lib -L/usr/local64/opt/R-2.15.2/lib/R/library/RInside/lib -lRInside -Wl,-rpath,/usr/local64/opt/R-2.15.2/lib/R/library/RInside/lib -o rinside_arma0
The error you get is because Rcpp.h is included before RcppArmadillo.h, Rcpp.h is included by RInside.h.
For the magic that RcppArmadillo gives you, the file RcppArmadillo.h needs to be loaded before Rcpp.h. So I suggest you do this:
#include <RcppArmadillo.h>
#include <RInside.h>