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
Related
This might be a very basic question, but this is my first time with such an issue. I am using an M1 macOS Big Sur. I am trying to run boost libraries for my program. I have installed boost on my device using arch -arm64 brew install boost.
When I try to compile the following program:
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
int128_t boost_product(long long A, long long B)
{
int128_t ans = (int128_t)A * B;
return ans;
}
int main()
{
long long first = 98745636214564698;
long long second = 7459874565236544789;
cout << "Product of " << first << " * " << second
<< " = \n"
<< boost_product(first, second);
return 0;
}
with
$ g++ --version
Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: arm64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
I get the following error:
boost.cpp:1:10: fatal error: 'boost/multiprecision/cpp_int.hpp' file not found
#include <boost/multiprecision/cpp_int.hpp>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
This is what I see when I go into /opt/homebrew/lib:
cmake libboost_log-mt.dylib libboost_serialization.a libgettextsrc-0.21.dylib
gcc libboost_log.a libboost_serialization.dylib libgettextsrc.dylib
gettext libboost_log.dylib libboost_stacktrace_addr2line-mt.a libgmp.10.dylib
libasprintf.0.dylib libboost_log_setup-mt.a libboost_stacktrace_addr2line-mt.dylib libgmp.a
libasprintf.a libboost_log_setup-mt.dylib libboost_stacktrace_addr2line.a libgmp.dylib
libasprintf.dylib libboost_log_setup.a libboost_stacktrace_addr2line.dylib libgmpxx.4.dylib
libboost_atomic-mt.a libboost_log_setup.dylib libboost_stacktrace_basic-mt.a libgmpxx.a
libboost_atomic-mt.dylib libboost_math_c99-mt.a libboost_stacktrace_basic-mt.dylib libgmpxx.dylib
...
When I cd into cmake, I see that there are a bunch of Boost_...-prefixed files.
It looks like I have boost on my computer, but how do I use it in my program and compile it with g++?
I figured out that the homebrew was adding files to /opt/homebrew/Cellar/boost/1.79.0_1/include/boost. Once the location was identified, I simply compiled by code with flag
g++ -I/opt/homebrew/Cellar/boost/1.79.0_1/include/boost ...
And made sure my include statements referenced the appropriate .hpp files.
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!
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 am trying to use the very recent capability of the RcppArmadillo package (version 0.3.910.0 with R 3.0.1 and evrerything up to date) for conversion of a sparse matrix from the Matrix package (class "dgCMatrix") to the sp_mat type of armadillo. I am using the "as" and "wrap" functions from the file "RcppArmadilloExtensions/spmat.h". Unfortunately, I am experiencing a compilation error while trying to create the shared library .so when invoking "R CMD INSTALL myRpackage".
Here is a minimal example to reproduce the error:
I created an empty package with RcppArmadillo.package.skeleton()
I defined 2 .cpp files with their corresponding headers .h to perform sum and product of sparse matrices imported from R, as follows :
file "arma_sp_sum.h"
#ifndef _anRpackage_ARMA_SP_SUM_H
#define _anRpackage_ARMA_SP_SUM_H
#include <RcppArmadilloExtensions/spmat.h>
RcppExport SEXP arma_sp_prod(SEXP SPMAT) ;
#endif
file "arma_sp_sum.cpp"
#include "arma_sp_sum.h"
using namespace Rcpp ;
SEXP arma_sp_sum(SEXP SPMAT){
arma::sp_mat m1 = Rcpp::as<arma::sp_mat>(SPMAT) ;
arma::sp_mat m2 = Rcpp::as<arma::sp_mat>(SPMAT) ;
arma::sp_mat res = m1 + m2;
return Rcpp::wrap(res) ;
}
file "arma_sp_prod.h"
#ifndef _anRpackage_ARMA_SP_PROD_H
#define _anRpackage_ARMA_SP_PROD_H
#include <RcppArmadilloExtensions/spmat.h>
RcppExport SEXP arma_sp_prod(SEXP SPMAT) ;
#endif
file "arma_sp_prod.cpp"
#include "arma_sp_prod.h"
using namespace Rcpp ;
SEXP arma_sp_prod(SEXP SPMAT){
arma::sp_mat m1 = Rcpp::as<arma::sp_mat>(SPMAT) ;
arma::sp_mat m2 = Rcpp::as<arma::sp_mat>(SPMAT) ;
arma::sp_mat res = m1 * m2;
return Rcpp::wrap(res) ;
}
Then, when running $ R CMD INSTALL anRpackage $, the compiler successively creates the ".o" files but I get the following ld error :
ld: duplicate symbol arma::SpMat<double> Rcpp::as<arma::SpMat<double> >(SEXPREC*)in arma_sp_sum.o and arma_sp_prod.o for architecture x86_64
collect2: ld returned 1 exit status
make: *** [anRpackage.so] Error 1
ERROR: compilation failed for package ‘anRpackage’
So what am I doing wrong? Sorry if it is a silly question... Anyway, thanks to all the guys doing such a good job with armadilllo/RcppArmadillo, and for your help.
J.
I have made a few changes to RcppArmadillo to clean this. Now as and wrap are correctly templated for sparse matrix types from armadillo (arma::SpMat<T>).
Can you try again using the RcppArmadillo from svn ?
Also, now, you should only need
#include <RcppArmadillo.h>
With the updated code, I'm able to compile your package as well as something like this :
#include <RcppArmadillo.h>
// [[Rcpp::depends("RcppArmadillo")]]
using namespace Rcpp ;
// [[Rcpp::export]]
arma::sp_mat sparse( arma::sp_mat A ){
A(0,0) = 1;
A(1,0) = 2;
return A ;
}
/*** R
require(Matrix)
m <- Matrix(c(0,0,2:0), 3,5)
sparse(m)
*/