I tried to use eigen in mac. After I installing it I run a demo from its' main page in Xcode.The code is as follows:
#include <iostream>
#include <Eigen/Dense>
using Eigen::MatrixXd;
int main()
{
MatrixXd m(2,2);
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
std::cout << m << std::endl;
}
But it shows "Eigen/Dense' file not found". I try the ways as followed:
Change include line to:#include <Eigen/Core>
try to place the "Eigen" into the "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/" which includes header file like .
3.use the command line"g++ -I /usr/local/include/eigen3 aaa.cpp -o aaa -O1 ". The third one is from
fatal error: 'eigen3/Eigen/Dense' file not found
But I don't know why use this command line. Can someone tell me why? What's more, It also doesn't work for me.
Some people said "/usr/local/include" is the default folders, but there is no "/usr/local/include" in my Mac. So I make a file folder named "include" in 'usr/local'and put the Eigen into it. But it doesn't work. I can't run this code in Xcode.
Can someone help me to solve this problem? Thanks!
Related
I am running just a little code using libsndfile, in the emscripten environment
#include <iostream>
#include <sndfile.h>
int main()
{
SF_INFO info;
const char * path = "~/data/somefile.wav";
SNDFILE* sf = sf_open(path,SFM_READ, &info);
if(sf == NULL)
{
std::cout<< sf_strerror(sf) << std::endl;
return 1;
}
std::cout<<info.samplerate<<std::endl;
std::cout<<"Hello world" << std::endl;
}
So ideally if I run this with normal cmake (Apple Clang compiler) everything works fine, the samplerate and hello world are printed, but when I run this with emcmake cmake (em++ compiler) and run the compiled node main.js file it says System error: no such file or directory. Who can help me with this? Who has experienced such thing?
So I figured it out.
The problem is that Emscripten has its virtual file environment. So if you want this file to be uploaded and later be seen in compiled .js file, you need to add compile flag --preload-file <FILE_PATH> , after that the file with given path will be recognized by emscripten environment.
This question is related to: C++ and R: Create a .so or .dll plus i have read the questions and replies of these posts:
Compiling RInside programs on Windows
Problem with compiling RInside examples under Windows
I try to run the code provided as an example in the answer provided
#include <RInside.h> // for the embedded R via RInside
#include <iomanip>
int main(int argc, char *argv[]) {
RInside R(argc, argv); // create an embedded R instance
std::string txt = // load library, run regression, create summary
"suppressMessages(require(stats));"
"swisssum <- summary(lm(Fertility ~ . , data = swiss));"
"print(swisssum)";
R.parseEvalQ(txt); // eval command, no return
// evaluate R expressions, and assign directly into Rcpp types
Rcpp::NumericMatrix M( (SEXP) R.parseEval("swcoef <- coef(swisssum)"));
Rcpp::StringVector cnames( (SEXP) R.parseEval("colnames(swcoef)"));
Rcpp::StringVector rnames( (SEXP) R.parseEval("rownames(swcoef)"));
std::cout << "\n\nAnd now from C++\n\n\t\t\t";
for (int i=0; i<cnames.size(); i++) {
std::cout << std::setw(11) << cnames[i] << "\t";
}
std::cout << std::endl;
for (int i=0; i<rnames.size(); i++) {
std::cout << std::setw(16) << rnames[i] << "\t";
for (int j=0; j<cnames.size(); j++) {
std::cout << std::setw(11) << M(i,j) << "\t";
}
std::cout << std::endl;
}
std::cout << std::endl;
exit(0);
}
The error in the CMD is the following
C:\Users\DON\Desktop>R CMD SHLIB final.cpp
g++ -m64 -I"C:/R/R-3.2.4/include" -DNDEBUG -I"d:/RCompile/r-compiling/local/
local323/include" -O2 -Wall -mtune=core2 -c final.cpp -o final.o
final.cpp:1:74: fatal error: RInside.h: No such file or directory
compilation terminated.
make: *** [final.o] Error 1
Warning message:
comando ejecutado 'make -f "C:/R/R-3.2.4/etc/x64/Makeconf" -f "C:/R/R-3.2.4/shar
e/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)
' SHLIB="final.dll" WIN=64 TCLBIN=64 OBJECTS="final.o"' tiene estatus 2
Clearly it cant find the RInside.h header. I have the R installed in a folder without spaces. The PATH in global variables have: C:\R\R-3.2.4\bin; C:\Rtools\bin;C:\Rtools\gcc-4.6.3\bin
I understand that in the CMD i cant introduce comands like
$ export PKG_LIBS=‘Rscript -e "Rcpp:::LdFlags()"‘ # if Rcpp older than 0.11.0
$ export PKG_CXXFLAGS=‘Rscript -e "Rcpp:::CxxFlags()"‘
Which first defines and exports two relevant environment variables which R CMD SHLIB then relies on (as put in the FAQ file)
Any advice on this? I need to do a Makefile for each cpp file that i want to compile?
The error is in your approach. You did
R CMD SHLIB final.cpp
which is nowhere given as the correct approach for working with RInside.
Because we need to tell R about headers and libraries for several components, you are supposed to
cd inst/examples/standard
make # build all
or
make rinside_sample3 # build just this
or, if you're on that OS,
make -f Makefile.win # all
or
make -f Makefile.win rinside_sample3
as the Makefile tells R where do find this. That also answers your second question: One Makefile per directory will do. And look at the Makefile: it sets several include directives; your approach only dealt with Rcpp so of course you get an error about RInside.h not found.
I think you keep asking the same question over and over.
OS X El Capitan 10.11.2
Installed CGAL library via macports (version 2.3.4)
I have a file (/Users/Arseniy/Desktop/vec.cpp):
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/convex_hull_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
int main()
{
Point_2 points[5] = { Point_2(0,0), Point_2(10,0), Point_2(10,10), Point_2(6,5), Point_2(4,1) };
Point_2 result[5];
Point_2 *ptr = CGAL::convex_hull_2( points, points+5, result );
std::cout << ptr - result << " points on the convex hull:" << std::endl;
for(int i = 0; i < ptr - result; i++){
std::cout << result[i] << std::endl;
}
return 0;
}
Also i found headers of CGAL library (/usr/local/include/CGAL).
And when i tried to compile it via g++ in terminal (g++ -0 vec vec.cpp -lCGAL -I/usr/local/include/CGAL) I see the error:
"ld: library not found for -lCGAL
clang: error: linker command failed with exit code 1 (use -v to see invocation).
I'm pretty new to gcc. This problem may seem easy to you but I am here to learn.
Thank you for your attention and your help!
I Think Pods isn't being included in the build.
Can you check the pods root path in xcode please? To do this, click "pods" > build settings > and where you see "PODS_ROOT" double click that, which show something like
${SRCROOT}/../Pods
If everything is fine, the issue will be pods isn't being installed, run pods install ( pod install)
For further reference use this link
http://www.binpress.com/tutorial/cocoapods-dependancy-management-for-xcode/139
Sorry If this Doesn't Solves your problem.
You need to provide the linker the path to the CGAL library using the -L option. You are also probably missing the -frounding-math flag.
CGAL recommends to use cmake.
I want to be able to execute programs on my computer. I installed CGAL using Macports, I am not sure how to proceed next. Can anybody tell me how to execute the program, I am desperately trying to run the following program but don't know how to:
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/convex_hull_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_2 Point_2;
int main()
{
Point_2 points[5] = { Point_2(0,0), Point_2(10,0), Point_2(10,10), Point_2(6,5), Point_2(4,1) };
Point_2 result[5];
Point_2 *ptr = CGAL::convex_hull_2( points, points+5, result );
std::cout << ptr - result << " points on the convex hull:" << std::endl;
for(int i = 0; i < ptr - result; i++){
std::cout << result[i] << std::endl;
}
return 0;
}
CGAL comes with a script called cgal_create_cmake_script that should be run where you saved your example file.
Then run cmake . and make
CGAl gets installed on the directory :
opt/local/include/cgal
steps:
Write your program into a text file and save excutable.cpp
In the command line go to the directory of the executable( use cd command)
then write the following commands
cgal_create_CMakeLists -s executable //without .cpp!!
cmake -DCGAL_DIR = opt/local/include/cgal
make
go to the folder where you saved executable.cpp and then click on the executable file(has a black square icon)
and your done :)
NOTE: only works if you installed using macports. if you installed using homebrew directories change,the procedure remains the same :)
You also need command line tools installed.
I hope I dont get downvoted, but I have search online and the Eigen wiki and I cant find instructions on how to install Eigen3 to use it on Xcode5.
I downloaded the tar file and untar it, but then I dont know where to go.
I managed to do it.
Because in Eigen3 there is no library to link to. What you have to do is to untar the downloaded file and then copy the Eigen folder into
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
After that you can create any project and just add the headers of Eigen3
To try it, you can run a the following example given in the "Getting started" guide:
#include <iostream>
#include <Eigen/Dense>
using Eigen::MatrixXd;
int main()
{
MatrixXd m(2,2);
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
std::cout << m << std::endl;
}
That has the following output:
3 -1
2.5 1.5