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>
Related
I am currently trying to use the DLFCN-WIN32 library in order to use a c++ script originally implemented to use the dlfcn.h library.
When compiling the code (cantera V2.3), everything goes well except when generating the shared library where the dlopen and dlclose functions are not found.
originally script is :
/**
* #file CustomKinetics.cpp
*
* #ingroup chemkinetics
*/
//
// Author: Q. Cazeres, A. Felden, P. Pepiot
//
//
#include "cantera/kinetics/CustomKinetics.h"
#include <iostream>
#include <dlfcn.h>
using namespace std;
namespace Cantera
{
CustomKinetics::CustomKinetics(thermo_t* th) : GasKinetics(th)
{
printf("WARNING: Using customized kinetics from f90 file.\n");
handle = dlopen("customkinetics.so", RTLD_LAZY);
// load symbol
ck = (ck_t) dlsym(handle, "customkinetics_");
}
void CustomKinetics::get_wdot_reduced(doublereal* wdot)
{
doublereal P = thermo().pressure();
doublereal T = thermo().temperature();
// New yarc2 format
//doublereal rho = thermo().density();
const doublereal* m_y = thermo().massFractions();
ck(&P,&T,&m_y[0],&wdot[0]);
// New yarc2 format
//ck(&P,&T,&rho,&m_y[0],&wdot[0]);
// Old yarc format
//mol/kmol conversion cantera is in kmol
for (size_t i=0;i<thermo().nSpecies();i++) {
wdot[i]=wdot[i]/1000.0;
}
}
The script is compiled with the following command line :
g++ -o build\src\kinetics\CustomKinetics.o -c -std=c++0x -lpsapi -O3 -Wno-inline -g -Wall -include src/pch/system.h -DNDEBUG -Iinclude -Iinclude\cantera\ext -Ibuild\src -Ibuild\src\L -Isrc\L -IL:\LIB_WINDOWS\DLFCN-WIN32\include -IL:\LIB_WINDOWS\BOOST\boost_1_78_0 src\kinetics\CustomKinetics.cpp
The shared library is compiled with the following command line :
scons: warning: Using $CXX to link Fortran and C++ code together.
This may generate a buggy executable if the 'g++'
compiler does not know how to deal with Fortran runtimes.
g++ -static-libgcc -static-libstdc++ -shared -o build\lib\cantera_shared.dll build\ext\libexecstream\exec-stream.o build\ext\fmt\fmt\format.o build\ext\fmt\fmt\ostream.o build\ext\fmt\fmt\posix.o build\ext\sundials\src\sundials\sundials_band.o build\ext\sundials\src\sundials\sundials_dense.o build\ext\sundials\src\sundials\sundials_direct.o build\ext\sundials\src\sundials\sundials_iterative.o build\ext\sundials\src\sundials\sundials_math.o build\ext\sundials\src\sundials\sundials_nvector.o build\ext\sundials\src\sundials\sundials_pcg.o build\ext\sundials\src\sundials\sundials_sparse.o build\ext\sundials\src\sundials\sundials_spbcgs.o build\ext\sundials\src\sundials\sundials_spfgmr.o build\ext\sundials\src\sundials\sundials_spgmr.o build\ext\sundials\src\sundials\sundials_sptfqmr.o build\ext\sundials\src\nvec_ser\fnvector_serial.o build\ext\sundials\src\nvec_ser\nvector_serial.o build\ext\sundials\src\cvodes\cvodea.o build\ext\sundials\src\cvodes\cvodea_io.o build\ext\sundials\src\cvodes\cvodes.o build\ext\sundials\src\cvodes\cvodes_band.o build\ext\sundials\src\cvodes\cvodes_bandpre.o build\ext\sundials\src\cvodes\cvodes_bbdpre.o build\ext\sundials\src\cvodes\cvodes_dense.o build\ext\sundials\src\cvodes\cvodes_diag.o build\ext\sundials\src\cvodes\cvodes_direct.o build\ext\sundials\src\cvodes\cvodes_io.o build\ext\sundials\src\cvodes\cvodes_sparse.o build\ext\sundials\src\cvodes\cvodes_spbcgs.o build\ext\sundials\src\cvodes\cvodes_spgmr.o build\ext\sundials\src\cvodes\cvodes_spils.o build\ext\sundials\src\cvodes\cvodes_sptfqmr.o build\ext\sundials\src\ida\ida.o build\ext\sundials\src\ida\ida_band.o build\ext\sundials\src\ida\ida_bbdpre.o build\ext\sundials\src\ida\ida_dense.o build\ext\sundials\src\ida\ida_direct.o build\ext\sundials\src\ida\ida_ic.o build\ext\sundials\src\ida\ida_io.o build\ext\sundials\src\ida\ida_sparse.o build\ext\sundials\src\ida\ida_spbcgs.o build\ext\sundials\src\ida\ida_spgmr.o build\ext\sundials\src\ida\ida_spils.o build\ext\sundials\src\ida\ida_sptfqmr.o build\src\base\Parser.o build\src\base\ValueCache.o build\src\base\application.o build\src\base\checkFinite.o build\src\base\clockWC.o build\src\base\ct2ctml.o build\src\base\ctexceptions.o build\src\base\ctml.o build\src\base\global.o build\src\base\plots.o build\src\base\stringUtils.o build\src\base\xml.o build\src\thermo\ConstCpPoly.o build\src\thermo\ConstDensityThermo.o build\src\thermo\DebyeHuckel.o build\src\thermo\Elements.o build\src\thermo\FixedChemPotSSTP.o build\src\thermo\GibbsExcessVPSSTP.o build\src\thermo\HMWSoln.o build\src\thermo\HMWSoln_input.o build\src\thermo\IdealGasPhase.o build\src\thermo\IdealMolalSoln.o build\src\thermo\IdealSolidSolnPhase.o build\src\thermo\IdealSolnGasVPSS.o build\src\thermo\IonsFromNeutralVPSSTP.o build\src\thermo\LatticePhase.o build\src\thermo\LatticeSolidPhase.o build\src\thermo\MargulesVPSSTP.o build\src\thermo\MaskellSolidSolnPhase.o build\src\thermo\MetalSHEelectrons.o build\src\thermo\MineralEQ3.o build\src\thermo\MixedSolventElectrolyte.o build\src\thermo\MixtureFugacityTP.o build\src\thermo\MolalityVPSSTP.o build\src\thermo\MolarityIonicVPSSTP.o build\src\thermo\Mu0Poly.o build\src\thermo\MultiSpeciesThermo.o build\src\thermo\Nasa9Poly1.o build\src\thermo\Nasa9PolyMultiTempRegion.o build\src\thermo\NasaPoly2.o build\src\thermo\PDSS.o build\src\thermo\PDSS_ConstVol.o build\src\thermo\PDSS_HKFT.o build\src\thermo\PDSS_IdealGas.o build\src\thermo\PDSS_IonsFromNeutral.o build\src\thermo\PDSS_SSVol.o build\src\thermo\PDSS_Water.o build\src\thermo\Phase.o build\src\thermo\PhaseCombo_Interaction.o build\src\thermo\PureFluidPhase.o build\src\thermo\RedlichKisterVPSSTP.o build\src\thermo\RedlichKwongMFTP.o build\src\thermo\SemiconductorPhase.o build\src\thermo\SingleSpeciesTP.o build\src\thermo\Species.o build\src\thermo\SpeciesThermoFactory.o build\src\thermo\SpeciesThermoInterpType.o build\src\thermo\StoichSubstance.o build\src\thermo\SurfPhase.o build\src\thermo\ThermoFactory.o build\src\thermo\ThermoPhase.o build\src\thermo\VPSSMgr.o build\src\thermo\VPSSMgrFactory.o build\src\thermo\VPSSMgr_ConstVol.o build\src\thermo\VPSSMgr_General.o build\src\thermo\VPSSMgr_IdealGas.o build\src\thermo\VPSSMgr_Water_ConstVol.o build\src\thermo\VPSSMgr_Water_HKFT.o build\src\thermo\VPStandardStateTP.o build\src\thermo\WaterProps.o build\src\thermo\WaterPropsIAPWS.o build\src\thermo\WaterPropsIAPWSphi.o build\src\thermo\WaterSSTP.o build\src\tpx\CarbonDioxide.o build\src\tpx\HFC134a.o build\src\tpx\Heptane.o build\src\tpx\Hydrogen.o build\src\tpx\Methane.o build\src\tpx\Nitrogen.o build\src\tpx\Oxygen.o build\src\tpx\RedlichKwong.o build\src\tpx\Sub.o build\src\tpx\Water.o build\src\tpx\lk.o build\src\tpx\utils.o build\src\equil\BasisOptimize.o build\src\equil\ChemEquil.o build\src\equil\MultiPhase.o build\src\equil\MultiPhaseEquil.o build\src\equil\vcs_Gibbs.o build\src\equil\vcs_MultiPhaseEquil.o build\src\equil\vcs_SpeciesProperties.o build\src\equil\vcs_TP.o build\src\equil\vcs_VolPhase.o build\src\equil\vcs_elem.o build\src\equil\vcs_elem_rearrange.o build\src\equil\vcs_inest.o build\src\equil\vcs_nondim.o build\src\equil\vcs_phaseStability.o build\src\equil\vcs_prep.o build\src\equil\vcs_prob.o build\src\equil\vcs_rearrange.o build\src\equil\vcs_report.o build\src\equil\vcs_rxnadj.o build\src\equil\vcs_setMolesLinProg.o build\src\equil\vcs_solve.o build\src\equil\vcs_solve_TP.o build\src\equil\vcs_solve_phaseStability.o build\src\equil\vcs_species_thermo.o build\src\equil\vcs_util.o build\src\numerics\BandMatrix.o build\src\numerics\CVodesIntegrator.o build\src\numerics\DAE_solvers.o build\src\numerics\DenseMatrix.o build\src\numerics\Func1.o build\src\numerics\FuncEval.o build\src\numerics\IDA_Solver.o build\src\numerics\ODE_integrators.o build\src\numerics\ResidJacEval.o build\src\numerics\RootFind.o build\src\numerics\SquareMatrix.o build\src\numerics\funcs.o build\src\numerics\polyfit.o build\src\kinetics\AqueousKinetics.o build\src\kinetics\BulkKinetics.o build\src\kinetics\C12H26_25_373_27_TJKinetics.o build\src\kinetics\C12H26_NOX_27_452_20_TJKinetics.o build\src\kinetics\C2H4_18_320_11_AFKinetics.o build\src\kinetics\C3H8_22_173_12_FCKinetics.o build\src\kinetics\C7H16_25_210_27_FCKinetics.o build\src\kinetics\CH4_22_320_18_TJKinetics.o build\src\kinetics\CustomKinetics.o build\src\kinetics\Falloff.o build\src\kinetics\FalloffFactory.o build\src\kinetics\GasKinetics.o build\src\kinetics\Group.o build\src\kinetics\HYCHEM_27_272_12_AFKinetics.o build\src\kinetics\HYCHEM_NOX_29_548_17_AFKinetics.o build\src\kinetics\ImplicitSurfChem.o build\src\kinetics\InterfaceKinetics.o build\src\kinetics\Kinetics.o build\src\kinetics\KineticsFactory.o build\src\kinetics\Reaction.o build\src\kinetics\ReactionPath.o build\src\kinetics\RxnRates.o build\src\kinetics\importKinetics.o build\src\kinetics\solveSP.o build\src\kinetics\c12h262537327tj.o build\src\kinetics\c12h262745220tj.o build\src\kinetics\c2h41832011af.o build\src\kinetics\c3h82217312fc.o build\src\kinetics\c7h162521027fc.o build\src\kinetics\ch42232018tj.o build\src\kinetics\hychem2727212af.o build\src\kinetics\hychemnox2954817af.o build\src\kinetics\sankaran13.o build\src\transport\AVBPTransport.o build\src\transport\DustyGasTransport.o build\src\transport\GasTransport.o build\src\transport\HighPressureGasTransport.o build\src\transport\LTPspecies.o build\src\transport\LiquidTranInteraction.o build\src\transport\LiquidTransport.o build\src\transport\LiquidTransportData.o build\src\transport\LiquidTransportParams.o build\src\transport\MMCollisionInt.o build\src\transport\MixTransport.o build\src\transport\MultiTransport.o build\src\transport\SimpleTransport.o build\src\transport\SolidTransport.o build\src\transport\SolidTransportData.o build\src\transport\TransportBase.o build\src\transport\TransportData.o build\src\transport\TransportFactory.o build\src\transport\TransportParams.o build\src\transport\WaterTransport.o build\src\oneD\Domain1D.o build\src\oneD\MultiJac.o build\src\oneD\MultiNewton.o build\src\oneD\OneDim.o build\src\oneD\Sim1D.o build\src\oneD\StFlow.o build\src\oneD\boundaries1D.o build\src\oneD\refine.o build\src\zeroD\ConstPressureReactor.o build\src\zeroD\FlowDevice.o build\src\zeroD\FlowReactor.o build\src\zeroD\IdealGasConstPressureReactor.o build\src\zeroD\IdealGasReactor.o build\src\zeroD\Reactor.o build\src\zeroD\ReactorBase.o build\src\zeroD\ReactorFactory.o build\src\zeroD\ReactorNet.o build\src\zeroD\ReactorSurface.o build\src\zeroD\Wall.o build\src\clib\ct.o build\src\clib\ctfunc.o build\src\clib\ctmultiphase.o build\src\clib\ctonedim.o build\src\clib\ctreactor.o build\src\clib\ctrpath.o build\src\clib\ctsurf.o build\src\clib\ctxml.o -Lbuild\lib -Lbuild\src\L -Lsrc\L -LL:\LIB_WINDOWS\DLFCN-WIN32\lib -Wl,--out-implib,build\lib\libcantera_shared.a -Wl,--output-def,build\lib\cantera_shared.def
And after that I got the following error message :
=====
b"build\\src\\kinetics\\CustomKinetics.o: In function `Cantera::CustomKinetics::CustomKinetics(Cantera::ThermoPhase*)':\r\nL:\\LIB_WINDOWS\\CANTERA\\cantera-avbp-2.3/src/kinetics/CustomKinetics.cpp:23: undefined reference to `dlopen'\r\nL:\\LIB_WINDOWS\\CANTERA\\cantera-avbp-2.3/src/kinetics/CustomKinetics.cpp:26: undefined reference to `dlsym'\r\nbuild\\src\\kinetics\\CustomKinetics.o: In function `Cantera::CustomKinetics::close_dl()':\r\nL:\\LIB_WINDOWS\\CANTERA\\cantera-avbp-2.3/src/kinetics/CustomKinetics.cpp:53: undefined reference to `dlclose'\r\nL:\\LIB_WINDOWS\\CANTERA\\cantera-avbp-2.3/src/kinetics/CustomKinetics.cpp:53: undefined reference to `dlclose'\r\ncollect2.exe: error: ld returned 1 exit status\r\n"
=====
scons: *** [build\lib\cantera_shared.dll] Error 1
scons: building terminated because of errors.
The include and lib directories of the DLFCN-WIN32 libraries are well put in argument with -L option. Did I forget a compilation option?
Thank you in advance for your help,
Rock
I'm following along with this tutorial for Webtoolkit: https://www.webtoolkit.eu/wt/doc/tutorial/wt.html
I am running all this on a Rasbian/Debian on a Virtual Machine and I am using C++14
I decided to copy paste the hello.cpp code onto my Desktop and am compiling it like this on my terminal as I was facing linking errors and thus followed along with command line examples in the tutorial:
g++ -std=c++14 -o hello hello.cpp -I/usr/include -L/usr/lib
However I still get:
hello.cpp:1:29: fatal error: Wt/WApplication.h: No such file or directory
#include <Wt/WApplication.h>
My Wt files are located in /usr/include and /usr/lib which is why I used them.
This stackoverflow did not solve my issue: How to Install Wt into a Custom Folder Without "fatal error: Wt/WApplication: No such file or directory"
EDIT: I was able to run the example files located in the Wt folders in /usr/lib/Wt/examples but can't run it on Desktop, I followed the command line examples on the tutorial for linking errors
EDIT 2: The cpp code if it helps, same as tutorial, just copy pasted:
#include <Wt/WApplication.h>
#include <Wt/WBreak.h>
#include <Wt/WContainerWidget.h>
#include <Wt/WLineEdit.h>
#include <Wt/WPushButton.h>
#include <Wt/WText.h>
class HelloApplication : public Wt::WApplication
{
public:
HelloApplication(const Wt::WEnvironment& env);
private:
Wt::WLineEdit *nameEdit_;
Wt::WText *greeting_;
};
HelloApplication::HelloApplication(const Wt::WEnvironment& env)
: Wt::WApplication(env)
{
setTitle("Hello world");
root()->addWidget(std::make_unique<Wt::WText>("Your name, please? "));
nameEdit_ = root()->addWidget(std::make_unique<Wt::WLineEdit>());
Wt::WPushButton *button = root()->addWidget(std::make_unique<Wt::WPushButton>("Greet me."));
root()->addWidget(std::make_unique<Wt::WBreak>());
greeting_ = root()->addWidget(std::make_unique<Wt::WText>());
auto greet = [this]{
greeting_->setText("Hello there, " + nameEdit_->text());
};
button->clicked().connect(greet);
}
int main(int argc, char **argv)
{
return Wt::WRun(argc, argv, [](const Wt::WEnvironment& env) {
return std::make_unique<HelloApplication>(env);
});
}
The Wt include files do not have the .h extension on some OSs.
Try #include <Wt/WApplication>
root#08c7a05c8129:/usr/lib/Wt/examples/hello# ls /usr/include/Wt
Auth WBatchEditProxyModel WDateValidator WHTML5Audio WLocalizedStrings WPopupWidget WSslInfo WTimePicker
Chart WBoostAny WDefaultLayout WHTML5Video WLogger WProgressBar WStackedWidget WTimeValidator
Dbo WBootstrapTheme WDefaultLoadingIndicator WIOService WMatrix4x4 WPushButton WStandardItem WTimer
Ext WBorder WDialog WIcon WMeasurePaintDevice WRadioButton WStandardItemModel WTimerWidget
Http WBorderLayout WDllDefs.h WIconPair WMediaPlayer WRandom WStatelessSlot WToolBar
Json WBoxLayout WDoubleSpinBox WIdentityProxyModel WMemoryResource WRasterImage WStreamResource WTransform
Mail WBreak WDoubleValidator WImage WMenu WReadOnlyProxyModel WString WTree
Payment WBrush WEnvironment WInPlaceEdit WMenuItem WRectArea WStringListModel WTreeNode
Render WButtonGroup WEvent WIntValidator WMessageBox WRectF WStringStream WTreeTable
Utils WCalendar WException WInteractWidget WMessageResourceBundle WRegExp WStringUtil WTreeTableNode
WAbstractArea WCanvasPaintDevice WFileResource WItemDelegate WMessageResources WRegExpValidator WSubMenuItem WTreeView
WAbstractGLImplementation WCheckBox WFileUpload WItemSelectionModel WModelIndex WResource WSuggestionPopup WVBoxLayout
WAbstractItemDelegate WCircleArea WFitLayout WJavaScript WNavigationBar WScrollArea WSvgImage WValidationStatus
WAbstractItemModel WClientGLWidget WFlags WJavaScriptPreamble WObject WScrollBar WTabWidget WValidator
WAbstractItemView WColor WFlashObject WJavaScriptSlot WOverlayLoadingIndicator WSelectionBox WTable WVector3
WAbstractListModel WCombinedLocalizedStrings WFont WLabel WPaintDevice WServer WTableCell WVector4
WAbstractMedia WComboBox WFontMetrics WLayout WPaintedWidget WServerGLWidget WTableColumn WVectorImage
WAbstractProxyModel WCompositeWidget WFormModel WLayoutItem WPainter WShadow WTableRow WVideo
WAbstractSpinBox WConfig.h WFormWidget WLayoutItemImpl WPainterPath WSignal WTableView WViewWidget
WAbstractTableModel WContainerWidget WGLWidget WLength WPanel WSignalMapper WTemplate WVirtualImage
WAbstractToggleButton WCssDecorationStyle WGenericMatrix WLengthValidator WPdfImage WSlider WTemplateFormView WVmlImage
WAccordionLayout WCssStyleSheet WGlobal WLineEdit WPen WSocketNotifier WText WWebWidget
WAggregateProxyModel WCssTheme WGoogleMap WLineF WPoint WSortFilterProxyModel WTextArea WWidget
WAnchor WDate WGradient WLink WPointF WSound WTextEdit WWidgetItem
WAnimation WDateEdit WGridLayout WLoadingIndicator WPolygonArea WSpinBox WTheme
WApplication WDatePicker WGroupBox WLocalDateTime WPopupMenu WSplitButton WTime
WAudio WDateTime WHBoxLayout WLocale WPopupMenuItem WSslCertificate WTimeEdit
so use without extension:
#include <Wt/WApplication>
Try :
g++ -std=c++14 -o hello hello.cpp -I/usr/local/include/Wt -L/usr/local/lib64/
OR
g++ -std=c++14 -o hello hello.cpp -I/usr/local/include/Wt -L/usr/local/lib/
I'm having a question about using a C ++ code using Rcpp outside of a package structure.
To clarify my doubt, consider the C ++ code (test.cpp) below:
// [[Rcpp::depends(RcppGSL)]]
#include <Rcpp.h>
#include <numeric>
#include <gsl/gsl_sf_bessel.h>
#include <RcppGSL.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_blas.h>
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector timesTwo(NumericVector x) {
return x * 2;
}
// [[Rcpp::export]]
double my_bessel(double x){
return gsl_sf_bessel_J0 (x);
}
// [[Rcpp::export]]
int tamanho(NumericVector x){
int n = x.size();
return n;
}
// [[Rcpp::export]]
double soma2(NumericVector x){
double resultado = std::accumulate(x.begin(), x.end(), .0);
return resultado;
}
// [[Rcpp::export]]
Rcpp::NumericVector colNorm(const RcppGSL::Matrix & G) {
int k = G.ncol();
Rcpp::NumericVector n(k); // to store results
for (int j = 0; j < k; j++) {
RcppGSL::VectorView colview = gsl_matrix_const_column (G, j);
n[j] = gsl_blas_dnrm2(colview);
}
return n; // return vector
}
The above code works when it is inside the structure of a package. As we know, using the Rcpp::compileAttributes() the file is created RcppExports.cpp. So I will have access to the functions in the R. environment.
My interest is to use the C++ function implemented using the Rcpp outside the framework of a package. For this I compiled the C ++ code using the g ++ compiler as follows:
g++ -I"/usr/include/R/" -DNDEBUG -I"/home/pedro/R/x86_64-pc-linux-gnu-library/3.5/Rcpp/include" -I"/home/pedro/Dropbox/UFPB/Redes Neurais e AnĂ¡lise de Agrupamento/Rcpp" -I /home/pedro/R/x86_64-pc-linux-gnu-library/3.5/RcppGSL/include -D_FORTIFY_SOURCE=2 -fpic -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -c test.cpp -o test.o -lgsl -lgslcblas -lm
g++ -shared -L/usr/lib64/R/lib -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -o produto.so produto.o -L/usr/lib64/R/lib -lR -lgsl -lgslcblas -lm
The compilation occurred successfully and no warning message was issued. In this way, the test.o andtest.so files were generated. Already in R, using the .Call interface, I did:
dyn.load("test.so")
my_function <- function(x){
.Call("soma2",x)
}
When trying to use the my_function () function, an error occurs stating that soma2 is not in the load table. Is there any way to create the RcppExports.cpp file outside the framework of a package? I guess the correct one would be to have compiled the code RcppExports.cpp and not test.cpp.
Thanks in advance.
If you are working outside of a package you can simply use Rcpp::sourceCpp(<file>). This will take care of compilating, linking and prociding an R wrapper for you. With your file I get:
> Rcpp::sourceCpp("test.cpp")
> soma2(1:5)
[1] 15
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.
The following program aborts with pointer being freed was not allocated:
#include <boost/program_options.hpp>
int main(int argc, char* argv[])
{
boost::program_options::positional_options_description positional;
return 0;
}
I compiled and linked the program with Boost 1.46.1, which I built myself into /usr/local, on OS X 10.6.7. I can't find any installed libboost_program_options other than the one I'm (supposedly) linking against.
Any idea what causes this crash?
Edit: As for stacktrace, the program
#include <boost/program_options.hpp>
#include <execinfo.h>
int main(int argc, char* argv[])
{
boost::program_options::positional_options_description positional;
void* callstack[128];
int i, frames = backtrace(callstack, 128);
char** strs = backtrace_symbols(callstack, frames);
for (i = 0; i < frames; ++i) {
printf("%s\n", strs[i]);
}
free(strs);
return 0;
}
built as
g++ -Wp,-MMD,.make-debug/main.dd -Wall -g3 -I/usr/local/include -c main.cc -o .make-debug/main.o
g++ -o sandbox .make-debug/main.o -lboost_program_options -L/usr/local/lib
and run as ./sandbox produces the output
0 sandbox 0x00000001000017bf main + 57
1 sandbox 0x0000000100001764 start + 52
2 ??? 0x0000000000000001 0x0 + 1
sandbox(50587) malloc: *** error for object 0x7fff70506500: pointer being freed was not al
located
*** set a breakpoint in malloc_error_break to debug
Command terminated
As for building Boost:
$ cd boost_1_46_1
$ ./bootstrap.sh --prefix=/usr/local
$ ./bjam toolset=darwin-4.2
And here's my ~/user-config.jam:
using darwin : 4.0 : g++-4.0 ;
using darwin : 4.2 : g++-4.2 ;
using darwin : 4.5.1 : /Users/matan/usr/bin/g++ ;
I am unable to reproduce
macmini:stackoverflow samm$ cat po.cc
#include <boost/program_options.hpp>
#include <boost/version.hpp>
#include <iostream>
int
main(int argc, char* argv[])
{
std::cout << BOOST_LIB_VERSION << std::endl;
boost::program_options::positional_options_description positional;
return 0;
}
macmini:stackoverflow samm$ g++ -I /opt/local/include -L/opt/local/lib -lboost_program_options po.cc
macmini:stackoverflow samm$ ./a.out
1_46_1
macmini:stackoverflow samm$
you should update your question with the steps you used to build boost, particularly the arguments to bjam.
I think I resolved the issue, but I'm not happy with my solution. I neglected to mention that I previously installed gcc 4.6.0 with --program-suffix=-4.6 in /usr/local. Uninstalling it and rebuilding Boost solved the issue. I then had no compilers installed other than gcc-4.0 and gcc-4.2 which came with XCode. Presumably gcc-4.6 files interfered with gcc-4.0 files or the darwin toolset.