用Python编译c++项目的时候遇到“command 'gcc' failed with exit status 1”错误。
下载和更新python-dev等没有解决问题依旧报错。
终端错误详细代码如下:
skipping 'mesh_core_cython.cpp' Cython extension (up-to-date)
building 'mesh_core_cython' extension
gcc -pthread -B /home/xiong/anaconda2/compiler_compat -Wl,--sysroot=/ -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/xiong/.local/lib/python2.7/site-packages/numpy/core/include -I/home/xiong/anaconda2/include/python2.7 -c mesh_core_cython.cpp -o build/temp.linux-x86_64-2.7/mesh_core_cython.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
In file included from /home/xiong/.local/lib/python2.7/site-packages/numpy/core/include/numpy/ndarraytypes.h:1821:0,
from /home/xiong/.local/lib/python2.7/site-packages/numpy/core/include/numpy/ndarrayobject.h:18,
from /home/xiong/.local/lib/python2.7/site-packages/numpy/core/include/numpy/arrayobject.h:4,
from mesh_core_cython.cpp:627:
/home/xiong/.local/lib/python2.7/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it by " \
^
gcc -pthread -B /home/xiong/anaconda2/compiler_compat -Wl,--sysroot=/ -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/xiong/.local/lib/python2.7/site-packages/numpy/core/include -I/home/xiong/anaconda2/include/python2.7 -c mesh_core.cpp -o build/temp.linux-x86_64-2.7/mesh_core.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
mesh_core.cpp: In function ‘void _write_obj_with_colors_texture(std::__cxx11::string, std::__cxx11::string, float*, int*, float*, float*, int, int, int)’:
mesh_core.cpp:349:31: error: no matching function for call to ‘std::basic_ofstream
ofstream obj_file(filename);
^
In file included from mesh_core.h:9:0,
from mesh_core.cpp:11:
/usr/include/c++/5/fstream:697:7: note: candidate: std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits
basic_ofstream(const char* __s,
^
/usr/include/c++/5/fstream:697:7: note: no known conversion for argument 1 from ‘std::__cxx11::string {aka std::__cxx11::basic_string
/usr/include/c++/5/fstream:682:7: note: candidate: std::basic_ofstream<_CharT, _Traits>::basic_ofstream() [with _CharT = char; _Traits = std::char_traits
basic_ofstream(): __ostream_type(), _M_filebuf()
^
/usr/include/c++/5/fstream:682:7: note: candidate expects 0 arguments, 1 provided
/usr/include/c++/5/fstream:656:11: note: candidate: std::basic_ofstream
class basic_ofstream : public basic_ostream<_CharT,_Traits>
^
/usr/include/c++/5/fstream:656:11: note: no known conversion for argument 1 from ‘std::__cxx11::string {aka std::__cxx11::basic_string
error: command 'gcc' failed with exit status 1
发现错误是我自己c++的版本过低导致gcc编译报错。解决办法:
修改了代码中调用ofstream obj_file(filename)的地方,改成ofstream obj_file(filename.c_str()) 问题解决。
怎么找代码中调用的地方,我是直接把#include
完毕。