标签: libc++

在Xcode 4.3.1中使用libc ++时,如何获得合理的变量显示?

我正在使用Xcode 4.3.1的C++ 11语言方言以及libc ++作为标准库.这种组合中的语言支持是惊人的,但调试是折磨.Xcode的"摘要格式"和lldb的摘要格式功能都不会显示任何标准类型(std :: string,std :: vector等)和漂亮的打印.为这些类型编写漂亮的打印机由于其复杂性而非常重要.(例如,std :: string在libc ++中非常复杂.)

在这种情况下,其他开发人员如何为STL类型获得适当的变量显示?或者没有其他人使用libc ++与Xcode/lldb?

debugging lldb libc++ xcode4.3

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

链接调用C++ 11 std :: bind不起作用

调用嵌套std::bind表达式时遇到问题.以下代码演示了此问题.它无法使用libc ++进行编译,但可以使用boost:

#define BOOST 0

#if BOOST
    #include <boost/function.hpp>
    #include <boost/bind.hpp>
    using boost::function;
    using boost::bind;
#else
    #include <functional>
    using std::function;
    using std::bind;
    using std::placeholders::_1;
#endif


int sum(int a, int b) { return a+b; }

// works
template <typename F>
int yeah(F f, int c)
{
    return f(c);
}

// breaks with libc++
template <typename F>
int nope(F f, int c)
{
    return bind(f, c)();
}

// fixes the problem
template <typename F>
int fix1(F f, int c)
{ …
Run Code Online (Sandbox Code Playgroud)

c++ boost-bind c++11 libc++

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

带有clang的C++ 11线程

我想学习使用C++ 11线程来加速我的语言编译(是的,我正在构建一个编译器:x).我试过的第一个样本用clang(3.3 SVN)抛出了几个错误.它在GCC(4.6.3)下编译得很好.

我从llvm.org的SVN下载了clang和libc ++.clang是用GCC(4.6.3)编译的,而libc ++是用clang编译的.两个makefile都是用CMake生成的.

对于clang,我遵循了本指南:http://llvm.org/docs/GettingStarted.html#checkout

对于libc ++,我遵循了本指南:http://libcxx.llvm.org/

我要编译的代码片段(foobar.cpp):

#include <iostream>
#include <thread>

using namespace std;

int main(void) {
    thread t1([](void)->void {
        cout << "foobar" << endl;
    });
}
Run Code Online (Sandbox Code Playgroud)

它编译得很好,clang --std=c++0x -stdlib=libc++ -lpthread foobar.cpp但我收到很多链接器错误:

/tmp/foobar-59W5DR.o: In function `main':
foobar.cpp:(.text+0x21): undefined reference to `std::__1::thread::~thread()'
/tmp/foobar-59W5DR.o: In function `_ZNSt3__16threadC2IZ4mainE3$_0JEvEEOT_DpOT0_':
foobar.cpp:(.text+0x5c): undefined reference to `operator new(unsigned long)'
foobar.cpp:(.text+0x186): undefined reference to `operator delete(void*)'
foobar.cpp:(.text+0x19b): undefined reference to `std::__1::__throw_system_error(int, char const*)'
/tmp/foobar-59W5DR.o: In …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading clang c++11 libc++

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

如何用libc ++ istream_iterator读取文件中的0xFF?

请考虑以下示例代码:

#include <iostream>

using namespace std;

int main()
{
  istreambuf_iterator<char> eos;
  istreambuf_iterator<char> iit(cin.rdbuf());
  int i;
  for (i = 0; iit != eos; ++i, ++iit) {
    cout << *iit;
  }
  cout << endl << i << endl;
}
Run Code Online (Sandbox Code Playgroud)

以及包含以下内容的输入文件:"foo\xffbar":

$ hexdump testin
0000000 66 6f 6f ff 62 61 72
0000007
Run Code Online (Sandbox Code Playgroud)

现在使用clang libc ++ vs gnu libstdc ++进行测试:

$ make test
clang++ -std=c++11 -stdlib=libc++ -Wall -stdlib=libc++ -o bug-libcc bug.cpp
clang++ -std=c++11 -stdlib=libc++ -Wall -stdlib=libstdc++ -o bug-libstd bug.cpp
./bug-libcc < testin
foo …
Run Code Online (Sandbox Code Playgroud)

c++ istream-iterator libstdc++ libc++

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

为LLVM libc ++ 3.3构建静态和共享库

libc++来自SVN 的最新LLVM 3.3附带一个CMakeLists.txt.我是一个CMake新手,但昨天我研究了足够能够libc++在RHEL 6.4 x86_64主机上建立结账.

另外,我能够添加足够的CPack相关命令CMakeLists.txt来生成一个libcxx-3.3.svn-0.el6.x86_64.rpm.但很可能由于是新手CMake,我无法同时构建静态和共享库.

是.我回顾是否有可能让CMake构建同一个库的静态和共享版本?.但是,add_library我不想使用和枚举所有源文件,而是想使用libc++'s CMakeList.txt- 使用的方法APPEND.

我可以通过替换ON下面的第40行来生成静态库,OFF以构建静态库

40  option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
41 
Run Code Online (Sandbox Code Playgroud)

或者我可以保持原样并构建一个共享库.

我还修改了以下几行,例如消除NOT或注释掉第232和233行.但无论我尝试什么,我似乎无法让静态库与共享库一起构建.

232  if (NOT LIBCXX_ENABLE_SHARED)
233    list(APPEND LIBCXX_CXX_FEATURE_FLAGS -D_LIBCPP_BUILD_STATIC)
234  endif()
Run Code Online (Sandbox Code Playgroud)

如何调整CMakeList.txt文件以便同时构建文件?

c++ cmake clang cpack libc++

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

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

使用std :: is_arithmetic的SFINAE std :: isfinite和类似函数

我在将一些代码从VS2013移植到GGC 4.9和Clang 3.5(使用libc ++)时遇到了编译失败.代码的要点是

#include <cmath>

struct Foo
{
    operator double() const { return( 101.0 ); } // Implicit conversion to double
};

int main( int, char** )
{
    Foo foo;

    std::exp( foo );      // Compiles
    std::isfinite( foo ); // Does not

    return( 0 );
}
Run Code Online (Sandbox Code Playgroud)

我相信isfinite调用不会编译,因为isfinitecmath中的函数的返回类型声明为:

typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
Run Code Online (Sandbox Code Playgroud)

因为Foo不是is_arithmetic,isfinite从过载集中删除.isfinite喜欢的朋友也是如此isnan.所以我的问题是这是否是预期的.

标准是否要求函数的参数isfinite实际上直接double或者float可以隐式转换为它们?

另外我有点不确定为什么std::is_arithmeticstd::is_floating_point,不is_arithmetic暗示isfinite …

c++ c++11 clang++ libc++

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

如何获得-std = c ++ 11 w/libstdc ++?

为什么这不起作用:

#include <regex>
int main() {
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

编译为:

clang++ -std=c++11 -stdlib=libstdc++ temp.cpp
temp.cpp:1:10: fatal error: 'regex' file not found
#include <regex>
         ^
1 error generated.


clang++ --version
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin14.5.0
Thread model: posix
Run Code Online (Sandbox Code Playgroud)

如果我能够stdlib成为libc++然后再编译.正则表达式c++11,但clang本身似乎没有问题-std=c++11 -stdlib=libstdc++.至少在我的机器上,它看起来像我可以使用的东西/usr/include/regex.h,但这不是标准的,除了我想使用的正则表达式以外的东西(例如std :: to_string).

这已经想出的原因是因为我想链接到第三方库(对此我没有源),这是符合作为std::string,而不是std::__1::basic_string,但我代码使用std::regexstd::to_string.我不确定是否要引入对boost的依赖.

c++ clang libstdc++ c++11 libc++

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

如何检查是否安装了libc ++?

我正在从源头构建一些东西.我的系统的gcc和stdlibc ++太旧了,但我可以使用一个clang构建.默认情况下,clang使用stdlibc ++,但可以选择安装libc ++以供clang使用.

检查libc ++是否与clang一起安装的最佳方法是什么?

c++ cmake clang libc++

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

为什么在解析为double时此字符串流会失败?

我有以下代码:

#include <string>
#include <iostream>
#include <sstream>

int main()
{
        size_t x, y;
        double a = std::stod("1_", &x);
        double b = std::stod("1i", &y);

        std::cout << "a: " << a << ", x: " << x << std::endl;
        std::cout << "b: " << b << ", y: " << y << std::endl;

        std::stringstream s1("1_");
        std::stringstream s2("1i");

        s1 >> a;
        s2 >> b;

        std::cout << "a: " << a << ", fail: " << s1.fail() << std::endl;
        std::cout << "b: " << …
Run Code Online (Sandbox Code Playgroud)

c++ stringstream libc++

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