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

时间:2017-03-23 14:37:34

标签: android c macros android-source clearsilver

我在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__)

根据这个问题"问问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

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

#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

2 个答案:

答案 0 :(得分:0)

我现在正在面对AOSP构建中的一个新错误,看起来这将是一场可怕的无休止的战斗,除非我解决一些关于我的环境,配置或其他任何事情的更重要的事情。然而,我确实以下列方式解决了这个特定的错误...

我没有运行整个AOSP make,而是尝试编译一个在这个宏上窒息的文件:

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

RESULT

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

RESULT

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噩梦的下一个问题......

答案 1 :(得分:0)

显然,这是我的真实答案:

https://source.android.com/source/known-issues.html#build-error-with-40x-and-earlier-on-ubuntu-1110

  

在Ubuntu 11.10上构建IceCreamSandwich 4.0.x(和旧版本)   更新失败...要么降级到Ubuntu 10.04,要么使用主服务器   分支,可以在Ubuntu 11.10和更新版本上编译。

我使用其他人为大幅定制的AOSP编写的源代码,并且只是在一个巨大的tarball中移交。我无法搞清楚我使用的回购分支。显然,我别无选择,只能设置完整的独立操作系统。

育! (或类似的东西......)