【问题标题】:Error: format not a string literal and no format arguments [-Werror=format-security]错误:格式不是字符串文字,也没有格式参数 [-Werror=format-security]
【发布时间】:2016-11-14 19:28:38
【问题描述】:

在 ubuntu 上安装 4suite.xml 时出现此错误。尝试在我的 ubuntu 上安装 harpia,但我的系统中缺少几个软件包,所以在获取那些缺少的依赖项时,我坚持了这一点。

username@ubuntu:~/4Suite-XML-1.0.2$ sudo python setup.py install
running install
running build
running config
running build_py
running build_ext
building 'Ft.Xml.Lib.cStreamWriter' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c Ft/Xml/src/StreamWriter.c -o build/temp.linux- x86_64-2.7/Ft/Xml/src/StreamWriter.o
In file included from /usr/include/python2.7/Python.h:94:0,
             from Ft/Xml/src/StreamWriter.c:14:
Ft/Xml/src/StreamWriter.c: In function ‘writer_print’:
/usr/include/python2.7/stringobject.h:91:32: error: format not a string literal and no format arguments [-Werror=format-security]
 #define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)
                            ^ 
 Ft/Xml/src/StreamWriter.c:605:15: note: in expansion of macro   ‘PyString_AS_STRING’
 fprintf(fp, PyString_AS_STRING(repr));
           ^


Ft/Xml/src/StreamWriter.c: In function ‘entitymap_print’:
/usr/include/python2.7/stringobject.h:91:32: error: format not a string    literal and no format arguments [-Werror=format-security]
#define PyString_AS_STRING(op) (((PyStringObject *)(op))->ob_sval)
                            ^
Ft/Xml/src/StreamWriter.c:815:15: note: in expansion of macro  ‘PyString_AS_STRING’
fprintf(fp, PyString_AS_STRING(repr));
           ^

cc1: some warnings being treated as errors

你能帮我弄清楚吗?

【问题讨论】:

    标签: python xml


    【解决方案1】:

    尝试使用以下代码可能会有所帮助:

    fprintf(fp, "%s", PyString_AS_STRING(repr));
    

    线索来自fprintf, error: format not a string literal and no format arguments [-Werror=format-security]How to fix this compiler error 'format not a string literal and no format arguments'以及deploying python codes中的类似情况

    【讨论】:

    • 当我在 fedora 23 x86_64 中安装 wxPython 2.8.12.1 时,我遇到了类似的问题。我将源代码中出现的PyErr_Format(PyExc_RuntimeError, mesg);更改为PyErr_Format(PyExc_RuntimeError, "%s", mesg);。它对我有用。
    【解决方案2】:

    对我来说,一个快速而肮脏的解决方法是设置 CFLAGS 以使用 -Wno-error=format-security 覆盖 -Werror=format-security(CenTOS 上的 python 2):

    wget  https://files.pythonhosted.org/packages/0e/ae/3c5b4fffb12be7c3a80c99475853349e1cf8477f99051921ea06fbf5e3b9/4Suite-XML-1.0.2.tar.gz
    tar -xvf 4Suite-XML-1.0.2.tar.gz
    export CFLAGS=" -Wno-error=format-security" # no error will be generated, you know what you do
    python2  ./setup.py install # 4Suite-XML compilation works without error
    

    【讨论】:

      猜你喜欢
      • 2013-06-20
      • 2013-08-25
      • 2014-12-23
      • 1970-01-01
      • 2010-12-13
      • 2011-05-24
      • 2011-08-12
      • 1970-01-01
      • 2015-01-27
      相关资源
      最近更新 更多