标签: libstdc++

初始化列表中的隐式转换失败

考虑一下片段:

#include <unordered_map>

void foo(const std::unordered_map<int,int> &) {}

int main()
{
        foo({});
}
Run Code Online (Sandbox Code Playgroud)

这与GCC 4.9.2失败并显示以下消息:

map2.cpp:7:19: error: converting to ‘const std::unordered_map<int, int>’ from initializer list would use explicit constructor ‘std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type, const hasher&, const key_equal&, const allocator_type&) [with _Key = int; _Tp = int; _Hash = std::hash<int>; _Pred = std::equal_to<int>; _Alloc = std::allocator<std::pair<const int, int> >; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::size_type = long unsigned int; std::unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::hasher = std::hash<int>; std::unordered_map<_Key, …
Run Code Online (Sandbox Code Playgroud)

c++ gcc libstdc++ c++11

41
推荐指数
2
解决办法
1万
查看次数

可以定义一个完全通用的swap()函数吗?

以下片段:

#include <memory>
#include <utility>

namespace foo
{
    template <typename T>
    void swap(T& a, T& b)
    {
        T tmp = std::move(a);
        a = std::move(b);
        b = std::move(tmp);
    }

    struct bar { };
}

void baz()
{
    std::unique_ptr<foo::bar> ptr;
    ptr.reset();
}
Run Code Online (Sandbox Code Playgroud)

不为我编译:

$ g++ -std=c++11 -c foo.cpp
In file included from /usr/include/c++/5.3.0/memory:81:0,
                 from foo.cpp:1:
/usr/include/c++/5.3.0/bits/unique_ptr.h: In instantiation of ‘void std::unique_ptr<_Tp, _Dp>::reset(std::unique_ptr<_Tp, _Dp>::pointer) [with _Tp = foo::bar; _Dp = std::default_delete<foo::bar>; std::unique_ptr<_Tp, _Dp>::pointer = foo::bar*]’:
foo.cpp:20:15:   required from here
/usr/include/c++/5.3.0/bits/unique_ptr.h:342:6: error: call of …
Run Code Online (Sandbox Code Playgroud)

c++ gcc libstdc++ argument-dependent-lookup c++11

39
推荐指数
3
解决办法
2112
查看次数

std :: poisson_distribution中C++标准库中的错误?

我想我从C++标准库遇到了std :: poisson_distribution的错误行为.

问题:

  1. 你能否确认它确实是一个错误而不是我的错误?
  2. poisson_distribution函数的标准库代码究竟出了什么问题,假设它确实是一个错误?

细节:

以下C++代码(文件poisson_test.cc)用于生成泊松分布数:

#include <array>
#include <cmath>
#include <iostream>
#include <random>

int main() {
  // The problem turned out to be independent on the engine
  std::mt19937_64 engine;

  // Set fixed seed for easy reproducibility
  // The problem turned out to be independent on seed
  engine.seed(1);
  std::poisson_distribution<int> distribution(157.17);

  for (int i = 0; i < 1E8; i++) {
    const int number = distribution(engine);
    std::cout << number << std::endl;
  }
}
Run Code Online (Sandbox Code Playgroud)

我按如下方式编译此代码:

clang++ -o poisson_test -std=c++11 poisson_test.cc …
Run Code Online (Sandbox Code Playgroud)

c++ libstdc++ c++-standard-library c++11

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

Android SDK - aapt错误:libstdc ++.so.6无法打开共享对象文件

我正在创建一个无中生有的新项目,用于测试目的,在新的ADT安装(Ubuntu Gnome 14.04 LTS,x86_64 CPU)上将所有参数保留为默认值(我没有进行任何代码更改),但我有以下内容Eclipse控制台中的错误:

[2014-06-11 09:03:10 - Kronos] /home/erwan/Applications/ADT/adt-bundle-linux-x86_64-20140321/sdk/build-tools/19.1.0/aapt: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

这是我已经尝试过的:

- >我试图通过Ubuntu软件库(重新)安装ia32-libs,libstdc ++和libstdc ++ 6:没有变化

- >检查更新(对于Eclipse和SDK):没有变化

- >重新安装所有Android Build工具:无变化

- >重新安装亚行:没有变化

linux android adt libstdc++

36
推荐指数
3
解决办法
5万
查看次数

如何将C++目标文件与ld链接

我正在尝试使用ld而不是g ++链接C++的输出.我只是这样做是为了学习如何做,而不是为了实际目的,所以请不要建议只用g ++来做.

看看这个问题,这个人在运行ld命令时会得到同样的错误:

$ ld test.o -o test.out
ld: warning: cannot find entry symbol _start; defaulting to 00000000004000e8
test.o: In function `main':
test.cpp:(.text+0x1c): undefined reference to `strcasecmp'
test.cpp:(.text+0x23): undefined reference to `std::cout'
test.cpp:(.text+0x28): undefined reference to `std::ostream::operator<<(int)'
test.cpp:(.text+0x2d): 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> >&)'
test.cpp:(.text+0x35): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
test.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x75): undefined reference to `std::ios_base::Init::Init()'
test.cpp:(.text+0x7a): undefined reference to `__dso_handle'
test.cpp:(.text+0x84): undefined reference to `std::ios_base::Init::~Init()'
test.cpp:(.text+0x89): undefined …
Run Code Online (Sandbox Code Playgroud)

c++ linker linker-errors ld libstdc++

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

仅使用 std::function 和 std::shared_pointer 在 C++ 标准库中进行双重释放

shared_ptr我最近在 lambda 中捕获 a 时在程序中遇到了一个奇怪的双重释放错误。我能够将其减少为以下最小示例:

#include <memory>
#include <functional>

struct foo {
    std::function<void(void)> fun;
};

foo& get() {
    auto f = std::make_shared<foo>();
    // Create a circular reference by capturing the shared pointer by value
    f->fun = [f]() {};
    return *f;

}

int main(void) {
    get().fun = nullptr;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

使用 GCC 12.2.0 和地址清理程序编译并运行它,会在 中产生双重释放std::function

$ g++ -fsanitize=address -g -Wall -Wextra -o main main.cpp && ./main
=================================================================
==2401674==ERROR: AddressSanitizer: attempting double-free on 0x602000000010 in thread T0:
    #0 …
Run Code Online (Sandbox Code Playgroud)

c++ g++ libstdc++ undefined-behavior compiler-bug

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

构建gcc/libstdc ++时使用了哪些配置选项?

在阅读了DLL和EXE之间传递空对象的问题之后std::string,我担心用于构建我的gcc/libstdc ++的configure选项.更具体我想知道是否--enable-fully-dynamic-string在期间使用./configure.

我在Windows XP上使用MinGW 4.4.0.

  1. 有人知道用于构建此版本的配置吗?

  2. 是否有一般方法可以为任何GNU gcc安装找到此信息?gcc手册没有给我这个主题的暗示.

感谢您的输入!

c++ gcc mingw configure libstdc++

30
推荐指数
1
解决办法
2万
查看次数

为什么将对象引用参数传递给线程函数无法编译?

我使用新的c ++ 11 std::thread接口遇到了问题.
我无法弄清楚如何std::ostream将对a的引用传递给线程将执行的函数.

这是传递整数的示例(在gcc 4.6下按预期编译和工作):

void foo(int &i) {
    /** do something with i **/
    std::cout << i << std::endl;
}

int k = 10;
std::thread t(foo, k);
Run Code Online (Sandbox Code Playgroud)

但是当我尝试传递一个ostream时,它无法编译:

void foo(std::ostream &os) {
    /** do something with os **/
    os << "This should be printed to os" << std::endl;
}

std::thread t(foo, std::cout);
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点,还是根本不可能?

注意:从编译错误看来它似乎来自一个已删除的构造函数...

c++ libstdc++ c++11

29
推荐指数
1
解决办法
2万
查看次数

IOS7(仅)stdlibc ++链接问题

我需要帮助.我有一个使用stdc ++的框架,比如std:string.现在,当我为IOS7创建新的应用程序时,由于stdc ++ lib的问题,链接此框架存在问题:

架构armv7的未定义符号"std :: basic_string,std :: allocator> :: _ Rep :: _ S_empty_rep_storage",引自...

我发现一些奇怪的事情,当我在这个应用程序中将Deplyment目标更改为ios6时,一切正常.使用ios7,我看到错误.

我已经在其他链接器标志中设置了标志:-lstdc ++

知道自己做错了什么吗?

xcode libstdc++ ios7

28
推荐指数
3
解决办法
3万
查看次数

将内存清理程序与libstdc ++一起使用

我希望使用-fsanitize=memoryclang中的标志来分析如下的程序:

#include <string>
#include <iostream>
#include <fstream>
using namespace std;

void writeToFile(){
    ofstream o;
    o.open("dum");
    o<<"test"<<endl; //The error is here.
                     //It does not matter if the file is opened this way,
                     //or with o("dum");
    o.close();
}
int main(){
    writeToFile();
}
Run Code Online (Sandbox Code Playgroud)

据我所知,这个程序是正确的,但是当我使用clang++ san.cpp -fsanitize=memory它时失败(在运行时):

UMR in __interceptor_write at offset 0 inside [0x64800000e000, +5)  
==9685== WARNING: MemorySanitizer: use-of-uninitialized-value  
    #0 0x7f48d0899ae5 (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x7bae5)  
    #1 0x7f48d08d1787 (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xb3787)  
    #2 0x7f48d08d21e2 (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xb41e2)  
    #3 0x7f48d08cfd1e (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0xb1d1e)  
    #4 0x7f48d08b1f2d (/usr/lib/x86_64-linux-gnu/libstdc++.so.6+0x93f2d)  
    #5 0x7f48d16d60f5 in writeToFile() /home/daniel/programming/test/santest.cpp:10 …
Run Code Online (Sandbox Code Playgroud)

c++ libstdc++ clang++ msan memory-sanitizer

28
推荐指数
2
解决办法
3300
查看次数