Using boost library in Julia with Cxx.jl on Windows - c++

I'm using Cxx with Julia 1.3.1 to use a function of the boost library, it works properly on Linux after the installation of such library, but in Windows i have never make it work. This is the module i wrote:
module Airyzero
#Returns zeros of Airy's function
using Cxx;
export airyzero
cxx"""
#include<iostream>
#include <boost/math/special_functions/airy.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
typedef boost::multiprecision::cpp_dec_float_50 float_type;
"""
cxx"""
double airyzero1(int y) {
return boost::math::airy_ai_zero<double>(y);
}
"""
airyzero(ind) = #cxx airyzero1(ind)
end
So i can use the function airy_ai_zero from boost as airyzero in my code. I need that works also in Windows because none of the computers of my lab uses Linux (neither my collegues).

I added to the header directory the path where boost was installed:
if Sys.iswindows()
const pathboost = "C:\\boost_1_73_0";
addHeaderDir(pathboost,kind=C_System);
end

Related

Pybind11 and Boost from C++

I want to use functions from Boost C++ Libraries (like gauss_kronrod.hpp) in my Pybind11 project to optimize python using C++.
Using C++ functions from standard libraries (like numeric) is straightforward:
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <numeric>
namespace py = pybind11;
.
.
.
PYBIND11_MODULE(_test, m) {
m.def("test_func", &test_func);
}
How can I access all the functions from Boost? I downloaded it and saved it in the folder thirdparty of my Pybind11 project. I can include a single function from Boost using to complete path to this function:
# include <thirdparty/boost/boost/math/quadrature/gauss_kronrod.hpp>
However func.hpp loads other functions from Boost which can not be found. I feel like I need to add the Path to Boost in my file CMakeLists.txt.
Under PyBind11: boost::multiprecision::cpp_int to Python is an example where cpp_int.hpp from Boost was successfully used within Pybind11. Unfortunately, its not clear how they made the command
#include <boost/multiprecision/cpp_int.hpp>
work properly

OpenCV on C++/Namespace issue?

I am new to C++ so I get some trouble to use openCV on my C++ project. I'm using Xcode as an IDE.
So I used brew to install opencv using the two command lines:
brew install opencv3 --with-ffmpeg --with-tbb --with-contrib
brew reinstall opencv3 --HEAD --with-python3 --with-ffmpeg --with-tbb --with-contrib
I checked the path to add to my project to load the library using recursivity, so I added on Xcode the path for header path and library:
/usr/local/Cellar/**
I also tried to install it another way, but still got the same issue:
brew install opencv
And adding the path to:
/usr/local/include/**
Everything seems to work since the library is detected, but import is not working because I got namespace errors in the openCV files, for instance:
No type named 'unique_ptr' in namespace 'std'
No member named 'allocator_traits' in namespace 'std'; did you mean 'allocator_arg_t'?
I checked on the internet and maybe it should be due to the the C++ language dialect or standard library, but I use GNU ++ 14 and libc++ . From what I found it should be working in that config, but I still got the issues. Do you have any ideas ?
EDIT: I don't even try to use it yet, I just used the include and print an hello:
#include <iostream>
#include "cv.h"
int main(int argc, char *argv[]){
std::cout<<"hello";
}
I also tried cv.hpp instead of cv.h, still not working
Thanks a lot !
I don't think you are using the correct #include paths, if you look at the OpenCV Example, you need the following for OpenCV 3.0 to open an image:
#include <opencv2/core/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>
None of these are like the headers that you have, which are likely for older versions.
This tutorial looks like a very sensible one to get up and running with xcode, and the example at the bottom looks like a better start

Rcpp C++11 .Call issues under Windows

I'm experiencing .Call issues when running functions built with Rcpp on Windows, if my c++ code uses C++11 std::regex and I have found no way out so far.
Unlike prior questions on similar issues, I have had neither building nor linking issues. The Rcpp package builds and links fine using the C++11 plugin, making usable packages on my platform. constexpr and C++11-specific functions like std::stoi cause no issue when std::regex is not used.
Using Windows boost libs, I experienced linking issues, even when specifying PKG_LIBS="-L/path/to/boost/libs -lboost_regex", so I'd rather stick to std::regex.
The same packages build, install and run fine under linux, using vanilla std::regex or boost::regex.
I unfortunately found no solution in the fine Rcpp gallery examples.
Windows platform is :
R version 3.2.3 (2015-12-10)
x86_64-w64-mingw32/x64 (64-bit)
Running under:
Windows >= 8 x64 (build 9200)
Rcpp_0.12.3
Rtools 3.3.0.1959 running g++ 4.9.3 (x86_64-posix-seh,
built by MinGW-W64 project), normally C++11-compatible.
PKG_CXXFLAGS="-std=c++11"
The linux platform is similar except for g++ (version 5.3).
Below is a simplified code chunk for duplication.
#include <Rcpp.h>
#if defined(__linux__) && ! defined(FORCE_STL_BUILD)
#include <boost/regex.hpp>
#define reglib boost
#else
#include <regex>
#define reglib std
#endif
#include <string>
using namespace Rcpp;
// [[Rcpp::plugins(cpp11)]]
constexpr int a[3]= {2, 10, 15};
// [[Rcpp::export]]
int my_test(int prop, const std::string& index)
{
#ifndef NO_REG
static const reglib::regex test {"H.*A", reglib::regex::icase};
#endif
int index_int = std::stoi(index) + a[1] + prop;
return index_int;
}
This code runs OK when built using -DNO_REG. Otherwise invoking test::my_test(1, "1000") returns:
`Error in .Call("test_my_test", PACKAGE = "test", prop, index) :
"test_my_test" not available for .Call() for package "test"`
EDIT:
1. The question focuses on std::regex. Boost issues are only incidental comments.
2. Issues only arise after packaging, not using Rcpp::source("cppfile")
3. Packaging code:
R console:
Rcpp::Rcpp.package.skeleton("test", attributes=TRUE, example_code=FALSE, cpp_files="test.cpp")
Rcpp::compileAttributes("test")
CMD console:
REM paths to R/bin/x64 and Rtools/bin, Rtools/mingw_64/bin added to PATH
set PKG_CXXFLAGS=-std=c++11
R CMD build test
R CMD INSTALL test_1.0.tar.gz
ADDITIONAL EDIT:
.Call issues arise as soon as a regex is declared in the C++ code. Using it or no (as in std::regex_match) makes no change.
Can you try disentangling this some more? You are mixing a lot of things here.
Try maybe 'just' C++ from R first, with the newer g++ 4.9.3 compiler and see if that lets you use Boost as you hope. Your use case there is local and non-standard, so you have to work this out. We generally just recommend using BH without linking.
I don't actually see an Rcpp issue here. You are simply pushing the (working, tested, trusted) Rcpp setup into a corner it has not been used in yet. So you may need to work some things out yourself.
Also note that g++ 4.9.3 for R is not really released yet.

Boost compilation error with python

I'm new to the boost C++ library and I'm trying to use boost with python. Whenever I compile my simple test program I get an error:
error: pyconfig.h: No such file or dirctory
(followed by thousand more errors which I'm sure are because of this missing header).
I downloaded boost from it's website and then built the library. I still have no idea why that file is missing and how to get it. Please help!
I'm using code::blocks MinGW compiler and I have pointed code blocks to the boost folder as a search directory for headers as well as libraries.
Here's my simple program:
#include <boost/python.hpp>
using namespace boost::python;
int main()
{
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print ’Today is’,ctime(time())\n");
Py_Finalize();
return 0;
}
You apparently do not have the CPython headers in your include path. Just having boost::python is not enough, you need Python itself, too.

C++ search directories and files

Can someone tell me if there is a library built in C++ that I can use to get a list of files and directories? I've looked around and I see people using dirent.h but I need to download it(i think).
Thanks
P.S. I've looked at the fstream, but thats only for reading and outputting files as far as i know.
FORGOT TO MENTION. I DO NOT WANT TO DOWNLOAD ANYTHING, I JUST WANT TO SEE IF THERE IS A LIBRARY THAT IS BUILT WITHIN C++ THAT I CAN USE STRAIGHT OFF THE BAT. THIS IS FOR WINDOWS ASWELL
How about Boost::Filesystem? Supports directory iteration and is portable.
You can use Boost Filesystem library.
http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/index.htm
Some nice samples are also provided at the link.
EDIT:
Without downloading a 3rd party library, there is no portable way to do it. For windows you can use CFileFind class from MFC.
Using namespace std::filesystem is available in visual studio 2017 you have in #include
#include <iostream>
#include <iostream>
#include <fstream>
#include <filesystem>
#include <chrono>
#include <thread>
#include <functional>
namespace fs = std::filesystem;
void Files_in_Directory();
fs::path path_Copy_Directory = "E:\Folder";
fs::path path_Paste_Directory = "E:\Folder1";
int main()
{
Files_in_Directory()
return 0;
}
void Files_in_Directory()
{
for (const auto & entry : fs::directory_iterator(path_Copy_Directory))
{
std::cout << entry.path() << std::endl;
}
}
Since others already mentioned boost::filesystem there are also other alternatives. Almost every C++ framework has some way to list directories and files. Like wxWidgets or poco and there are many more.
Regarding dirent.h. It is a standard C Posix library so on Posix compatible systems it should be available. For Windows you can also get it here and it includes instructions on how to use it.
After your edit:
On Windows you can use things like FindFirstFile (example here) and then you don't have to download anything. But it only works on Windows. It is not build in C++.