标签: g++-4.7

std :: set没有成员安置

g ++ 4.7.2是否实现std::set::emplace,如C++ 11标准所定义并在此处记录

我写了以下小测试用例:

#include <set>
#include <string>

struct Foo
{
    std::string mBar;
    bool operator<(const Foo& rhs) const
    {
        return mBar < rhs.mBar;
    }
    Foo(const std::string bar) : mBar(bar) {};
};

typedef std::set<Foo> Foos;

int main()
{
    Foos foos;
    foos.emplace(std::string("Hello"));
}
Run Code Online (Sandbox Code Playgroud)

在G ++ 4.7.2下,这无法编译:

[john.dibling@somewhere hacks]$ g++ -o main.o -std=c++0x -c main.cpp
main.cpp: In function ‘int main()’:
main.cpp:19:10: error: ‘Foos’ has no member named ‘emplace’
Run Code Online (Sandbox Code Playgroud)

也无法在IDEOne下编译,但它在MSVC 2012 Update 1下编译.

c++ g++ libstdc++ c++11 g++-4.7

24
推荐指数
2
解决办法
9363
查看次数

g ++ 4.7.2上的-std = c ++ 11的CppUTest错误

我一直在使用CppUTest与g ++ 4.7.2一段时间没有问题.但是,我刚刚打开-std=c++11选项,所以我可以开始使用std::unique_ptr它立即失败.

即使只是编译主模块:

#include <CppUTest/CommandLineTestRunner.h>

int main(int argc, char ** argv) {
    return CommandLineTestRunner::RunAllTests(argc, argv);
}
Run Code Online (Sandbox Code Playgroud)

失败的变化:

In file included from /usr/include/CppUTest/TestHarness.h:77:0,
                 from /usr/include/CppUTest/CommandLineTestRunner.h:31,
                 from tests/testmain.cpp:15:
/usr/include/CppUTest/MemoryLeakWarningPlugin.h:56:53: error: declaration of ‘void* operator new(size_t) throw (std::bad_alloc)’ has a different exception specifier
In file included from /usr/include/c++/4.7/ext/new_allocator.h:34:0,
                 from /usr/include/c++/4.7/x86_64-linux-gnu/bits/c++allocator.h:34,
                 from /usr/include/c++/4.7/bits/allocator.h:48,
                 from /usr/include/c++/4.7/string:43,
                 from /usr/include/CppUTest/SimpleString.h:136,
                 from /usr/include/CppUTest/Utest.h:34,
                 from /usr/include/CppUTest/TestHarness.h:71,
                 from /usr/include/CppUTest/CommandLineTestRunner.h:31,
                 from tests/testmain.cpp:15:
/usr/include/c++/4.7/new:93:7: error: from previous declaration ‘void* operator new(std::size_t)’
Run Code Online (Sandbox Code Playgroud)

删除该-std=c++11选项使一切工作再次正常.

CppUTest文档对与重载的新运算符冲突的宏做了一些评论,并建议首先包括#including标准头,但我得到这个问题而根本不包括任何头,尽管它看起来像CppUTest/CommandLineTestRunner.h包括 …

cpputest c++11 g++-4.7

6
推荐指数
0
解决办法
738
查看次数

错误"'fdopen'未声明为"使用g ++ 4编译,使用g ++ 3编译

我有快速编译g ++版本3.something的代码.然后我想构建一些其他包含C++ 11符号的代码,所以我升级到g ++ 4.7.现在我的原始代码没有构建.我收到错误:

'fdopen'未在此范围内声明

根据手册页,fdopen()在stdio.h中声明,我包括在内.我不确定它是否相关,但我在Cygwin环境中工作.我使用的g ++的确切版本是Cygwin提供的版本4.7.2.

我没有更改此代码,因为我切换了编译器,我可以肯定地确认它已构建,我的测试代码运行并通过以前的编译器传递.

根据要求,演示问题的示例代码:

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char **argv)
{
    int   fd;
    FILE *fp;

    fd = open("test.txt", (O_WRONLY | O_CREAT | O_EXCL), S_IRWXU);
    if(0 < fd)
    {
        fp = fdopen(fd, "wb");

        fprintf(fp, "Testing...\n");
        fclose(fp);
    }

    return 0;
}


# g++ -std=c++11 -o test test.cpp
test.cpp: In function 'int main(int, char**)':
test.cpp:14:29: error: 'fdopen' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)

c++ g++-4.7

5
推荐指数
2
解决办法
9181
查看次数

CUDA 5.5 RC与g ++ 4.7和4.8:__ int128构建错误

我正在尝试使用COSA SDK 5.5 RC和Mac OS X 10.8上的g ++ 4.7编译一些代码.如果我理解正确,CUDA 5.5应该与g ++ 4.7一起使用.查看/usr/local/cuda/include/host_config.h它甚至可以使用g ++ 4.8.

关于g ++ 4.8:我试着编译以下程序:

// example.cu
#include <stdio.h>
int main(int argc, char** argv) {
  printf("Hello World!\n");
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

但它失败了:

$ nvcc example.cu -ccbin=g++-4.8
/usr/local/Cellar/gcc48/4.8.1/gcc/include/c++/4.8.1/cstdlib(178): error: identifier "__int128" is undefined
/usr/local/Cellar/gcc48/4.8.1/gcc/include/c++/4.8.1/cstdlib(179): error: identifier "__int128" is undefined
2 errors detected in the compilation of "/tmp/tmpxft_00007af2_00000000-6_example.cpp1.ii".
Run Code Online (Sandbox Code Playgroud)

相同的程序使用g ++ 4.7编译和运行:

$ nvcc example.cu -ccbin=g++-4.7
$ ./a.out 
Hello World!
Run Code Online (Sandbox Code Playgroud)

但如果我包括<limits> ......

// example_limits.cu
#include <stdio.h>
#include <limits>
int main(int argc, char** …
Run Code Online (Sandbox Code Playgroud)

cuda g++-4.7 g++4.8

5
推荐指数
1
解决办法
4354
查看次数

OpenMP:请勿使用超线程核心(半个num_threads()具有超线程)

g ++ 4.7中的OpenMP(并行使用)效率不是很高吗?在使用5倍CPU的情况下为2.5倍,我确定程序的性能在使用默认值的情况下在500%CPU左右的11s和13s之间变化(通常总是高于12s,有时甚至慢于13.4s)#pragma omp parallel for,并且OpenMP加速仅为在g++-4.7 -O3 -fopenmp4核8线程Xeon上,在5倍CPU w /时为2.5倍。

我尝试使用schedule(static) num_threads(4),并注意到我的程序始终在大约320%的CPU上以11.5s至11.7s(总是低于12s)完成操作,例如,运行更一致,并且使用了更少的资源(即使最好的运行速度比运行速度慢了半秒)具有超线程的罕见异常值)。

是否有任何简单的OpenMP方式可检测超线程并减少num_threads()到CPU内核的实际数量?

(有一个类似的问题,由于使用OpenMP的超线程导致的性能不佳:如何将线程绑定到内核,但是在我的测试中,我发现仅将线程从8个减少到4个就已经可以用g ++-4.7做到这一点。在Debian 7 Wheezy和Xeon E3-1240v3上,因此,这个问题仅仅是关于减少num_threads()内核数。)

c++ openmp hyperthreading cpu-cores g++-4.7

5
推荐指数
1
解决办法
3700
查看次数

ofstream不在linux上工作

我有一个简单的测试代码:

#include <string>
#include <iostream>
#include <fstream>

int main() {
std::ofstream strm = std::ofstream("test.txt");
strm << "TEST123";
strm.close();
return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果我在Windows上编译它,它完美地工作.但是当我使用以下命令在debian上编译它时:g ++ - 4.7 -std = c ++ 0x -lpthread TestStream.cpp -ldl -o TestStream比它提供以下输出: 在此输入图像描述

我用google搜索这个错误无济于事.有谁知道如何解决这个问题?我在我的项目中使用了很多流,并且想在linux上编译它.

编辑:所以我现在感谢WinterMute编译,但现在它打印空文件.我该如何解决?

编辑2:不知道为什么,但第二次编译它的工作.谢谢!

c++ linux g++-4.7

3
推荐指数
1
解决办法
6652
查看次数

在Ubuntu中C++程序编译失败,但在MacOSX中有效

嗨我有一个用C++编写的程序.当我使用g ++编译器在Mac终端中编译它时,它会编译并运行.但是当我使用g ++编译器在Ubuntu终端中编译相同的C++程序时,它就失败了.我不知道为什么会这样.

Ubuntu中的g ++编译器版本是4.7.3.

这是我的代码示例

#include <iostream>

using namespace std;

#define IXSIZE 400
#define IYSIZE 400
#define IZSIZE 3

void putbyte(FILE *outf, unsigned char val)
{ 
    unsigned char buf[1]; 

    buf[0] = val; 
    fwrite(buf,1,1,outf); 
} 

void putshort(FILE *outf, unsigned short val) 
{ 
    unsigned char buf[2]; 

    buf[0] = (val>>8); 
    buf[1] = (val>>0); 
    fwrite(buf,2,1,outf); 
} 
Run Code Online (Sandbox Code Playgroud)

我得到以下错误

seperate.cpp: In function ‘void putbyte(FILE*, unsigned char)’: seperate.cpp:23:21: error: ‘fwrite’ was not declared in this scope seperate.cpp: In function ‘void putshort(FILE*, short unsigned int)’: seperate.cpp:32:21: error: …

c++ macos ubuntu g++ g++-4.7

1
推荐指数
1
解决办法
7086
查看次数

C++ 11上的嵌套类成员访问

在C++ 11中,我试图通过以下方式从嵌套类访问封闭类的成员变量:

struct Enclosing {
    int a;
    struct Nested {
        int f() {
            return a;
        }
    };
};
Run Code Online (Sandbox Code Playgroud)

即使这不使用g ++ 4.7.2和-std = c ++ 11进行编译,也会生成以下形式的错误消息:

error: invalid use of non-static data member 'Enclosing::a'
Run Code Online (Sandbox Code Playgroud)

据我所知,C++ 11将嵌套类视为类的成员,因此可以认为嵌套类可以访问封闭类的每个其他成员.我做错什么了吗?提前致谢.

更新:

虽然我的问题似乎在下面有一个答案,但我不相信这会被标记为重复.

在发布问题之前经过大量搜索之后,我知道在C++ 11标准之前讨论嵌套类和封闭类之间的关系.

像这样的先前相关讨论引用了C++ 11中的一些"更新",例如C++嵌套类可访问性

但至少从我读过的答案来看,不完全清楚C++ 11在这个问题上与旧版本"不同".

从技术上讲,我的问题的解决方案存在于较旧的线程中,例如 嵌套类'访问封闭类'私有数据成员,这一事实必须被指出,但是它让我看起来很无聊.但是,我没有得到任何将C++ 11置于背景中的答案; 至少,我不认为我的问题可以被公平地视为在C++ 11标准之前提出的问题的"重复".

c++ c++11 g++-4.7

1
推荐指数
1
解决办法
3159
查看次数

标签 统计

g++-4.7 ×8

c++ ×6

c++11 ×3

g++ ×2

cpputest ×1

cpu-cores ×1

cuda ×1

g++4.8 ×1

hyperthreading ×1

libstdc++ ×1

linux ×1

macos ×1

openmp ×1

ubuntu ×1