I'm trying to build this project , on Google Colab ( link to notebook ), the listed requirements are:
GCC 4.8.* Python 2.7.* Boost 1.67 OpenCV 2.4.*
the CMakeLists.txt is as follows:
cmake_minimum_required (VERSION 2.6.0)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -std=c++11")
# Head and source
include_directories(include)
AUX_SOURCE_DIRECTORY(src DIR_SRCS)
# Find necessary packages
find_package( PythonLibs 2.7 REQUIRED )
include_directories( ${PYTHON_INCLUDE_DIRS} )
find_package( Boost COMPONENTS python REQUIRED )
include_directories( ${Boost_INCLUDE_DIR} )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIR} )
# Define the wrapper library
add_library(Augment SHARED ${DIR_SRCS})
target_link_libraries(Augment ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} ${OpenCV_LIBRARIES} Augment)
# Don't prepend wrapper library name with lib
set_target_properties(Augment PROPERTIES PREFIX "" )
EDIT:with the original cmakelists I get
/usr/include/python2.7 for PYTHON_INCLUDE_DIRS ,
/usr/lib/x86_64-linux-gnu/libpython2.7.so for PYTHON_LIBRARIES
/usr/local/include for Boost_INCLUDE_DIR
Boost::python for Boost_LIBRARIES
having no experience in c ,I ran into a couple of errors during make
the first is:
fatal error: numpy/ndarrayobject.h: No such file or directory
runnung !find /usr/ -name ndarrayobject.h outputs:
/usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/ndarrayobject.h
/usr/local/lib/python3.6/dist-packages/tensorflow/include/external/local_config_python/numpy_include/numpy/ndarrayobject.h
/usr/local/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h
/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h
/usr/local/pkgs/numpy-base-1.19.2-py37hfa32c7d_0/lib/python3.7/site-packages/numpy/core/include/numpy/ndarrayobject.h
so I tried replacing this:
find_package( PythonLibs 2.7 REQUIRED )
include_directories( ${PYTHON_INCLUDE_DIRS} )
with:
set(PYTHON_INCLUDE_DIRS /usr/local/lib/python2.7)
include_directories( ${PYTHON_INCLUDE_DIRS})
which works I guess but now this error is raised:
fatal error: pyconfig.h: No such file or directory
running !find /usr/include -name pyconfig.h outputs:
/usr/include/x86_64-linux-gnu/python2.7/pyconfig.h
/usr/include/x86_64-linux-gnu/python3.6m/pyconfig.h
/usr/include/python2.7/pyconfig.h
/usr/include/python3.6m/pyconfig.h
how to solve this error ? and i'm quite sure another error will be raised when cmake fails to find opencv 2.4
you can play around with the notebook here
I'm trying to build a project using the waf build tool.
The build fails in the configure step when checking the python headers.
I narrowed the problem down to this minimal example of my wscript:
def options(ctx):
ctx.load('compiler_c')
def configure(ctx):
ctx.load('compiler_c python')
ctx.check_python_version((2,7,0))
if int(ctx.env.PYTHON_VERSION[0]) == 2:
print ('→ Configuring for python2')
else:
print ('→ Configuring for python3')
ctx.check_python_headers(features='pyext')
I use python versions (3.6.12 & 3.7.9) that I installed with pyenv on Ubuntu 20.04.
I run that like this and it fails with an error that I cannot make sense of:
$ python waf configure
Setting top to : /home/myuser/waf-test
Setting out to : /home/myuser/waf-test/build
Checking for 'gcc' (C compiler) : /usr/bin/gcc
Checking for program 'python' : /home/myuser/.pyenv/versions/3.7.9/bin/python
Checking for python version >= 2.7.0 : 3.7.9
→ Configuring for python3
python-config : /home/myuser/.pyenv/versions/3.7.9/bin/python-config
Asking python-config for pyext '--cflags --libs --ldflags' flags : yes
Testing pyext configuration : Could not build python extensions
The configuration failed
(complete log in /home/myuser/waf-test/build/config.log)
$ tail -n 20 build/config.log
[1/2] Compiling build/.conf_check_d3b505aa7ab58576b6d76a2fc3091b1f/test.c
['/usr/bin/gcc', '-fPIC', '-g', '-fwrapv', '-O3', '-I../../../../.pyenv/versions/3.7.9/include/python3.7m', '-DPYTHONDIR="/usr/local/lib/python3.7/site-packages"', '-DPYTHONARCHDIR="/usr/local/lib/python3.7/site-packages"', '-DNDEBUG', '../test.c', '-c', '-o/home/myuser/waf-test/build/.conf_check_d3b505aa7ab58576b6d76a2fc3091b1f/testbuild/test.c.1.o']
[2/2] Linking build/.conf_check_d3b505aa7ab58576b6d76a2fc3091b1f/testbuild/testprog.cpython-37m-x86_64-linux-gnu.so
['/usr/bin/gcc', '-shared', 'test.c.1.o', '-o/home/myuser/waf-test/build/.conf_check_d3b505aa7ab58576b6d76a2fc3091b1f/testbuild/testprog.cpython-37m-x86_64-linux-gnu.so', '-Wl,-Bstatic', '-Wl,-Bdynamic', '-L/home/myuser/.pyenv/versions/3.7.9/lib/python3.7/config-3.7m-x86_64-linux-gnu', '-L/home/myuser/.pyenv/versions/3.7.9/lib', '-lpython3.7m', '-lcrypt', '-lpthread', '-ldl', '-lutil', '-lm', '-lpython3.7m', '-lcrypt', '-lpthread', '-ldl', '-lutil', '-lm']
err: /usr/bin/ld: /home/myuser/.pyenv/versions/3.7.9/lib/python3.7/config-3.7m-x86_64-linux-gnu/libpython3.7m.a(pylifecycle.o): relocation R_X86_64_PC32 against symbol `Py_VerboseFlag' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
from /home/myuser/waf-test: Test does not build: Traceback (most recent call last):
File "/home/myuser/waf-test/.waf3-2.0.20-36f5354d605298f6a89c09e0c7ef6c1d/waflib/Configure.py", line 335, in run_build
bld.compile()
File "/home/myuser/waf-test/.waf3-2.0.20-36f5354d605298f6a89c09e0c7ef6c1d/waflib/Build.py", line 176, in compile
raise Errors.BuildError(self.producer.error)
waflib.Errors.BuildError: Build failed
-> task in 'testprog' failed with exit status 1 (run with -v to display more information)
Could not build python extensions
from /home/myuser/waf-test: The configuration failed
Note that this problem does not appear with python 3.8.6 that was also installed with pyenv. I can configure without errors.
My questions: How can it be that the python versions in pyenv differ in a way that waf checks fail in one version and not in another?
Since I simply install the versions with pyenv install 3.6.12, what do I need to change in the install so my build succeeds?
Well, the error is that, when creating the test program to check if pyext is correctly set, the compiler complains about the fact that pylifecycle.o included in libpython3.7m.a is non relocatable ie non compiled with the -fPIC flag.
As the code fragment generated by waf is compiled with -fPIC, it seems that the problem is that pylifecycle.o in libpython3.7m.a is not compiled with -fPIC, which makes sense as it is in a static library. Maybe the problem is that it uses the .a archive lib instead of the shared object one ie the .so.
Check if you have the shared object version of libpython ie libpython3.7m.so.
I have some project which supposed to support Win32 and x64 platform.
Some code is generated by python script.
This script uses python3 features.
In CMakeLists.txt I have something like this:
find_package(PythonInterp REQUIRED)
if (CMAKE_CL_64)
set(MY_APP_PLATFORM "x64")
else()
set(MY_APP_PLATFORM "Win32")
endif()
add_custom_command(TARGET MyApp
PRE_BUILD
COMMAND ${PYTHON_EXECUTABLE} ${MyApp_ROOT}/generator.py -p ${MY_APP_PLATFORM }
WORKING_DIRECTORY ${PATH_GENERATED_SRC}
COMMENT "Generating code..."
VERBATIM
)
Quite simple.
Now when project for x64 is used everything works like a charm, but when building for Win32 (cmake have to generate separate project) cmake finds python 2.7.2.
Changing CMakeLists.txt this way:
find_package(PythonInterp 3.7 REQUIRED)
Leads to cmake failure.
Is there way to fix it, or do I have to correct pythons script to be python2 compatible?
Or do I have to install python3 for 32 and 64 bits to cover both platforms?
The CMake Module is FindPython3.cmake in your cmake distribution.
This should work:
find_package(Python3 COMPONENTS Interpreter)
add_custom_command(TARGET MyApp
PRE_BUILD
COMMAND ${PYTHON3_EXECUTABLE} ${MyApp_ROOT}/generator.py -p ${MY_APP_PLATFORM}
WORKING_DIRECTORY ${PATH_GENERATED_SRC}
COMMENT "Generating code..."
VERBATIM
)
It is available since cmake 3.12.
Documentation
I am on MacOS 10.13.3 (17D47) with Python 2.7.14. I am in the process of building caffe w/ python. The project is CPU only. I am able to build caffe through make run test however, after attempting make pycaffe I get an error. This is the result:
touch python/caffe/proto/__init__.py
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
PROTOC (python) src/caffe/proto/caffe.proto
In file included from python/caffe/_caffe.cpp:17:
In file included from ./include/caffe/caffe.hpp:12:
./include/caffe/net.hpp:41:5: warning: unused typedef 'INVALID_REQUESTED_LOG_SEVERITY' [-Wunused-local-typedef]
LOG_EVERY_N(WARNING, 1000) << "DEPRECATED: ForwardPrefilled() "
^
/usr/local/include/glog/logging.h:943:30: note: expanded from macro 'LOG_EVERY_N'
INVALID_REQUESTED_LOG_SEVERITY); \
^
1 warning generated.
ld: library not found for -lboost_python
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [python/caffe/_caffe.so] Error 1
I have a Makefile.config that calls out boost-python from the brew install set as:
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/local/Cellar/boost-python/1.67.0/lib
My two initial questions are:
1)Am I not allowed to link to the boost library using the system python? 2)What is the correct way to tell make to grab boost-python?
I was actually having the same problem and couldn't find any answers for days. However, I found this question: Build caffe with Python ( cannot find -lboost_python3 ) .
That question is for python3, but I'm using python2.7 . Basically, I went into the Makefile (not Makefile.config), searched for boost_python, and changed it to boost_python27 . I did the following steps:
vim Makefile
use vim command :?boost_python (there should only be 1 occurrence)
changed PYTHON_LIBRARIES ?= boost_python python2.7
to PYTHON_LIBRARIES ?= boost_python27 python2.7
ran the command sudo make pycaffe
I hope this helps you!
Goto Makefile (and not the .config file) and change the name of the ld library to python27.
I am trying to install Lapack on my Windows 7 64bit to use SciPy. I have run into many different answers about this topic but I have not seen anywhere anything about this.
I am following the guide from this website: https://icl.cs.utk.edu/lapack-for-windows/lapack/ from the section "Easy Windows Build". As the site states, I need to install CMAKE, Visual Studio and download lapack. I have installed "cmake-3.5.0-rc3-win32-x86", "Visual Studio 13" and minGW with all the packages that were available (just in case).
Finally, when I open the "cmake-gui" (as administrator) to perform the steps it says to build "Lapack" and I specify my source code folder (the lapack decompressed folder "lapack-3.6.0") and my output folder (a folder in Documents) and I click the Configure button I get the following error message:
Error in configuration process, project files may be invalid
I checked the log files of cmake and this is what I get:
CMakeError.log
Compiling the Fortran compiler identification source file "CMakeFortranCompilerId.F" failed.
Compiler: C:/MinGW/bin/gfortran.exe
Build flags:
Id flags:
The output was:
The system cannot find the file specified
Checking whether the Fortran compiler is Compaq using "-what" did not match "Compaq Visual Fortran":
gfortran.exe: error: unrecognized command line option '-what'
gfortran.exe: fatal error: no input files
compilation terminated.
Checking whether the Fortran compiler is NAG using "-V" did not match "NAG Fortran Compiler":
gfortran.exe: error: unrecognized command line option '-V'
gfortran.exe: fatal error: no input files
compilation terminated.
Determining if the Fortran compiler works failed with the following output:
Change Dir: C:/Program Files (x86)/LAPACK/CMakeFiles/CMakeTmp
Run Build Command:"devenv.com" "CMAKE_TRY_COMPILE.sln" "/build" "Debug" "/project" "cmTC_249e8"
Generator: execution of make failed. Make command was: "devenv.com" "CMAKE_TRY_COMPILE.sln" "/build" "Debug" "/project" "cmTC_249e8"
CMakeOutput.log
The system is: Windows - 6.1.7601 - AMD64
Determining if the Fortran compiler is GNU succeeded with the following output:
# 1 "C:/Program Files (x86)/CMake/share/cmake-3.5/Modules/CMakeTestGNU.c"
# 1 "<command-line>"
# 1 "C:/Program Files (x86)/CMake/share/cmake-3.5/Modules/CMakeTestGNU.c"
void THIS_IS_GNU();
void THIS_IS_MINGW();
I have installed MinGW and I checked it is under the directory:
C:/MinGW
since I have also specified native compilers for CMAKE from inside the bin folder
gfortran.exe
gcc.exe
g++.exe
for Fortran, C and C++ respectively.
I checked online about the error in configuration process and from what I found out is that I need to have installed Visual Studio but I already have that.
Finally, I added the directory
C:\MinGW\bin
to the PATH variable.
Any suggestions as to why I cannot get to install LAPACK would be helpful.
Thank you