Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #12

Open
ZsGyao opened this issue Apr 8, 2023 · 11 comments
Open

Bug #12

ZsGyao opened this issue Apr 8, 2023 · 11 comments

Comments

@ZsGyao
Copy link

ZsGyao commented Apr 8, 2023

使用Ubuntu22.04 g++10.3编译失败

报错信息:
macro "__has_attribute" requires an identifier 304 | #if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__)

@ZsGyao
Copy link
Author

ZsGyao commented Apr 8, 2023

我在CmakeList中使用_D_const_ = __unused__解决了一部分问题,但是在rpc/rpc_session仍然出现了这个bug

@ZsGyao
Copy link
Author

ZsGyao commented Apr 8, 2023

用的编译器是g++11.3

@ZsGyao
Copy link
Author

ZsGyao commented Apr 9, 2023

您好,对于这个问题,brpc compile failed with error "error: macro "__has_attribute" requires an identifier" #1693 也有相同的问题出现,我使用相同的方法更改,但并未完全解决问题,所以我使用了另一种方法供参考,但这种方法是不推荐的。
这个问题的出现是由于gcc对于const解释不彻底导致的。
sudo vim /usr/include/x86_64-linux-gnu/sys/cdefs.h
进行如下更改

/* This declaration tells the compiler that the value is constant. */
// #if __GNUC_PREREQ (2,5) || __glibc_has_attribute (const)
#if __GNUC_PREREQ (2,5)
define attribute_const attribute ((const))
#else
define attribute_const /* Ignore */
#endif

编译通过

[ 96%] Building CXX object CMakeFiles/acid_static.dir/acid/rpc/rpc_session.cpp.o
[100%] Linking CXX static library ../lib/libacid.a
[100%] Built target acid_static

@ZsGyao
Copy link
Author

ZsGyao commented Apr 9, 2023

同时libgo也存在相同的问题,我已经在libgo提交了issue。

@zavier-wong
Copy link
Owner

您好,具体是在rpc/rpc_session的哪个部分代码编译有问题

@ZsGyao
Copy link
Author

ZsGyao commented Apr 9, 2023

感谢您及时的回复
在CmakeList中CXX_FLAGS中将参数-D__const__= 改为 -D__const__=__unused__可以解决下面这个报错

[  3%] Building CXX object CMakeFiles/acid_static.dir/acid/common/byte_array.cpp.o
In file included from /usr/include/features.h:486,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/c++config.h:586,
                 from /usr/include/c++/11/iosfwd:38,
                 from /usr/include/c++/11/ios:38,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/fstream:38,
                 from /home/xxx/Downloads/acid/acid/common/byte_array.cpp:5:
/usr/include/x86_64-linux-gnu/sys/cdefs.h:314:60: error: macro "__has_attribute" requires an identifier
  314 | #if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__)
      |                                                            ^
make[2]: *** [CMakeFiles/acid_static.dir/build.make:76:CMakeFiles/acid_static.dir/acid/common/byte_array.cpp.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:83:CMakeFiles/acid_static.dir/all] 错误 2
make: *** [Makefile:91:all] 错误 2

这是参考brpc的方案解决的,但是在后续编译时仍然遇到了下面这个报错,在试过修改系统的方式(上面提到的)后可以通过编译,我认为可能不是代码的问题。ps. libgo在修改-D__const__=__unused__后已经通过make && make install,我不清楚这由于是不是libgo的引起的
具体报错如下

[ 93%] Building CXX object CMakeFiles/acid_static.dir/acid/rpc/rpc_server.cpp.o
[ 96%] Building CXX object CMakeFiles/acid_static.dir/acid/rpc/rpc_session.cpp.o
In file included from /usr/include/features.h:486,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/c++config.h:586,
                 from /usr/include/c++/11/type_traits:38,
                 from /usr/include/c++/11/unordered_map:38,
                 from /usr/local/include/libgo/common/config.h:3,
                 from /usr/local/include/libgo/coroutine.h:3,
                 from /usr/local/include/libgo/libgo.h:2,
                 from /home/xxx/Downloads/acid/acid/rpc/rpc_session.h:8,
                 from /home/xxx/Downloads/acid/acid/rpc/rpc_session.cpp:5:
/usr/include/x86_64-linux-gnu/sys/cdefs.h:314:60: error: macro "__has_attribute" requires an identifier
  314 | #if __GNUC_PREREQ (2,5) || __glibc_has_attribute (__const__)
      |                                                            ^
make[2]: *** [CMakeFiles/acid_static.dir/build.make:454:CMakeFiles/acid_static.dir/acid/rpc/rpc_session.cpp.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:83:CMakeFiles/acid_static.dir/all] 错误 2
make: *** [Makefile:91:all] 错误 2

@zavier-wong
Copy link
Owner

晕,这bug完全没有头绪啊😂

@ZsGyao
Copy link
Author

ZsGyao commented Apr 9, 2023

hhh,我也觉得,之前弄了一天,最后只能改系统那个文件啦,编译完改回来就可以了。
不过感觉在g++11没解决这个问题前,cmake的cxx_flag里加上-D__const__=__unused__是推荐的,可以看一下我提交的pr

@zavier-wong
Copy link
Owner

我好像找到了,之前模仿libgo写cmake,把这条一起写进CMakeList了
set(CMAKE_CXX_FLAGS "-std=c++20 -D__const__= -fPIC -fno-strict-aliasing -Wall ${CMAKE_CXX_FLAGS}")
但是我并不需要-D__const__= 这条flag
所以这行应该改为set(CMAKE_CXX_FLAGS "-std=c++20 -fPIC -fno-strict-aliasing -Wall ${CMAKE_CXX_FLAGS}")

@ZsGyao
Copy link
Author

ZsGyao commented Apr 10, 2023

尝试了一下,还是出现了这种问题🧐,暂时没什么其他解决办法了

@kun-rpc
Copy link

kun-rpc commented Jun 30, 2024

我也出现了这个问题,请问还有什么其他的解决方案吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants