Error in building boost:python code - c++

I've the following boost:python code(gona.cpp).
#include <iostream>
using namespace std;
void say_hello(const char* name) {
cout << "Hello " << name << "!\n";
}
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(hello)
{
def("say_hello", say_hello);
}
int main(){
return 0;
}
I have boost 1.47(boost pro) installed in my system(Windows 7 32-bit).
I used Microsoft Visual Studio 2010 to build this and it has been built successfully. But I want to use this in a python code (as an import). I have the following piece of code (setup.py) to build this into a python module.
from distutils.core import setup
from distutils.extension import Extension
setup(name="PackageName",
ext_modules=[
Extension("hello", ["gona.cpp"],
libraries = ["boost_python", "boost"])
])
"gona" is the file C++ file name. I used the following command to build this in the command line.
python setup.py build
After I do this, I get the following error.
>python setup.py build
running build
running build_ext
building 'hello' extension
C:\MinGW\bin\gcc.exe -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c De
cision_Tree.cpp -o build\temp.win32-2.7\Release\gona.o
gona.cpp:9:35: fatal error: boost/python/module.hpp: No such file or di
rectory
compilation terminated.
error: command 'gcc' failed with exit status 1
It seems the boost installation I have in my system works only on Visual studio(as it had been built successfully). I've run other boost programs without problems in Visual studio.
How do I build this as a python module, so that it can be imported in python code?. (Using command line or Visual studio)

Several things here:
You can also build a Python module using VS2010 directly, just set the output path to foo.pyd instead of foo.dll.
setup.py seems to use MinGW, maybe you can convince it to use the working VS2010 setup instead?
You can use "-I" to inform GCC about include paths, see the GCC documentation. I'm not sure how to tell setup.py where it should look for include paths though, but you should be able to locate that documentation easily.
It looks like setup.py is trying to compile as C code ("gcc.exe" instead of "g++.exe"), which could cause further problems.
Your code has a main() function, which is not required in a DLL (binary Python modules are effectively DLLs).

Related

Rcpp project clean and rebuild

I'm trying to build the sample hello world file that comes by default when an Rcpp package project is created in RStudio on Mac.
I'm using latest version of RStudio (Version 1.3.959) and R (4.0.2). The clang version is 11.0.3 and have the command line tools installed.
Unlike the expected compile output of rcpp_hello_world.cpp to create .o objects I see that in my project, RStudio uses R and tries to byte-compile, avoiding the C compilation.
I also updated the Makeconf for gnu++17
(CXX = clang++ -mmacosx-version-min=10.13 -std=gnu++17)
I haev installed Rcpp, RcppEigen and BH packages and created a new Rcpp project and I updated the NAMESPACE file to recognize the Rcpp tags for interface functions.
Here is the output I got:
==> Rcpp::compileAttributes()
* Updated R/RcppExports.R
==> R CMD INSTALL --preclean --no-multiarch --with-keep.source RcppPackage003a
* installing to library ‘/Users/username/Library/R/4.0/library’
* installing *source* package ‘RcppPackage003a’ ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
Error: package or namespace load failed for ‘RcppPackage003a’ in library.dynam(lib, package, package.lib):
shared object ‘RcppPackage003a.so’ not found
Error: loading failed
Execution halted
Any pointers on what I could be doing wrong and why it's not trying to compile the src files?
As a quick Rcpp install test I was able to call a C++ function from R (referring this doc - http://heather.cs.ucdavis.edu/Rcpp.pdf)
by sourcing a test cpp file with following function -
#include <Rcpp.h>
// [[Rcpp::export]]
void hello()
{
Rprintf("Hello, world!\n");
}
and then in R console calling the hello function after sourcing the cpp file:
library(Rcpp)
sourceCpp("hello.cpp")
hello()
How can I debug the missing link where it is not picking up the cpp file to be compiled?
Thanks in advance!

Issue running SDL Cpp based applicaton

I Have never used SDL and have not coded in C/C++ this last 4 years so I m rusty somehow.
I have found an interesting project on github and I want to run it.
I have a kali linux distribution,
First I installed DotNet that I believe is fine since calling DotNet from terminal gives response from the console tool. I also installed CMake.
Then I successfully installed SDL2 using the vcpkg tool. the compiler is recognizing all the sources dependencies.
But when I run the app I m getting this prompt error
[Running] cd "/opt/workspaces/dvr/sdl/Media-Player/" && g++ main.cpp -o main && "/opt/workspaces/dvr/sdl/Media-Player/"main
In file included from main.cpp:1:
Core.h:8:10: fatal error: SDL2/SDL.h: No such file or directory
8 | #include "SDL2/SDL.h"
| ^~~~~~~~~~~~
compilation terminated.
My sdl2 headers are located on the vcpkg folder in /opt/workspaces/dvr/vcpkg/packages/sdl2_x64-linux/include/SDL2
What should I do to fix this

linking of C++ and Python with BOOST; error = rule "Copyright" unknown in module "xml"

I am trying to execute linking of C++ and Python with BOOST.
Using the example from https://www.boost.org/doc/libs/1_63_0/libs/python/doc/html/tutorial/tutorial/hello.html#tutorial.hello.let_s_jam, and issuing bjam at ~/libs/python/example/tutorial/ which contains these files:
hello.cpp hello.py Jamfile
The read-out from the console error is:
/home/benjamin/boost/boost_1_71_0/tools/build/src/tools/types/xml.jam:12:
in load ERROR: rule "Copyright" unknown in module "xml".
Here is what I undertook to solve this problem:
I built boost from boost_1_71_0.tar.bz2 using the ./b2 file in the directory /boost/boost_1_71_0/ which is dated November 14, 2019.
My Ubuntu 18.04 system has a b2 link at /usr/bin/b2 -> bjam, which is older (March 6, 2018) and the bjam file (March 6, 2018).
No other bjam files exist on the system.
From bjam for boost 1.54, I tried:
sudo-apt install bjam
error: E: Package 'bjam' has no installation candidate.
All the programs in the user-config.jam file (e.g., c++, msvc/code, python3) are correct, which is located in my /home/benjamin/boost/boost_1_71_0/tools/build/example/.
For pity's sake and to help me (newbie), please advise.
Looking at error message it seems that error is with file /home/benjamin/boost/boost_1_71_0/tools/build/src/tools/types/xml.jam
I checked with my local installation (which is boost 1.65.1), but I am not able to locate any file with name xml.jam. But I have few other .jam file at location /usr/share/boost-build/src/tools/types/. As example
asm.jam
# Copyright Craig Rodrigues 2005. Distributed under the Boost
# Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
type ASM : s S asm ;
So it seems that your xml.jam either invalid OR few lines should be commented (as in above file).
Try below options.
Check your xml.jam, if there are any content which are not related jam then you should comment out information.
Rename your xml.jam to xml.jam.bkp. This file may not be needed.(Not needed in my case with boost 1.65.1)
Try to install everything from Ubuntu package manager and use that. You can install all boost module by sudo apt install libboost-all-dev. I tried https://github.com/boostorg/python/tree/develop/example code with my local installed boost (1.65.1) from package manager and it work fine.

Compiling native node addon with c++ 17 inside fails during npm install on ubuntu

I have native add-on for nodejs that uses c++17 features, specifically "shared_mutex".
When I call npm install which downloads and compiles the add-on i get an error:
The linux machine has GCC 6.0 installed.
My Binding.gyp uses the following config to catch os type and add flags accordingly:
'conditions': [
['OS=="linux"', {
'CXXFLAGS': [
'-std=c++1z'
]}],
** i've also tried with '-std=c++17', '-std=c++1z'.
What am I missing?
Update:
1. Updated ubuntu 16.04 to GCC 16.04 and made it default.
2. It seems that when i try to compile it manualy using node-gyp rebuild "CXXFLAGS='-std=c++17'" it works and brings only one error:
"shared_,utex in namespace std does not name a type std::shared_mutex file mutex" (the last error)
Problem solved. For anyone who has the same issue, bind.gyp should use cflags_cc instead of cxxflags.

Error: Compiling Boost with MPI Support in Windows

I am trying to compile a 64 bit version of Boost 1.57 (www.boost.org) from source with MPI support using Microsoft Visual Studio 2015, but I am having errors. I am following the directions on the following website (https://gist.github.com/UnaNancyOwen/d879a41710e9c05025f8#file-boost1-56-0-md). I have followed the instructions to the letter, but I am (instead) running the following command to build:
C:\boost_1_57_0>b2.exe toolset = msvc-14.0 address-model = 64 --build-dir = build \ x64 install --prefix = "C: \ Program Files \ Boost" -j4
With the following error:
C:/boost_1_57_0/tools/build/src/tools\mpi.jam:251: syntax error at argument $(cluster_pack_path_native)
C:/boost_1_57_0/tools/build/src/tools\mpi.jam:252: syntax error at keyword {
libs\graph_parallel\build\Jamfile.v2:17: in modules.load
ERROR: rule "mpi.configured" unknown in module "Jamfile<C:\boost_1_57_0\libs\graph_parallel\build>".
C:/boost_1_57_0/tools/build/src/build\project.jam:311: in load-jamfile
C:/boost_1_57_0/tools/build/src/build\project.jam:64: in load
C:/boost_1_57_0/tools/build/src/build\project.jam:89: in load-used-projects
C:/boost_1_57_0/tools/build/src/build\project.jam:75: in load
C:/boost_1_57_0/tools/build/src/build\project.jam:145: in project.find
C:/boost_1_57_0/tools/build/src\build-system.jam:535: in load
C:\boost_1_57_0\tools\build\src/kernel\modules.jam:289: in import
C:\boost_1_57_0\tools\build\src/kernel/bootstrap.jam:139: in boost-build
C:\boost_1_57_0\boost-build.jam:17: in module scope
Any thoughts? The goal is to get the C++ Point Cloud Library (PCL) to work for VS 2015. I have Windows 8. Let me know if you need any more details...