我知道还有其他类似的问题,但是(我可以将C++ 11与Xcode一起使用吗?)但主要与旧版本的Osx或xcode相关,所以它们似乎并不是正确的解决方案来继续使用Osx Lion和xcode 4.1.osx Lion对c ++ 0x功能有什么要求?我想我必须使用新的libc ++作为标准库,将LLVM 3.0设置为编译器.是否有一种默认方式让LLVM 3.0在Lion上运行?
编辑:好吧,看起来它只是时间问题,直到LLVM 3.0将成为xcode 4的一部分:http: //oleb.net/blog/2011/07/whats-new-for-developers-in-lion-part-1 /
我收到以下错误:
class Test
{
std::map<std::string,Test> test;
};
Run Code Online (Sandbox Code Playgroud)
错误是"字段具有不完整类型'测试'".我读了一些线程,建议这可能是随xcode附带的libcxx版本中的一个错误,但如果我只需将其更改为:它就不会让我感到惊讶:
class Test
{
std::map<std::string,std::shared_ptr<Test>> test;
};
Run Code Online (Sandbox Code Playgroud)
我只想仔细检查这肯定是一个正确的错误,而不是一个错误.
干杯!
配置了一个std::istringstream在failbit设置时抛出异常的时候我没有用libc ++发生异常(这是在linux下使用libc ++编译并在libcxxrt的支持下编译).我想这是libc ++或libcxxrt中的一个错误:
#include <iostream>
#include <sstream>
template<typename T> std::istream &getvalue(std::istream &is, T &value, const T &default_value = T())
{
std::stringstream ss;
std::string s;
std::getline(is, s, ',');
ss << s;
if((ss >> value).fail())
value = default_value;
return is;
}
int main()
{
std::string s = "123,456,789";
std::istringstream is(s);
unsigned n;
try
{
is.exceptions(std::ios::failbit | std::ios::eofbit);
getvalue(is, n);
std::cout << n << std::endl;
getvalue(is, n);
std::cout << n << std::endl;
// Disable EOF exception on last …Run Code Online (Sandbox Code Playgroud) 这个问题来自这个问题.
使用clang 3.4和libstdc ++ 编译以下代码:
#include <functional>
int main() {
std::function<void()> f = []() {};
}
Run Code Online (Sandbox Code Playgroud)
但是使用clang 3.4和libc ++ 失败了:
In file included from main.cpp:1:
In file included from /usr/include/c++/v1/functional:465:
In file included from /usr/include/c++/v1/memory:599:
/usr/include/c++/v1/tuple:320:11: error: rvalue reference to type '<lambda at main.cpp:4:31>' cannot bind to lvalue of type '<lambda at main.cpp:4:31>'
: value(__t.get())
^ ~~~~~~~~~
/usr/include/c++/v1/tuple:444:8: note: in instantiation of member function 'std::__1::__tuple_leaf<0, <lambda at main.cpp:4:31> &&, false>::__tuple_leaf' requested here
struct __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
^ …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用libc ++,libc ++ abi和clang ++ 3.6.0在Arch Linux x64上编译我的项目.
项目编译正确,但无法链接以下错误:
错误:CMakeFiles/main.cpp.o:对符号'__cxa_thread_atexit @@ CXXABI_1.3.7'的未定义引用
/usr/lib/libstdc++.so.6: - 1:错误:添加符号时出错:命令行中缺少DSO
我正在使用-stdlib=libc++ -lc++abi标志进行编译和链接.
我应该链接哪些额外的库?我错过了一面旗帜吗?
我注意到,使用emscripten,即使是相对较小的C++文件也可以很快变成相当庞大的JavaScript文件.例:
#include <memory>
int main(int argc, char** argv) {
std::shared_ptr<int> sp(new int);
}
Run Code Online (Sandbox Code Playgroud)
使用像这样的命令用最近的emsdk编译它
em++ -std=c++11 -s DISABLE_EXCEPTION_CATCHING=1 -s NO_FILESYSTEM=1 \
-s NO_BROWSER=1 -s NO_EXIT_RUNTIME=1 -O3 -o foo.js foo.cc
Run Code Online (Sandbox Code Playgroud)
生成的文件超过400k.随着-g抛出我可以做
grep -n '^function _' foo.js | c++filt -_
Run Code Online (Sandbox Code Playgroud)
看看我们在那里有什么样的功能.这里有些例子:
std::__1::moneypunct<char, false>::do_thousands_sep() const
std::__1::locale::~locale()
std::__1::basic_string<wchar_t, …>::~basic_string()
std::__1::time_get<…>::__get_day(…) const
std::__1::codecvt<wchar_t, char, __mbstate_t>::codecvt(unsigned int)
std::__1::locale::__imp::install(std::__1::locale::facet*, long)
_printf_core
Run Code Online (Sandbox Code Playgroud)
我自己并没有打电话给任何人,但是所有的功能都包括在内.可能其中许多都包含在一些虚拟功能表中.其他可能是由于一些静态初始化器.
如果这是正常的代码链接到我的硬盘驱动器上的某个共享库; 我不反对.但只需要一个共享指针,就可以传输半兆字节的JavaScript代码?必须有办法避免这种情况.
std :: sort的libcxx(llvm版本的c ++标准库)使用相同的元素调用比较谓词,即比较函子的两个参数都指向要排序的序列中的相同位置.一个简化的例子来说明这一点.
$ cat a.cc
#include <algorithm>
#include <vector>
#include <cassert>
int main(int argc, char** argv) {
int size = 100;
std::vector<int> v(size);
// Elements in v are unique.
for (int i = 0; i < size; ++i)
v[i] = i;
std::sort(v.begin(), v.end(),
[&](int x, int y) { assert(x != y); return x < y; });
return 0;
}
$ clang++ -std=c++11 -stdlib=libc++ a.cc -o a.out
$ ./a.out
a.out: a.cc:14: auto main(int, char **)::(anonymous class)::operator()(int, int) const: Assertion …Run Code Online (Sandbox Code Playgroud) 尝试在Mac上使用pip install安装cvxpy软件包时,收到以下错误消息:
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
In file included from cvxpy/cvxcore/src/cvxcore.cpp:15:
cvxpy/cvxcore/src/cvxcore.hpp:18:10: fatal error: 'vector' file not found
#include <vector>
^~~~~~~~
1 warning and 1 error generated.
error: command '/usr/bin/clang' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
Mac正在运行OS Mojave.
我的macOS版本是 10.14
Xcode版本是 10.2
为clang编写插件。我只是使用以下命令从Github安装llvm和clang。
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build
cd build
cmake -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" ../llvm
Run Code Online (Sandbox Code Playgroud)
然后使用clang --version,它显示:
clang version 10.0.0 (https://github.com/llvm/llvm-project.git 73f702ff192475b27039325a7428ce037771a5de)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: /Users/kim/GitHub/llvm-project/build/bin
Run Code Online (Sandbox Code Playgroud)
现在,我只是尝试编译非常简单的Hello World程序:
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
mkdir build
cd build
cmake -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi" ../llvm
Run Code Online (Sandbox Code Playgroud)
用命令 clang++ test.cpp -o test
但不幸的是,它无法编译错误:
In file included from test.cpp:1:
In file included from /Users/kim/GitHub/llvm-project/build/bin/../include/c++/v1/iostream:37:
In file included from /Users/kim/GitHub/llvm-project/build/bin/../include/c++/v1/ios:214:
In file included from …Run Code Online (Sandbox Code Playgroud) 我注意到在clang的libc ++中std::set::equal_range(与相同std::map)给出的结果与libstdc ++不同。我一直认为equal_range应该返回std::make_pair(set.lower_bound(key), set.upper_bound(key))cppreference和libstdc ++所做的等效。但是在libc ++中,我有一个给出不同结果的代码。
#include <set>
#include <iostream>
#include <iterator>
struct comparator {
using range_t = std::pair<int, int>;
using is_transparent = std::true_type;
bool operator()(int lhs, int rhs) const
{
return lhs < rhs;
}
bool operator()(int lhs, range_t rhs) const
{
return lhs < rhs.first;
}
bool operator()(range_t lhs, int rhs) const
{
return lhs.second < rhs;
}
};
using range_set = std::set<int, comparator>;
int main()
{
range_set set = …Run Code Online (Sandbox Code Playgroud) libc++ ×10
c++ ×8
c++11 ×3
macos ×2
algorithm ×1
c++14 ×1
clang ×1
cvxpy ×1
emscripten ×1
header-files ×1
javascript ×1
lambda ×1
libstdc++ ×1
linker ×1
linux ×1
llvm-clang ×1
map ×1
osx-lion ×1
python ×1
python-3.x ×1
sorting ×1
std ×1
xcode ×1