简体   繁体   English

我是否需要做一些特殊的事情才能让我的C ++程序使用gcc进行编译?

[英]Do I need to do something special to get my C++ program to compile using gcc?

Why does my program compile nicely with no warnings when I type g++ program_name but when I type gcc program_name I get screenfuls of undefined reference errors... 当我键入g++ program_name但为什么输入gcc program_name时,为什么我的程序编译得很好而没有警告我得到了一些未定义的引用错误...

I am using the standard library quite a bit, here are my includes: 我使用标准库很多,这里是我的包括:

#include<string>
#include<vector>
#include<fstream>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<algorithm>

using namespace std;

The reason I ask is I spent all this time developing a solution for a codeeval.com challange. 我问的原因是我花了这么多时间为codeeval.com挑战开发一个解决方案。 It works perfectly when compiled with g++, but won't compile with gcc. 它在使用g ++编译时非常有效,但不能用gcc编译。

Long story short, when codeeval tries to run my stuff, I get a score of 0 (!) although I have no idea how they are going about testing submissions... They just say: Your program did not pass all the test cases or there may have been warnings printed out at runtime . 长话短说,当codeeval尝试运行我的东西时,我得到0分(!)虽然我不知道他们如何测试提交...他们只是说: Your program did not pass all the test cases or there may have been warnings printed out at runtime

Of course, I have no idea how they are compiling it... They do say: 当然,我不知道他们是如何编译的......他们说:

You submissions are executed in a *NIX type environment. Assume softwares/shells etc are in their standard locations. Nothing else.

(since the have a typo in their submission guidlines, might other stuff be up?) (因为他们的提交指南中有拼写错误,其他东西可能会出现吗?)

They also say they accept solutions for C++ 4.3.4. 他们还说他们接受C ++ 4.3.4的解决方案。 I am running cywin and 4.3.4 is the version of my gcc. 我正在运行cywin,4.3.4是我的gcc的版本。

Has anyone else ever had a problem with submitting C++ code to codeeval.com? 有没有其他人在向codeeval.com提交C ++代码时遇到过问题?

I'm trying not to be super frustrated, but at this point they seem more like codeevil.com to me... 我试着不要太沮丧,但在这一点上他们看起来更像是codeevil.com给我...

gcc doesnt link in the standard c++ libraries by default. 默认情况下,gcc在标准c ++库中没有链接。 Either add -lstdc++ to the link line, or just compile with g++. 将-lstdc ++添加到链接行,或者只使用g ++编译。

Strictly speaking, "gcc" is the Gnu C compiler, and "g++" the corresponding C++ compiler. 严格来说,“gcc”是Gnu C编译器,而“g ++”是相应的C ++编译器。 Personally, I prefer to use the former for C, the latter for C++, instead of relying on file suffixes or command line arguments. 就个人而言,我更喜欢将前者用于C,后者用于C ++,而不是依赖于文件后缀或命令行参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM