Anaconda安装的GCC编译报错:TIME_UTC和timespec_get未声明
关于conda安装的GCC无法识别time.h中TIME_UTC宏与timespec_get函数的问题
安装最新版Anaconda并配置conda-forge的cxx-compiler与compilers工具后,编译C文件时出现TIME_UTC宏和timespec_get函数未声明的错误——这二者本应包含在time.h头文件中,但系统自带编译器可成功编译该文件。已尝试调整conda-forge包优先级,未奏效,也未找到类似案例,寻求相关提示与建议。
最小示例
测试文件test.c
#include <stdlib.h> #include <stdio.h> #include <time.h> // 获取当前时间(纳秒级) long get_nanos() { struct timespec ts; timespec_get(&ts, TIME_UTC); return (long)ts.tv_sec * 1000000000L + ts.tv_nsec; } int main() { // 打印时间 long test_time = get_nanos(); printf("Time: %ld\n", test_time); }
环境创建步骤
conda create -n test_env conda activate test_env conda install -c conda-forge compilers cxx-compiler gcc test.c
GCC报错信息
test.c: In function 'get_nanos': test.c:9:9: warning: implicit declaration of function 'timespec_get' [-Wimplicit-function-declaration] 9 | timespec_get(&ts, TIME_UTC); | ^~~~~~~~~~~~ test.c:9:27: error: 'TIME_UTC' undeclared (first use in this function) 9 | timespec_get(&ts, TIME_UTC); | ^~~~~~~~ test.c:9:27: note: each undeclared identifier is reported only once for each function it appears in
conda包列表(均来自conda-forge)
# Name Version Build Channel _libgcc_mutex 0.1 conda_forge conda-forge _openmp_mutex 4.5 2_gnu conda-forge binutils 2.39 hdd6e379_1 conda-forge binutils_impl_linux-64 2.39 he00db2b_1 conda-forge binutils_linux-64 2.39 h5fc0e48_13 conda-forge c-compiler 1.5.2 h0b41bf4_0 conda-forge compilers 1.5.2 ha770c72_0 conda-forge cxx-compiler 1.5.2 hf52228f_0 conda-forge fortran-compiler 1.5.2 hdb1a99f_0 conda-forge gcc 11.3.0 h02d0930_13 conda-forge gcc_impl_linux-64 11.3.0 hab1b70f_19 conda-forge gcc_linux-64 11.3.0 he6f903b_13 conda-forge gfortran 11.3.0 ha859ce3_13 conda-forge gfortran_impl_linux-64 11.3.0 he34c6f7_19 conda-forge gfortran_linux-64 11.3.0 h3c55166_13 conda-forge gxx 11.3.0 h02d0930_13 conda-forge gxx_impl_linux-64 11.3.0 hab1b70f_19 conda-forge gxx_linux-64 11.3.0 hc203a17_13 conda-forge kernel-headers_linux-64 2.6.32 he073ed8_15 conda-forge ld_impl_linux-64 2.39 hcc3a1bd_1 conda-forge libgcc-devel_linux-64 11.3.0 h210ce93_19 conda-forge libgcc-ng 12.2.0 h65d4601_19 conda-forge libgfortran5 12.2.0 h337968e_19 conda-forge libgomp 12.2.0 h65d4601_19 conda-forge libsanitizer 11.3.0 h239ccf8_19 conda-forge libstdcxx-devel_linux-64 11.3.0 h210ce93_19 conda-forge libstdcxx-ng 12.2.0 h46fd767_19 conda-forge sysroot_linux-64 2.12 he073ed8_15 conda-forge
conda安装的GCC版本
(test_env) ➜ test_dir gcc --version gcc (conda-forge gcc 11.3.0-19) 11.3.0 Copyright (C) 2021 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.
内容的提问来源于stack exchange,提问作者Roger Q.
相关产品推荐
相关产品推荐

