zhblue / hustoj

Popular Open Source Online Judge based on PHP/C++/MySQL/Linux for ACM/ICPC and NOIP training, with easy installation. 开源OJ系统
http://www.hustoj.com/?cat=2
GNU General Public License v2.0
3.18k stars 759 forks source link

请问如何确认当前安装 的hustoj 中 c++编译器 是哪个版本? 比如 c++17 还是 c++20 ? #987

Closed 201zxming closed 5 months ago

201zxming commented 5 months ago

想 确认当前安装 的hustoj 中 c++编译器 是哪个版本。 比如 c++17 还是 c++20 。

zhblue commented 5 months ago

check the lines in /home/judge/etc/judge.conf

#use next two lines to overide C/C++ standard
OJ_CC_STD=-std=c99
OJ_CPP_STD=-std=c++17
#OJ_CC_OPT=-O2

and if not found , check /home/judge/src/core/judge_client/judge_client.cc

    if(__GNUC__ > 9 || (  __GNUC__ == 9 &&  __GNUC_MINOR__ >= 3 ) ){ 
        // ubuntu20.04 introduce g++9.3
        strcpy(cc_std,"-std=c17");
        strcpy(cpp_std,"-std=c++14");    // CCF NOI change settings for NOIP to C++14 on 2021-9-1
    }else{
        strcpy(cc_std,"-std=c99");
        strcpy(cpp_std,"-std=c++11");
    }

and the compiler version in Docker can be found by run code in TEST_RUN

#include <stdio.h>

int main()
{
    printf("%d.%d.%d\n",__GNUC__,__GNUC_MINOR__ ,__GNUC_PATCHLEVEL__);
    return 0;
}
201zxming commented 5 months ago

在 /home/judge/etc/judge.conf OJ_CC_STD=-std=c99 OJ_CPP_STD=-std=c++17 打开这2行配置后重启了判题机(安装 的时候这2行配置是默认屏蔽掉的),报错了: g++: error: unrecognized command line option ‘-std=c++17’

看来是不支持 C++ 17?

zhblue commented 5 months ago

说明你的ubuntu版本较老 ?

201zxming commented 5 months ago

请问是不是升级 GCC 版本才行呢? 当前机器 gcc 4.8.5 的

zhblue commented 5 months ago

建议备份数据后重装操作系统为ubuntu22.04,然后用最新脚本安装,最后还原备份数据。

201zxming commented 5 months ago

如果要升级到 支持C++20的话,以下配置该怎么写呢: 在 /home/judge/etc/judge.conf 的 OJ_CC_STD=-std=c99 OJ_CPP_STD=-std=c++17

201zxming commented 5 months ago

我这里是一台centos7.5, 试了下直接安装 最新版本的gcc也是有效的,主要以下几个操作(没有改 /home/judge/etc/judge.conf):

安新新版本

yum -y install centos-release-scl yum -y install devtoolset-11-gcc devtoolset-11-gcc-c++ devtoolset-11-binutils

配置环境变量,以便默认使用最新版本

echo "source /opt/rh/devtoolset-11/enable" >>/etc/profile source /etc/profile

确认新版本

gcc --version

重启判题机

cd /home/judge/src/core && sudo pkill -9 judged && ./make.sh && judged