Issue including std::vector to cython - vector

I have a problem importing the vector class to cython using
from libcpp.vector cimport vector
when I add this and try to compile the pyx file I get
python setup.py build_ext --inplace
running build_ext
skipping 'kmc_cy.c' Cython extension (up-to-date)
building 'kmc_cy' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -fPIC -I/usr/include/python2.7 -c kmc_cy.c -o build/temp.linux-x86_64-2.7/kmc_cy.o
kmc_cy.c:254:18: fatal error: vector: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
Here is my setup.py
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import sys
sys.path.append("/usr/lib64/python2.7/site-packages/Cython/Includes/libcpp")
ext_modules = [Extension("kmc_cy", ["kmc_cy.pyx"])]
setup(
name = 'kmc_cy',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules,
)
Cheers

As std::vector is C++ code, you need to set the correct language:
ext_modules = [Extension("kmc_cy", ["kmc_cy.pyx"],language='c++')]
Then g++ should be used instead of gcc and the file name should end with .cpp or .cc.
See this answer for more details.

Related

Linux issue happens on Windows? "fatal error: fftw3.h: No such file or directory"

I am running MRO 3.5.0 on Win10, and trying to install a package image.CannyImage from bnosac/image on the github. But it keeps reporting fatal errors as following.
* installing *source* package 'image.CannyEdges' ...
** libs
c:/Rtools/mingw_64/bin/g++ -m64 -I"C:/PROGRA~1/MICROS~1/ROPEN~1/R-35~1.0/include" -DNDEBUG -I"C:/Users/eric1/Documents/R/win-library/3.5/Rcpp/include" -I"C:/swarm/workspace/External-R-3.5.0/vendor/extsoft/include" -O2 -Wall -mtune=core2 -c RcppExports.cpp -o RcppExports.o
c:/Rtools/mingw_64/bin/gcc -m64 -I"C:/PROGRA~1/MICROS~1/ROPEN~1/R-35~1.0/include" -DNDEBUG -I"C:/Users/eric1/Documents/R/win-library/3.5/Rcpp/include" -I"C:/swarm/workspace/External-R-3.5.0/vendor/extsoft/include" -O2 -Wall -std=gnu99 -mtune=core2 -c adsf.c -o adsf.o
c:/Rtools/mingw_64/bin/g++ -m64 -I"C:/PROGRA~1/MICROS~1/ROPEN~1/R-35~1.0/include" -DNDEBUG -I"C:/Users/eric1/Documents/R/win-library/3.5/Rcpp/include" -I"C:/swarm/workspace/External-R-3.5.0/vendor/extsoft/include" -O2 -Wall -mtune=core2 -c rcpp_canny.cpp -o rcpp_canny.o
In file included from rcpp_canny.cpp:13:0:
canny.h:8:19: fatal error: fftw3.h: No such file or directory
#include <fftw3.h>
^
compilation terminated.
make: *** [C:/PROGRA~1/MICROS~1/ROPEN~1/R-35~1.0/etc/x64/Makeconf:215: rcpp_canny.o] Error 1
ERROR: compilation failed for package 'image.CannyEdges'
* removing 'C:/Users/eric1/Documents/R/win-library/3.5/image.CannyEdges'
In R CMD INSTALL
Installation failed: Command failed (1)
^
compilation terminated.
Google says I can solve the issue by sudo apt-get remove libfftw3-dev. Unfortunately, I am on Windows, and some advised, apply lib /machine:i386 /def:libfftw3-3.def on cmd mode. Ouch, there is no such command or file called lib.exe on Win10.
Please advise, how I can solve this issue on my Win10+MRO system. Thanks.
Even though this question is already a bit old:
By now (Feb 2020) there are precompiled packages available that work also under Windows:
Canny Edges - Package
and more general:
List of all available packages
I have tried installing them and (at least for me) it worked.

R gputools: gcc: error: unrecognized command line option ‘-Wp’

I had an error when I install gputools in R, and I cannot find any solution by google.
I use command install.packages("gputools")
/usr/local/cuda/bin/nvcc -c -Xcompiler "-fpic -I/usr/local/include -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic" -I. -I"/usr/local/cuda/include" -I"/usr/lib64/R/include" rinterface.cu -o rinterface.o
gcc: error: unrecognized command line option ‘-Wp’
make: *** [rinterface.o] Error 1
ERROR: compilation failed for package ‘gputools’
Can someone help me here? My gpu cards is given by
01:00.0 VGA compatible controller: NVIDIA Corporation GM107GL [Quadro K620] (rev a2)
Ok, I got this working with a couple hacks. This is for centos 7.
First issue was solved by looking at the mailing list. https://github.com/nullsatz/gputools/issues/12
Edit the Makefile, and Modify line 'CFLAGS : put '\' after 'Wp' & before ','
CFLAGS = -O2 -g -pipe -Wall -Werror=format-security -Wp\,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic
Second problem was that the R shared lib was not being found. I tried setting the LD_LIBRARY_PATH in the driver configuration file, and on the command line, but that did not work.
I ended up with the following hack:
cd /usr/local/cuda/lib64 && ln -s /usr/lib64/R/lib/libR.so libR.so
I used the command following to build (note the tar.gz file now contains the modified Makefile)
R CMD INSTALL --configure-args="--with-nvcc=/usr/local/cuda/bin/nvcc --with-r-lib=/usr/lib64/" ./gputools_1.0.tar.gz
I know this is ugly, but it seems to work.
It seems that your makefile has a typo
-Wp,-D_FORTIFY_SOURCE=2
Specifically, the comma (',') should be a space (' ') only.
Please try that and report back letting us know what happened

building a mapnik 2.2.0 RPM on RHEL 7

I am trying to build a mapnik 2.2.0 RPM file on my RHEL/CENTOS 7 machine.
so I took the RPM SRC file from Fedora 22 which is mapnik-2.2.0-11.fc21.src.rpm ( I have the same result with mapnik-2.2.0-5.fc20.src.rpm )
when I am running the rpmbuild I receive the following error message:
Welcome to Mapnik...
scons: warning: Ignoring missing SConscript 'deps/agg/build.py'
File "/root/rpmbuild/BUILD/mapnik-v2.2.0/SConstruct", line 1799, in <module>
scons: warning: Ignoring missing SConscript 'deps/mapnik/build.py'
File "/root/rpmbuild/BUILD/mapnik-v2.2.0/SConstruct", line 1808, in <module>
scons: done reading SConscript files.
scons: Building targets ...
g++ -o bindings/python/mapnik_building_symbolizer.os -c -ansi -Wall -pthread -ftemplate-depth-300 -O3 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fno-strict-aliasing -finline-functions -Wno-inline -Wno-parentheses -Wno-char-subscripts -fPIC -DHAVE_JPEG -DMAPNIK_USE_PROJ4 -DHAVE_PNG -DHAVE_TIFF -DBIGINT -DBOOST_REGEX_HAS_ICU -DLINUX -DMAPNIK_THREADSAFE -DNDEBUG -DHAVE_CAIRO -DHAVE_PYCAIRO -I. -Iinclude -I/usr/include/polyclipping -I/usr/include/agg2 -I/usr/include -I/usr/include/freetype2 -I/usr/include/libxml2 -I/usr/include/gdal -I/usr/include/python2.7 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/libpng15 -I/usr/include/libdrm -I/usr/include/pycairo bindings/python/mapnik_building_symbolizer.cpp
In file included from include/mapnik/symbolizer.hpp:29:0,
from include/mapnik/building_symbolizer.hpp:29,
from bindings/python/mapnik_building_symbolizer.cpp:26:
include/mapnik/image_compositing.hpp:74:19: error: 'comp_op_grain_merge' is not a member of 'agg'
grain_merge = agg::comp_op_grain_merge,
^
include/mapnik/image_compositing.hpp:75:21: error: 'comp_op_grain_extract' is not a member of 'agg'
grain_extract = agg::comp_op_grain_extract,
^
scons: *** [bindings/python/mapnik_building_symbolizer.os] Error 1
scons: building terminated because of errors.
error: Bad exit status from /var/tmp/rpm-tmp.kuI6KW (%build)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.kuI6KW (%build)
Mapnik normally comes with a heavily patched version of the AGG library right there in its source tree. The Fedora build however disables that in favour of having the Mapnik-AGG patches directly in its own AGG package (because they don't like duplicating system libraries elsewhere).
You either need an AGG library for CentOS that is feature-compatible with the patched Fedora version, or you have to modify your Mapnik build to disable the "system_agg" patch (and drop the "rm -rf boost deps" from the spec file).

Unable to install pyrocksdb against RocksDB master

I followed the instructions from here: http://pyrocksdb.readthedocs.org/en/latest/installation.html
When I try pip install git+git://github.com/stephan-hof/pyrocksdb.git I get the following output with error:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.4
creating build/lib.linux-x86_64-3.4/rocksdb
copying rocksdb/__init__.py -> build/lib.linux-x86_64-3.4/rocksdb
copying rocksdb/interfaces.py -> build/lib.linux-x86_64-3.4/rocksdb
copying rocksdb/errors.py -> build/lib.linux-x86_64-3.4/rocksdb
creating build/lib.linux-x86_64-3.4/rocksdb/tests
copying rocksdb/tests/__init__.py -> build/lib.linux-x86_64-3.4/rocksdb/tests
copying rocksdb/tests/test_db.py -> build/lib.linux-x86_64-3.4/rocksdb/tests
copying rocksdb/tests/test_options.py -> build/lib.linux-x86_64-3.4/rocksdb/tests
running egg_info
creating pyrocksdb.egg-info
writing dependency_links to pyrocksdb.egg-info/dependency_links.txt
writing top-level names to pyrocksdb.egg-info/top_level.txt
writing requirements to pyrocksdb.egg-info/requires.txt
writing pyrocksdb.egg-info/PKG-INFO
writing manifest file 'pyrocksdb.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
reading manifest file 'pyrocksdb.egg-info/SOURCES.txt'
writing manifest file 'pyrocksdb.egg-info/SOURCES.txt'
copying rocksdb/_rocksdb.cpp -> build/lib.linux-x86_64-3.4/rocksdb
running build_ext
building 'rocksdb._rocksdb' extension
creating build/temp.linux-x86_64-3.4
creating build/temp.linux-x86_64-3.4/rocksdb
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/home/iulian/py3env/include -I/usr/include/python3.4m -c rocksdb/_rocksdb.cpp -o build/temp.linux-x86_64-3.4/rocksdb/_rocksdb.o -std=gnu++11 -O3 -Wall -Wextra -Wconversion -fno-strict-aliasing
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++ [enabled by default]
rocksdb/_rocksdb.cpp:289:27: fatal error: rocksdb/slice.h: No such file or directory
#include "rocksdb/slice.h"
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Command "/home/iulian/py3env/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip-mndoekm3-build/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-3fwa2_ff-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/iulian/py3env/include/site/python3.4" failed with error code 1 in /tmp/pip-mndoekm3-build
I tried to checkout various versions of RocksDB (3.5, 3.6, 3.8, 3.9) and still no luck.
I am using Python 3.4 on a 64 bit Ubuntu 14.04.
You have to check that Cython==0.20 is installed! I had the same issue and that solved it!

github_install & R CMD INSTALL fails for videoplayR

I was trying to install the package videoplayR from github but failed to do the same. I tried two ways:
1. Using the installation guidance mentioned in README file.It gave the following error:
> install_github("sjmgarnier/videoplayR")
Downloading github repo sjmgarnier/videoplayR#master
Error in function (type, msg, asError = TRUE) :
2. Using R CMD SHLIB etc gives the following error while running R CMD check. It is a part of the install.out file:
* installing source package ‘videoplayR’ ...
** libs
g++ -I/usr/share/R/include -DNDEBUG -I"/home/nandy/R/x86_64-pc-linux-gnu-library/3.1/Rcpp/include" -I"/home/nandy/R/x86_64-pc-linux-gnu-library/3.1/RcppArmadillo/include" pkg-config --cflags opencv Rscript -e <p>'Rcpp:::CxxFlags()' -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c RcppExports.cpp -o RcppExports.o
g++ -I/usr/share/R/include -DNDEBUG -I"/home/nandy/R/x86_64-pc-linux-gnu-library/3.1/Rcpp/include" -I"/home/nandy/R/x86_64-pc-linux-gnu-library/3.1/RcppArmadillo/include" pkg-config --cflags opencv Rscript -e <p>'Rcpp:::CxxFlags()' -fpic -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -c Video.cpp -o Video.o
Video.cpp: In member function ‘double Video::current_frame()’:
Video.cpp:42:25: error: ‘CV_CAP_PROP_POS_FRAMES’ was not declared in this scope
return(inputVideo.get(CV_CAP_PROP_POS_FRAMES));
^
Video.cpp: In member function ‘void Video::set_current_frame(int)’:
Video.cpp:46:18: error: ‘CV_CAP_PROP_POS_FRAMES’ was not declared in this scope
inputVideo.set(CV_CAP_PROP_POS_FRAMES, n);
^
Video.cpp: In member function ‘void Video::next_frame_cv()’:
Video.cpp:63:22: error: ‘CV_CAP_PROP_POS_FRAMES’ was not declared in this scope
if (inputVideo.get(CV_CAP_PROP_POS_FRAMES) == inputVideo.get(CV_CAP_PROP_FRAME_COUNT)) {
^
Video.cpp:63:64: error: ‘CV_CAP_PROP_FRAME_COUNT’ was not declared in this scope
if (inputVideo.get(CV_CAP_PROP_POS_FRAMES) == inputVideo.get(CV_CAP_PROP_FRAME_COUNT)) {
^
Video.cpp: In member function ‘void Video::get_frame_cv(int)’:
Video.cpp:76:27: error: ‘CV_CAP_PROP_FRAME_COUNT’ was not declared in this scope
if (n > inputVideo.get(CV_CAP_PROP_FRAME_COUNT)) {
^
Video.cpp:80:18: error: ‘CV_CAP_PROP_POS_FRAMES’ was not declared in this scope
inputVideo.set(CV_CAP_PROP_POS_FRAMES, n);
^
Video.cpp: In member function ‘int Video::length()’:
Video.cpp:91:25: error: ‘CV_CAP_PROP_FRAME_COUNT’ was not declared in this scope
return(inputVideo.get(CV_CAP_PROP_FRAME_COUNT));
^
I am guessing problem 2 is occurring due to version problem of OpenCV. Am I right? Is there any way out of this?
Looks similar to these 2 reported problems: https://github.com/hadley/devtools/issues/650 and https://github.com/hadley/devtools/issues/467. It seems that you need to update your system (Linux I presume) to the latest version of Curl.
I believe this is my fault. I forgot to exclude the compiled shared object videoplayR.so last time I committed changes to the GitHub repo. If you're using a different OS than mine (OSX Yosemite), it is most certainly the cause of the problem that you encountered. I fixed it and now it should compile nicely on your computer as well.
FYI I compiled and ran the package with both OpenCV 2.4.9 and 2.4.10, but it should work with any 2.4.X version of OpenCV (never tried the latest OpenCV 3.0 beta).

Resources