Ubuntu 14.04上的Eclipse C ++找不到字符串的stod() [英] Eclipse C++ on Ubuntu 14.04 cannot find string's stod()

查看:106
本文介绍了Ubuntu 14.04上的Eclipse C ++找不到字符串的stod()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Elipse如果包含对字符串函数stod()的调用,则无法在我的系统上构建C ++程序。我正在使用C / C ++透视图在Eclipse上运行Ubuntu 14.04。



我已经包含了标头,并使用-std = c ++ 11编译标志进行了编译并进行了设置从gcc到g ++的编译器,但是没有用。我还尝试使用Eclipse的 ISO C ++ 11方言设置(将编译标志设置为-std = c ++ 0x。在所有情况下,编译器都无法看到stod函数。



要找出问题所在,我从cplusplus.com网站上编译了stod的示例:

  // stod示例
#include< iostream> // std :: cout
#include< string> // std :: string,std :: stod

int main()
{
std :: string orbits( 365.24 29.53);
std :: string :: size_type sz; // size_t

的别名double earth = std :: stod(轨道,& sz);
double moon = std :: stod(orbits.substr(sz));
std :: cout<<月亮完成<<(地球/月球)<<每个地球年的轨道。\n;
返回0;
}

无法编译,错误为无法解决功能站。如果我删除这些调用,并将地球初始化为0.0,将月亮初始化为1.0 ,它可以编译并正常运行(



我尝试从Ubuntu命令行编译相同的程序,当我包含-std = c ++ 11编译标志时,它可以工作。

 > g ++ -o teststod teststod.cpp -std = c ++ 11 
> teststod
每个地球年月球完成12.3684个轨道。

我的Linux是最新的,并且已经确定要进行更新。
一个可能的线索,我最初仅在Java目标上安装了Eclipse,但是我在Eclipse中将这些项目创建为具有C / C ++透视图的C ++项目。



参考,这是Eclipse的关于页面返回的内容:

 面向Java开发人员的IDE 
版本:Mars.1版本(4.5 .1)
内部版本号:20150924-1200

Ubuntu版本:
发行者ID:Ubuntu
描述:Ubuntu 14.04.5 LTS
发行:14.04
代号:trusty


解决方案

返回,我决定重新安装所有内容。回顾了youTube 在Windows上设置Eclipse C的视频之后,我意识到安装Eclipse要支持C,需要执行以下步骤:




  • java.oracle.com (完成)

  • 下载Eclipse(完成)

  • 下载C / C ++编译环境(

  • 下载Eclipse CDT软件包(未完成)



就像很多人一样,我以为我可以直接下载Eclipse for C / C ++并使其开箱即用,但是我无法构建任何类似helloWorld的教程。我需要单独下载编译器工具链。



我下载并安装了 cygwin 和Eclipse CDT软件包,但仍然出现错误,因为Eclipse找不到标准的包含文件头或make程序。



帖子讨论了设置 PATH 。我必须在 Window-> Preferences-> C / C ++-> Build-> Environment <下设置项目构建环境 PATH 变量/ code>并将路径 C:\cygwin64\bin 添加到 PATH 变量中。 / p>

在项目属性下,我必须转到位于 C /下的工具链编辑器 C ++构建并将当前工具链设置为 CygWin GCC Current根据以下 post < CDT Internal Builder 生成器 / a>。



由于我是从头开始的,因此我不得不返回并设置 -std = c ++ 0x 表示< project> Properties-> C / C ++ Build-> Settings-> Dialect'下的项目,然后选择 ISO C ++ 11(-std = c ++ 0x)低于语言标准。



该项目然后成功构建并正确运行。感谢StackEchange上为您提供各种帖子的人。


Elipse cannot build C++ programs on my system if they contains calls to string's function stod(). I am running Ubuntu 14.04 with Eclipse using the C/C++ perspective.

I have included the header, and compiled with the -std=c++11 compile flag and set the compiler from gcc to g++, but it did not work. I also tried using Eclipse's "ISO C++11" dialect setting (which sets the compile flag to -std=c++0x. In all cases, the compiler is unable to see the stod function.

To isolate the problem, I compiled the example from the cplusplus.com website for stod:

// stod example
#include <iostream>   // std::cout
#include <string>     // std::string, std::stod

int main ()
{
  std::string orbits ("365.24 29.53");
  std::string::size_type sz;     // alias of size_t

  double earth = std::stod (orbits,&sz);
  double moon = std::stod (orbits.substr(sz));
  std::cout << "The moon completes " << (earth/moon) << " orbits per Earth year.\n";
  return 0;
}

This fails to compile, with the error "Function stod could not be resolved". If I remove those calls, and initialize earth to 0.0, and moon to 1.0, it compiles and runs fine (with the wrong answer of course).

I tried compiling the same program from the Ubuntu command line and it works when I include the -std=c++11 compile flag.

> g++ -o teststod teststod.cpp -std=c++11
> teststod
The moon completes 12.3684 orbits per Earth year.

My Linux is up to date, and I have done an apt-get update to be sure. One possible clue, I originally installed Eclipse with only the Java target, but I created these projects in Eclipse as C++ projects with C/C++ perspectives.

For reference, here is what Eclipse's About page returns:

IDE for Java Developers
Version: Mars.1 Release (4.5.1)
Build id: 20150924-1200

Ubuntu version:
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.5 LTS
Release:    14.04
Codename:   trusty

解决方案

After taking a step back, I decided to reinstall everything. After reviewing a youTube video on setting up Eclipse C on windows, I realized that installing Eclipse to support C required these steps:

  • Downloading Java JDK from java.oracle.com (done)
  • Downloading Eclipse (done)
  • Downloading a C/C++ compile environment (not done!)
  • Downloading Eclipse CDT package (not done)

Like many people, I thought I could simply download Eclipse for C/C++ and have it work out of the box, but I could not build any of the tutorials like helloWorld. I needed to download the compiler toolchain separately.

I downloaded and installed cygwin and the Eclipse CDT package, but I still got errors because Eclipse could not find the standard include file headers, nor the make program.

This post talks about setting the PATH. I had to set the project build environment PATH variable under Window->Preferences->C/C++->Build->Environment and added the path C:\cygwin64\bin to the PATH variable.

Under Project Properties, I had to go to the Tool Chain Editor located under C/C++ Build and set Current Toolchain to CygWin GCC and Current builder to CDT Internal Builder according to this post.

And because I was starting from scratch, I had to go back and set -std=c++0x for the project under <project>Properties->C/C++ Build->Settings->Dialect' and chooseISO C++11 (-std=c++0x)underLanguage Standard`.

The project then built successfully and ran correctly. Thanks for everyone on StackEchange who helped with your various posts.

这篇关于Ubuntu 14.04上的Eclipse C ++找不到字符串的stod()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆