python编译出1error

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python编译出1error相关的知识,希望对你有一定的参考价值。

参考技术A 用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<char>::basic_ofstream(std::__cxx11::string&)’
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<char>; std::ios_base::openmode = std::_Ios_Openmode]
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<char>’ to ‘const char*’
/usr/include/c++/5/fstream:682:7: note: candidate: std::basic_ofstream<_CharT, _Traits>::basic_ofstream() [with _CharT = char; _Traits = std::char_traits<char>]
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<char>::basic_ofstream(const std::basic_ofstream<char>&)
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<char>’ to ‘const std::basic_ofstream<char>&’
error: command 'gcc' failed with exit status 1

发现错误是我自己c++的版本过低导致gcc编译报错。解决办法:
修改了代码中调用ofstream obj_file(filename)的地方,改成ofstream obj_file(filename.c_str()) 问题解决。

怎么找代码中调用的地方,我是直接把#include <fstream>屏蔽掉,然后编译程序,程序会报错,然后就直接修改。

VS2015+OpenGL4.0开发编译时弹出错误:glaux.lib(tk.obj) : error LNK2019: 无法解析的外部符号 _sscanf,该符号在函数 _GetRegistrySy

一、问题描述:

VS2015+OpenGL4.0开发编译时弹出如下所示的错误:

1>glaux.lib(tk.obj) : error LNK2019: 无法解析的外部符号 _sscanf,该符号在函数 [email protected] 中被引用

1>glaux.lib(tk.obj) : error LNK2019: 无法解析的外部符号 _vsprintf,该符号在函数 _PrintMessage 中被引用

二、问题原因:

VS2015默认编译时将许多标准库采用内联方式处理,因而没有可以链接的标准库文件,所以要专门添加标准库文件来链接标准库中的函数

三、解决办法:

1、VS2015编译会出现这个问题,解决办法在项目属性->链接器->输入->附加依赖项中添加依赖项 legacy_stdio_definitions.lib

2、在报错的*.c文件中代码开头添加:#pragma comment(lib, "legacy_stdio_definitions.lib")

以上是关于python编译出1error的主要内容,如果未能解决你的问题,请参考以下文章

Makefile编译时怎么打印出变量值

Windows下怎样编译出可在Linux上执行的程序

python能开发出exe电脑软件吗?golang编程可开发出APK安卓应用?不用安装的程序叫啥

如何利用Python打造出适合自己的定制化Eclipse IDE

20190131 经验总结:如何从rst文件编译出自己的sqlalchemy的文档

eclipse打开python文件出问题了