刘新明1989 2024-04-09 17:16 采纳率: 44.4%
浏览 5

在编译Python-3.0的时候出现了二个代码错误

img


错误提示代码如下:


./Modules/getbuildinfo.c: In function ‘_Py_svnversion’:
<command-line>: error: missing terminating " character
./Modules/getbuildinfo.c:48:42: note: in expansion of macro ‘SVNVERSION’
   48 |         static const char svnversion[] = SVNVERSION;
      |                                          ^~~~~~~~~~
./Modules/getbuildinfo.c:48:52: error: expected expression before ‘;’ token
   48 |         static const char svnversion[] = SVNVERSION;

python代码如下:

#include "Python.h"

#ifndef DONT_HAVE_STDIO_H
#include <stdio.h>
#endif

#ifndef DATE
#ifdef __DATE__
#define DATE __DATE__
#else
#define DATE "xx/xx/xx"
#endif
#endif

#ifndef TIME
#ifdef __TIME__
#define TIME __TIME__
#else
#define TIME "xx:xx:xx"
#endif
#endif

/* on unix, SVNVERSION is passed on the command line.
 * on Windows, the string is interpolated using
 * subwcrev.exe
 */
#ifndef SVNVERSION
#define SVNVERSION "$WCRANGE$$WCMODS?M:$"
#endif

const char *
Py_GetBuildInfo(void)
{
    static char buildinfo[50];
    const char *revision = Py_SubversionRevision();
    const char *sep = *revision ? ":" : "";
    const char *branch = Py_SubversionShortBranch();
    PyOS_snprintf(buildinfo, sizeof(buildinfo),
              "%s%s%s, %.20s, %.9s", branch, sep, revision, 
              DATE, TIME);
    return buildinfo;
};

const char *
_Py_svnversion(void)
{
    /* the following string can be modified by subwcrev.exe */
    static const char svnversion[] = SVNVERSION;
    if (svnversion[0] != '$')
        return svnversion; /* it was interpolated, or passed on command line */
    return "exported";
}

  • 写回答

5条回答 默认 最新

  • 码农阿豪@新空间 优质创作者: Java、后端开发技术领域 2024-04-09 17:16
    关注
    让阿豪来帮你解答,本回答参考chatgpt3.5编写提供,如果还有疑问可以评论或留言
    问题描述: 编译Python时出现以下错误提示: ./Modules/getbuildinfo.c: In function ‘_Py_svnversion’: : error: missing terminating " character ./Modules/getbuildinfo.c:48:42: note: in expansion of macro ‘SVNVERSION’ static const char svnversion[] = SVNVERSION; ^~~~~~~~~~ ./Modules/getbuildinfo.c:48:52: error: expected expression before ‘;’ token static const char svnversion[] = SVNVERSION; 可能原因: 1. 编译参数传递错误,导致“SVNVERSION”宏未正确展开。 2. “SVNVERSION”宏的字符串值缺少终止符。在C语言中,字符串必须以空字符“\0”作为终止符。 解决办法: 1. 检查编译时传递的参数是否正确。 2. 修改“SVNVERSION”宏的字符串值,在末尾添加空字符“\0”。 具体的修改代码如下: #ifndef SVNVERSION #define SVNVERSION "$WCRANGE$$WCMODS?M:$\0" #endif 注意,字符串末尾的双引号不需要加上空字符“\0”,因为C语言会自动在字符串末尾添加空字符。 参考代码: #ifndef SVNVERSION #define SVNVERSION "$WCRANGE$$WCMODS?M:$\0" #endif const char *Py_GetBuildInfo(void){ static char buildinfo[50]; const char *revision = Py_SubversionRevision(); const char *sep = *revision ? ":" : ""; const char *branch = Py_SubversionShortBranch(); PyOS_snprintf(buildinfo, sizeof(buildinfo), "%s%s%s, %.20s, %.9s", branch, sep, revision, DATE, TIME); return buildinfo; }; const char *_Py_svnversion(void){ /* the following string can be modified by subwcrev.exe */ static const char svnversion[] = SVNVERSION; if (svnversion[0] != '$') return svnversion; /* it was interpolated, or passed on command line */ return "exported"; }
    评论

报告相同问题?

问题事件

  • 创建了问题 4月9日