最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】用arm-xscale-linux-gnueabi编译代码出错:error: lvalue required as unary ‘&’ operand

Embedded crifan 6491浏览 0评论

【问题】

用arm-xscale-linux-gnueabi交叉编译代码,结果出错:

.././Src/xxx.c:707:32: error: lvalue required as unary ‘&’ operand

 

【解决过程】

1.直接去看代码:

706和707行的代码是:

            xmlrpc_read_string(&env, pResult,
                               &(CONSTCHAR *) pMoteStateResponse);

所以,先去找找xmlrpc_read_string,参考:

http://xmlrpc-c.sourceforge.net/doc/libxmlrpc.html

其api是:

void
xmlrpc_read_string(xmlrpc_env *         const envP,
                   const xmlrpc_value * const valueP,
                   const char **        const stringValueP);

然后手动去改代码为:

            // xmlrpc_read_string(&env, pResult,
                               // &(CONSTCHAR *) pMoteStateResponse);
            xmlrpc_read_string(&env, pResult,
                               &((CONSTCHAR *)pMoteStateResponse));

编译看看,是否有效,结果问题依旧。

 

2.参考了:

关于结构体和指针的一个问题

Understanding lvalues and rvalues in C and C++

稍微更清楚这个lvalue=左值=左边的值了

注意到此处,已经定义了该变量为CONSTCHAR了:

    CONSTCHAR *pMoteStateResponse = NULL;
    ...
    // xmlrpc_read_string(&env, pResult,
                       // &(CONSTCHAR *) pMoteStateResponse);
    xmlrpc_read_string(&env, pResult,
                       &((CONSTCHAR *)pMoteStateResponse));

所以,去掉CONSTCHAR *,试试:

            // xmlrpc_read_string(&env, pResult,
                               // &(CONSTCHAR *) pMoteStateResponse);
            xmlrpc_read_string(&env, pResult,
                               &pMoteStateResponse);

然后的确,消除了此问题了。

3.另外,看到:

Bug 53157 – within lambda, error: lvalue required as unary ‘&’ operand

所以,怀疑是:

gcc的bug,或者语法的兼容性问题,

即或许某个版本的gcc,是支持:

    CONSTCHAR *pMoteStateResponse = NULL;
    ...
    &(CONSTCHAR *) pMoteStateResponse);

的写法的。

而我当前的,交叉编译器的版本是:

CLi@PC-CLI-1 ~/develop/wihart_gateway_6_0/WBM/Build
$ arm-xscale-linux-gnueabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-xscale-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/home/CLi/develop/crosstool-ng/x-tools/arm-xscale-linux-gnueabi/libexec/gcc/arm-xscale-linux-gnueabi/4.6.0/lto-wrapper.exe
Target: arm-xscale-linux-gnueabi
Configured with: /home/CLi/develop/crosstool-ng/crosstool-ng-1.18.0_build/.build/src/gcc-4.6.0/configure --build=i686-build_pc-cygwin --host=i686-build_pc-cygwin --target=arm-xscale-linux-gnueabi --prefix=/home/CLi/develop/crosstool-ng/x-tools/arm-xscale-linux-gnueabi --with-sysroot=/home/CLi/develop/crosstool-ng/x-tools/arm-xscale-linux-gnueabi/arm-xscale-linux-gnueabi/sysroot --enable-languages=c,c++ --with-arch=armv5te --with-cpu=xscale --with-tune=xscale --with-float=softfp --with-pkgversion='crosstool-NG 1.18.0' --disable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --with-gmp=/home/CLi/develop/crosstool-ng/crosstool-ng-1.18.0_build/.build/arm-xscale-linux-gnueabi/buildtools --with-mpfr=/home/CLi/develop/crosstool-ng/crosstool-ng-1.18.0_build/.build/arm-xscale-linux-gnueabi/buildtools --with-mpc=/home/CLi/develop/crosstool-ng/crosstool-ng-1.18.0_build/.build/arm-xscale-linux-gnueabi/buildtools --with-ppl=no --with-cloog=no --with-libelf=no --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix --enable-target-optspace --disable-nls --disable-multilib --with-local-prefix=/home/CLi/develop/crosstool-ng/x-tools/arm-xscale-linux-gnueabi/arm-xscale-linux-gnueabi/sysroot --enable-c99 --enable-long-long
Thread model: posix
gcc version 4.6.0 (crosstool-NG 1.18.0)

即4.6.0的gcc。而上面的bug提交,是4.7.0的gcc(中的g++)就有的。

不知道是否是:

升级成更高版本的(此处的交叉编译器的)gcc,就可以解决此问题?

但是,觉得也很奇怪的是,当前的代码,好像是:

别人之前用,更低版本的(交叉编译器)gcc:

gcc-3.4.5-glibc-2.3.6

就可以正常编译的。

所以,应该不是这方面的问题才对。

4.这里也是用4.7的gcc出了类似问题:

ec_threads.c – error: lvalue required as unary ‘&’

但是不知道如何解决。

5.参考:

【已结贴】《Linux C编程一站式学习》的一个问题,欢迎讨论

去试试,手动用g++去编译试试,结果问题依旧。

6.去试试,会不会是因为多了个空格:

            // xmlrpc_read_string(&env, pResult,
                               // &(CONSTCHAR *) pMoteStateResponse);
            xmlrpc_read_string(&env, pResult,
                               &(CONSTCHAR *) pMoteStateResponse);

改为:

            // xmlrpc_read_string(&env, pResult,
                               // &(CONSTCHAR *) pMoteStateResponse);
            xmlrpc_read_string(&env, pResult,
                               &(CONSTCHAR *)pMoteStateResponse);

试试,结果还是出错。

 

【总结】

此处,只能是,把:

    CONSTCHAR *pMoteStateResponse = NULL;
    ...
    xmlrpc_read_string(&env, pResult,
                       &(CONSTCHAR *) pMoteStateResponse);

改为:

    CONSTCHAR *pMoteStateResponse = NULL;
    ...
    xmlrpc_read_string(&env, pResult,
                       &pMoteStateResponse);

而暂时解决此问题。

转载请注明:在路上 » 【已解决】用arm-xscale-linux-gnueabi编译代码出错:error: lvalue required as unary ‘&’ operand

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
81 queries in 0.174 seconds, using 22.53MB memory