gpt4 book ai didi

android - C 宏编译错误(AOSP : external/clearsilver/util/neo_err. h)

转载 作者:行者123 更新时间:2023-11-30 19:35:11 28 4
gpt4 key购买 nike

我在 C 语言中遇到了一个编译错误,涉及宏,这让我抓狂。这不是我的代码,而是广泛使用的库的一部分。我会告诉你背景故事,因为我知道别人会问我。

我正在尝试通过 GNU Make v.3.81 在 Ubuntu v.16.04 上为 Droid v.2.3 构建 Android 开源项目 (AOSP)。我遇到了许多错误,这些错误都与这个主要错误有关:

external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)

据“Ask Ubuntu”上的这个人说,他在安装 libswitch-perl 后遇到了这个问题:

https://askubuntu.com/questions/830569/external-clearsilver-util-neo-err-h8869-error-expected-expression-before

这似乎是一个非常奇怪的原因!我以前从未编译过 AOSP,所以我无法做出类似的声明。无论如何,我没有安装它。

dpkg-query: package 'libswitch-perl' is not installed and no information is available

忽略来源以外的任何内容,让我们深入了解更多细节。这是相关的clearsilver代码:

#if defined(USE_C99_VARARG_MACROS)
#define nerr_raise(e,f,...) \
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
#elif defined(USE_GNUC_VARARG_MACROS)
#define nerr_raise(e,f,a...) \
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,##a)
#endif

NEOERR *nerr_raisef (const char *func, const char *file, int lineno,
NERR_TYPE error, const char *fmt, ...)
ATTRIBUTE_PRINTF(5,6);

错误发生在行上:

nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)

我厌倦了将宏定义移到 nerr_raisef 函数定义之后,但这没有效果。我还尝试了这些行(插入到失败的行之前),以帮助找到问题:

#define mytest1 __PRETTY_FUNCTION__
#define myitest2 __FILE__
#define mytest3 __LINE__
#define mytest4(...) __VA_ARGS__
#define mytest5(e,f) nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f)
#define mytest6(e,f,...) nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f)
#define mytest7(e,f,...) nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
#define mytest8(e,f,...) \
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)

#ifdef nerr_raise
x
#endif

这些都没有问题。请注意,mytest8 宏是完全相同的该死的东西,具有不同的名称,并且可以编译!此外,松散的 x 不会被包含在内,即 nerr_raise 之前没有定义。

这是我运行 make 时得到的完整输出:

============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=2.3.4
TARGET_PRODUCT=imx53_smd
TARGET_BUILD_VARIANT=user
TARGET_SIMULATOR=false
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
HOST_ARCH=x86
HOST_OS=linux
HOST_BUILD_TYPE=release
BUILD_ID=GRJ22
============================================
build/core/main.mk:303: implicitly installing apns-conf_sdk.xml
find: ‘frameworks/base/frameworks/base/docs/html’: No such file or directory
find: ‘out/target/common/docs/gen’: No such file or directory
find: ‘frameworks/base/frameworks/base/docs/html’: No such file or directory
find: ‘out/target/common/docs/gen’: No such file or directory
find: ‘frameworks/base/frameworks/base/docs/html’: No such file or directory
find: ‘out/target/common/docs/gen’: No such file or directory
find: ‘frameworks/base/frameworks/base/docs/html’: No such file or directory
find: ‘out/target/common/docs/gen’: No such file or directory
find: ‘frameworks/base/frameworks/base/docs/html’: No such file or directory
find: ‘out/target/common/docs/gen’: No such file or directory
No private recovery resources for TARGET_DEVICE imx53_smd
host Java: droiddoc (out/host/common/obj/JAVA_LIBRARIES/droiddoc_intermediates/classes)
host C: libclearsilver-jni <= external/clearsilver/java-jni/j_neo_util.c
host C: libneo_util <= external/clearsilver/util/neo_files.c
host C: libneo_util <= external/clearsilver/util/ulist.c
host C: libneo_util <= external/clearsilver/util/neo_hdf.c
host C: libneo_util <= external/clearsilver/util/neo_str.c
host C: libneo_util <= external/clearsilver/util/ulocks.c
host C: libneo_util <= external/clearsilver/util/neo_hash.c
In file included from external/clearsilver/util/ulist.c:19:0:
external/clearsilver/util/ulist.c: In function ‘uListInit’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/ulist.c:64:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_NOMEM, "Unable to create ULIST: Out of memory");
^
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/ulist.c:70:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_NOMEM, "Unable to create ULIST: Out of memory");
^
external/clearsilver/util/ulist.c: In function ‘uListPop’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/ulist.c:124:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_OUTOFRANGE, "uListPop: empty list");
^
In file included from external/clearsilver/java-jni/j_neo_util.c:6:0:
external/clearsilver/java-jni/j_neo_util.c: In function ‘jni_fileload_cb’:
external/clearsilver/java-jni/../util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/java-jni/j_neo_util.c:257:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_ASSERT,
^
external/clearsilver/java-jni/../util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/java-jni/j_neo_util.c:268:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_ASSERT,
^
In file included from external/clearsilver/util/neo_files.c:26:0:
external/clearsilver/util/neo_files.c: In function ‘ne_listdir_fmatch’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_files.c:219:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_ASSERT, "Invalid call to ne_listdir_fmatch");
^
In file included from external/clearsilver/util/neo_hdf.c:24:0:
external/clearsilver/util/neo_hdf.c: In function ‘_alloc_hdf’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_hdf.c:62:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise (NERR_NOMEM, "Unable to allocate memory for hdf element");
^
In file included from external/clearsilver/util/neo_str.c:22:0:
external/clearsilver/util/neo_str.c: In function ‘string_appendvf’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_str.c:167:14: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_NOMEM,
^
external/clearsilver/util/neo_str.c: In function ‘string_array_split’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_str.c:223:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise (NERR_ASSERT, "separator must be at least one character");
^
external/clearsilver/util/neo_hdf.c: In function ‘hdf_set_attr’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_hdf.c:409:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_ASSERT, "Unable to set attribute on none existant node");
^
external/clearsilver/util/neo_hdf.c: In function ‘_set_value’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_hdf.c:648:14: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_NOMEM, "Unable to allocate memory");
^
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_hdf.c:795:16: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_NOMEM, "Unable to allocate memory");
^
external/clearsilver/util/neo_hdf.c: In function ‘hdf_set_valuevf’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_hdf.c:869:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_NOMEM, "Unable to allocate memory for format string");
^
external/clearsilver/util/neo_hdf.c: In function ‘_copy_attr’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_hdf.c:1028:14: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_NOMEM, "Unable to allocate copy of HDF_ATTR");
^
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_hdf.c:1036:14: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_NOMEM, "Unable to allocate copy of HDF_ATTR");
^
In file included from external/clearsilver/util/ulocks.c:22:0:
external/clearsilver/util/ulocks.c: In function ‘fLock’:
external/clearsilver/util/neo_err.h:102:75: error: expected expression before ‘)’ token
nerr_raise_errnof(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/ulocks.c:96:12: note: in expansion of macro ‘nerr_raise_errno’
return nerr_raise_errno (NERR_LOCK, "File lock failed");
^
In file included from external/clearsilver/util/neo_hash.c:18:0:
external/clearsilver/util/neo_hash.c: In function ‘ne_hash_init’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_hash.c:30:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_NOMEM, "Unable to allocate memory for NE_HASH");
^
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_hash.c:41:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_NOMEM, "Unable to allocate memory for NE_HASHNODES");
^
external/clearsilver/util/neo_hdf.c: In function ‘hdf_write_string’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_hdf.c:1342:28: note: in expansion of macro ‘nerr_raise’
if (*s == NULL) return nerr_raise(NERR_NOMEM, "Unable to allocate empty string");
^
external/clearsilver/util/neo_hash.c: In function ‘ne_hash_insert’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_hash.c:91:14: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_NOMEM, "Unable to allocate NE_HASHNODE");
^
external/clearsilver/util/neo_hash.c: In function ‘_hash_resize’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_hash.c:229:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_NOMEM, "Unable to allocate memory to resize NE_HASH");
^
external/clearsilver/util/neo_hdf.c: In function ‘hdf_read_file’:
external/clearsilver/util/neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
external/clearsilver/util/neo_hdf.c:1834:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_ASSERT, "Can't read NULL file");
^
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libclearsilver-jni_intermediates/j_neo_util.o] Error 1
make: *** Waiting for unfinished jobs....
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libneo_util_intermediates/neo_files.o] Error 1
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libneo_util_intermediates/ulist.o] Error 1
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libneo_util_intermediates/neo_str.o] Error 1
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libneo_util_intermediates/ulocks.o] Error 1
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libneo_util_intermediates/neo_hash.o] Error 1
make: *** [out/host/linux-x86/obj/SHARED_LIBRARIES/libneo_util_intermediates/neo_hdf.o] Error 1
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
/bin/bash: jar: command not found
make: *** [out/host/common/obj/JAVA_LIBRARIES/droiddoc_intermediates/javalib.jar] Error 127

最佳答案

我现在在 AOSP 构建中遇到了一个新错误,看起来这将是一场可怕的无休止的战斗,除非我解决一些关于我的环境、配置或其他方面的更基本的问题。然而,我确实通过以下方式解决了这个特定的错误......

我没有运行整个 AOSP make,而是尝试只编译一个被这个宏阻塞的文件:

cd external/clearsilver/util
gcc -I/[my full path...]/external/clearsilver neo_files.c

结果

In file included from neo_files.c:26:0:
neo_files.c: In function ‘ne_listdir_fmatch’:
neo_err.h:88:69: error: expected expression before ‘)’ token
nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,__VA_ARGS__)
^
neo_files.c:219:12: note: in expansion of macro ‘nerr_raise’
return nerr_raise(NERR_ASSERT, "Invalid call to ne_listdir_fmatch");

然后,根据 John Bollinger 的建议,我使用 gcc -E:

gcc -E -I/[my full path...]/external/clearsilver neo_files.c

截断结果

...
if (files ==
# 218 "neo_files.c" 3 4
((void *)0)
# 218 "neo_files.c"
)
return nerr_raisef(__PRETTY_FUNCTION__,"neo_files.c",219,NERR_ASSERT,"Invalid call to ne_listdir_fmatch",);

...

如果您查看宏扩展到的行的最末尾,您会看到:

... NERR_ASSERT,"Invalid call to ne_listdir_fmatch",);

注意参数列表末尾的逗号!这就是问题所在!

解决方案?使用##__VAR_ARGRS_。在宏观上。在这种情况下,## 前缀会删除前导逗号:

nerr_raisef(__PRETTY_FUNCTION__,__FILE__,__LINE__,e,f,##__VA_ARGS__)

我也对 neo_err.h 文件中的一些其他宏重复了这一点。然后,我不仅可以编译该文件,还可以运行整个clearsliver util mod的make:

make

结果

gcc -g -O2 -Wall -I..  -fPIC -o neo_err.o -c neo_err.c
gcc -g -O2 -Wall -I.. -fPIC -o neo_files.o -c neo_files.c
gcc -g -O2 -Wall -I.. -fPIC -o neo_misc.o -c neo_misc.c
gcc -g -O2 -Wall -I.. -fPIC -o neo_rand.o -c neo_rand.c
gcc -g -O2 -Wall -I.. -fPIC -o ulist.o -c ulist.c
gcc -g -O2 -Wall -I.. -fPIC -o neo_hdf.o -c neo_hdf.c
gcc -g -O2 -Wall -I.. -fPIC -o neo_str.o -c neo_str.c
gcc -g -O2 -Wall -I.. -fPIC -o neo_date.o -c neo_date.c
gcc -g -O2 -Wall -I.. -fPIC -o wildmat.o -c wildmat.c
gcc -g -O2 -Wall -I.. -fPIC -o neo_hash.o -c neo_hash.c
gcc -g -O2 -Wall -I.. -fPIC -o ulocks.o -c ulocks.c
gcc -g -O2 -Wall -I.. -fPIC -o rcfs.o -c rcfs.c
gcc -g -O2 -Wall -I.. -fPIC -o skiplist.o -c skiplist.c
gcc -g -O2 -Wall -I.. -fPIC -o dict.o -c dict.c
gcc -g -O2 -Wall -I.. -fPIC -o filter.o -c filter.c
gcc -g -O2 -Wall -I.. -fPIC -o neo_net.o -c neo_net.c
gcc -g -O2 -Wall -I.. -fPIC -o neo_server.o -c neo_server.c
ar cr ../libs/libneo_utl.a neo_err.o neo_files.o neo_misc.o neo_rand.o ulist.o neo_hdf.o neo_str.o neo_date.o wildmat.o neo_hash.o ulocks.o rcfs.o skiplist.o dict.o filter.o neo_net.o neo_server.o
ranlib ../libs/libneo_utl.a

成功!

现在,讨论 AOSP 噩梦的下一个问题......

关于android - C 宏编译错误(AOSP : external/clearsilver/util/neo_err. h),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42979203/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com