Ubuntu24下C++编译出现宏未定义的问题解决方案

#本人系统,ubuntu24,g++13
root@oe:~# g++ --version
g++ (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

root@oe:~# gcc --version
gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

root@oe:~# clang --version
Ubuntu clang version 18.1.3 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
root@oe:~# cat /etc/os-release 
PRETTY_NAME="Ubuntu 24.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.2 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

#编译的时候,经常出现这样的未定义宏的问题
/usr/include/x86_64-linux-gnu/sys/single_threaded.h:24:1: error: '__BEGIN_DECLS' does not name a type
     24 | __BEGIN_DECLS
        | ^~~~~~~~~~~~~
  In file included from /usr/include/c++/13/ext/atomicity.h:38,
                   from /usr/include/c++/13/bits/shared_ptr_base.h:61,
                   from /usr/include/c++/13/bits/shared_ptr.h:53,
                   from /usr/include/c++/13/memory:80,
                   from /root/git/tquic/deps/boringssl/src/include/openssl/base.h:424,
                   from /root/git/tquic/deps/boringssl/src/include/openssl/ssl.h:145,
                   from /root/git/tquic/deps/boringssl/src/ssl/bio_ssl.cc:10:
  /usr/include/x86_64-linux-gnu/sys/single_threaded.h:24:1: error: '__BEGIN_DECLS' does not name a type
     24 | __BEGIN_DECLS
        | ^~~~~~~~~~~~~
  /usr/include/x86_64-linux-gnu/sys/single_threaded.h:31:1: error: '__END_DECLS' does not name a type
     31 | __END_DECLS
        | ^~~~~~~~~~~

解决方案

#最后在这个文件里面出现问题,那就是它的头文件导入有误
/usr/include/x86_64-linux-gnu/sys/single_threaded.h
root@oe:~# cat /usr/include/x86_64-linux-gnu/sys/single_threaded.h |grep ".h>"
#include <features.h>
#里面只有一个头文件的问题,那就是找一下features.h的路径。
#不是find来搜索,而是看g++导入库的路径

root@oe:~# g++ -E /usr/include/x86_64-linux-gnu/sys/single_threaded.h -o /dev/null -v
Using built-in specs.
COLLECT_GCC=g++
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
******
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/13"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/13
 /usr/include/x86_64-linux-gnu/c++/13
 /usr/include/c++/13/backward
 /usr/lib/gcc/x86_64-linux-gnu/13/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
******
#就在这几个路径里面找,有没有features.h
#最后发现,只有/usr/local/include和/usr/include里面有,并且最后那个才是需要用的。
#简单处理,就是把/usr/include里面把用到的定义的宏复制到/usr/local/include里面去。

最近经常遇见和features.h中宏定义缺失有关的问题,都是通过这个方式解决的。

posted @ 2025-06-21 20:17  念秋  阅读(50)  评论(0)    收藏  举报