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.
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 need to be able to list the files in a directory, and so I'm trying to upgrade my C++ version in CodeBlocks to C++ 17 so i can use filesystem. To do this I followed the steps outlined at http://candcplusplus.com/enable-c17-in-code-blocks-mingw-gcc-for-all-version-with-pictures#:~:text=Enabling%20the%20C%2B%2B17,Create%20a%20project.
I didnt have to change much, CodeBlocks 20.03 and MinGW 8.1.0 are already installed. MinGW is already in my path from when I built wxWidgets. The Settings->Compiler...->Toolchain executables tab I didnt have to make any changes to, and appears in CodeBlocks as:
I also checked the box to use C++ 17 in compiler settings like so
I ran the test program on the website with the instructions and got "True!".
However when I change the basic test program to this, to try and use filesystem to read files in a directory, I get an error:
#include <iostream>
#include <filesystem>
using namespace std;
int main()
{
const int i=90;
if constexpr (i) //'if constexpr' is part of C++17
{
cout << "True!";
}
else
{
cout<<"False" ;
}
std::string path = "../MagicProgCPP/files/debug images/";
for (const auto & entry : filesystem::directory_iterator(path))
{
cout << entry.path() << std::endl;
}
cin.get();
return 0;
}
The program stops building, opens the file fs_path.h and stops on this line:
#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
if (__p.is_absolute()
|| (__p.has_root_name() && __p.root_name() != root_name())) <----- ******STOPS HERE
operator=(__p);
else
{
string_type __pathname;
if (__p.has_root_directory())
__pathname = root_name().native();
else if (has_filename() || (!has_root_directory() && is_absolute()))
__pathname = _M_pathname + preferred_separator;
__pathname += __p.relative_path().native(); // XXX is this right?
_M_pathname.swap(__pathname);
_M_split_cmpts();
}
#else
// Much simpler, as any path with root-name or root-dir is absolute.
if (__p.is_absolute())
operator=(__p);
else
{
if (has_filename() || (_M_type == _Type::_Root_name))
_M_pathname += preferred_separator;
_M_pathname += __p.native();
_M_split_cmpts();
}
#endif
return *this;
}
I get this error in the build log:
C:\Program Files\CodeBlocks\MinGW\lib\gcc\x86_64-w64-mingw32\8.1.0\include\c++\bits\fs_path.h|237|error: no match for 'operator!=' (operand types are 'std::filesystem::__cxx11::path' and 'std::filesystem::__cxx11::path')|
I'm prety confident the path exists as I entered it and there's files in it. The build log message suggests maybe I'm not using C++17? But when I click build, this is the line the program uses to build:
g++.exe -Wall -fexceptions -g -Wall -std=c++17 -c E:\testc17\main.cpp -o obj\Debug\main.o
What am I doing wrong? Thanks
The bug 78870 was fixed since 2018-07.
You should add to project options -> linker settings -> link libraries the following library: stdc++fs.
I tried to compile your code with MinGW gcc 8.1.0 (via CodeBlocks) and everything works well (clearly with another path, since I don't have the same directories as you).
You could also add a check on the existence of the search directory like this:
namespace fs = std::filesystem;
std::string mypath { "../MyDir" };
if(fs::exists(mypath))
{
for(const auto & entry : fs::directory_iterator(path))
{
cout << entry.path() << std::endl;
}
}
It appears that this exact problem is a known bug in mingw 8.1. The bug report is here: https://sourceforge.net/p/mingw-w64/bugs/737/
and has the error in the same location:
operator != is declared and defined in line 550, but referenced in line 237.
The problem is triggered by operator/= in line 233:
path& operator/=(const path& __p)
{
#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
if (__p.is_absolute()
|| (__p.has_root_name() && __p.root_name() != root_name()))
operator=(__p);
else
{
string_type __pathname;
if (__p.has_root_directory())
__pathname = root_name().native();
else if (has_filename() || (!has_root_directory() && is_absolute()))
__pathname = _M_pathname + preferred_separator;
__pathname += __p.relative_path().native(); // XXX is this right?
_M_pathname.swap(__pathname);
_M_split_cmpts();
}
The bug report said this was fixed in master meaning you need to install a version of mingw with the fix applied. I believe the best method is to upgrade mingw to a version greater than 8.1
user4581301 commented above in the main question that the following link has instructions on how to get a mingw install: How to install MinGW-w64 and MSYS2?
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!
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