U81502使用C提交时出现错误
  • 板块工单反馈版
  • 楼主xkcdjerry
  • 当前回复6
  • 已保存回复6
  • 发布时间2020/7/11 17:02
  • 上次更新2023/11/6 23:17:21
查看原帖
U81502使用C提交时出现错误
298051
xkcdjerry楼主2020/7/11 17:02

我在试着使用C做U81502,可是当复制粘贴代码并加上return a+b;之后,出现了如下错误:

SPJ compilation failed: 

/tmp/tmplcv21wp8/src:1:8: 错误:expected identifier or ‘(’ before string constant
 extern "C" int plus(int a, int b) {
        ^~~

(链接:https://www.luogu.com.cn/record/35045472)

当将extern "C"删除后,SPJ爆出如下错误:

No valid executable file was produced by the compiler
/usr/bin/ld: /tmp/tmplrm438bx/lib.o: in function `main':
src:(.text.startup+0x7): undefined reference to `std::cin'
/usr/bin/ld: src:(.text.startup+0x11): undefined reference to `std::istream::operator>>(int&)'
/usr/bin/ld: src:(.text.startup+0x1e): undefined reference to `std::istream::operator>>(int&)'
/usr/bin/ld: src:(.text.startup+0x32): undefined reference to `std::cout'
/usr/bin/ld: src:(.text.startup+0x39): undefined reference to `std::ostream::operator<<(int)'
/usr/bin/ld: src:(.text.startup+0x41): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/usr/bin/ld: /tmp/tmplrm438bx/lib.o: in function `_GLOBAL__sub_I_main':
src:(.text.startup+0x5c): undefined reference to `std::ios_base::Init::Init()'
/usr/bin/ld: src:(.text.startup+0x63): undefined reference to `std::ios_base::Init::~Init()'
collect2: 错误:ld 返回 1

(网址:https://www.luogu.com.cn/record/35045743)
此错误似乎是在评测C的时候使用了C++代码
我在仔细查看题面之后发现没有要求必须使用C++,请问这是站务在其他地方已经说了还是真的没有?
如果没有的话,请问可以修改之使其可以使用C通过吗?谢谢!

2020/7/11 17:02
加载中...