You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu Focal下GNU C++12搭配LLVM16头库编译失败求助

编译自定义OpenMP工具库的GCC编译错误问题

环境信息

  • 系统:Ubuntu 20.04.6 LTS(focal)
  • 编译工具:源码构建的GNU C++编译器v12.2.1
  • 依赖:LLVM v16.0.2提供的OpenMP头文件(omp-tools.h)和库文件(libomp.*),LLVM通过Ubuntu额外仓库安装

当前配置与编译命令

头文件路径配置

通过环境变量指定LLVM头文件路径:

export CPLUS_INCLUDE_PATH=/usr/lib/llvm-16/lib/clang/16/include:$CPLUS_INCLUDE_PATH

GCC编译命令

g++ -O3 -fopenmp -I ~/repo/git/smcs3/stan/lib/stan_math -I ~/repo/git/smcs3/stan/lib/stan_math/lib/eigen_3.3.3 -I ~/repo/git/smcs3/stan/lib/stan_math/lib/boost_1.69.0 -shared -fPIC counter.c ompt.c -o libompt.so -lomp

GCC编译错误信息

编译失败,返回以下错误:

In file included from /usr/include/stdio.h:33,
                 from counter.h:1,
                 from counter.c:1:
/usr/lib/llvm-16/lib/clang/16/include/stddef.h:41:39: error: missing binary operator before token "("
   41 | #if !defined(_SIZE_T) || __has_feature(modules)
      |                                       ^
In file included from /usr/include/stdio.h:43:
/usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h:95:3: error: ‘size_t’ does not name a type
   95 |   size_t __pad5;
      |   ^~~~~~
/usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h:1:1: note: ‘size_t’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?
  +++ |+#include <cstddef>
    1 | /* Copyright (C) 1991-2020 Free Software Foundation, Inc.
/usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h:98:67: error: ‘size_t’ was not declared in this scope
   98 |   char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];
      |                                                                   ^~~~~~
/usr/include/x86_64-linux-gnu/bits/types/struct_FILE.h:98:67: note: ‘size_t’ is defined in header ‘<cstddef>’; did you forget to ‘#include <cstddef>’?

LLVM编译情况

使用clang++-16编译同一代码可成功,但会出现警告:

编译命令

clang++-16 -O3 -fopenmp -I ~/repo/git/smcs3/stan/lib/stan_math -I ~/repo/git/smcs3/stan/lib/stan_math/lib/eigen_3.3.3 -I ~/repo/git/smcs3/stan/lib/stan_math/lib/boost_1.69.0 -shared -fPIC counter.c ompt.c -lomp -o libompt.so

警告信息

clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]

请求指导解决GCC编译失败的问题。


内容的提问来源于stack exchange,提问作者mabalenk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 10:14:55