错误:格式不是字符串文字而没有格式参数[-Werror = format-security]

时间:2016-11-14 19:28:38

标签: python xml

我在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
你可以帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

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

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

中的类似情况

答案 1 :(得分:0)

对我来说一个快速而肮脏的解决方法是将 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