我正在使用Macbook 1g,Snow Leopard.
几天前我安装了xcode 4.2并为c ++ 0x做了一个测试项目.
我将LLVM 3.0设置为c ++编译器,将C++语言方言设置为C++ 0x,将C++标准库设置为libc ++.
但在建设时,发生了错误.
"iostream" file not found
Run Code Online (Sandbox Code Playgroud)
我觉得最令人困惑.我怎么解决这个问题?
在经历了令人惊讶的小黑客之后,我设法在我的Linux机器上安装了libc ++(因为libstdc ++缺少了东西).不幸的是,由于具有相同名称的功能,我现有的一些代码现已破裂.
通常,以我需要的方式,bind()与套接字相关.但是,libc ++带有自己的bind()函数,基本上就是这个,但没有方便的命名空间来分隔它们.根据墨菲定律,编译器尝试使用错误的函数,并吐出错误.NetBeans没有看到任何问题,因为它实际上是在查看sys/socket.h文件,因为它应该是.
因此,如果这两个函数基本上超出了我的控制范围,那么我如何告诉编译器(clang ++)它应该在特定的头文件中查找而在该函数的其他地方?
让 clang++ 使用 GCC 的 libstdc++ ( -stdlib=stdc++)是很容易的,但是我该如何做相反的事情呢?在 OS X Mavericks 上,c++ 系统库是 libc++,这意味着基本上不能使用 libstdc++(如果你与其他 c++ 库如已经用 libc++ 编译的 boost 混合)。所以,粗略地说,这意味着 G++ 不可用......除非我可以要求它使用 libc++ 而不是 libstdc++。
谢谢。
我正在使用以下脚本g++-libc++在带有 MacPorts 的 Mac OS X 上在 libc++ 之上运行 g++(因此-mp名称。
#! /bin/sh
clangxx=clang++-mp-3.5
gxx=g++-mp-4.9
libcxx_includes=$($clangxx -print-search-dirs |
perl -ne 's{^libraries: =(.*)}{$1/../../../} && print')
exec $gxx -std=c++11 \
-isystem ${libcxx_includes}/include/c++/v1 \
-nostdinc++ -nodefaultlibs \
-lc -lc++ -lc++abi -lgcc_s.10.5 \
-Wl,-no_compact_unwind \
"$@"
Run Code Online (Sandbox Code Playgroud) 我正在使用cmake来管理使用第三方库的项目.
该库可以针对libc ++或libstd ++进行编译/链接(具体取决于版本).
我知道如何告诉cmake针对libc ++或libstdc ++编译/链接我的项目,但我不知道如何检查我使用的库是否是针对libc ++或libstd ++编译/链接的.是否有任何cmake命令来检查?
以下程序尝试std::tuple_element为用户定义的类型提供特化foo.不幸的是,clang-3.5用libc ++拒绝它,但是使用其他编译器或使用其他标准库来clang-3.5接受程序.这是对的吗?如果不是,为什么不呢?
#include <utility>
struct foo {};
namespace std
{
template<size_t, class> struct tuple_element;
template<size_t i>
struct tuple_element<i, foo> {};
}
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译器输出:
$ clang-3.5 -std=c++11 -stdlib=libc++ -lc++ test.cpp
test.cpp:11:8: error: explicit specialization of non-template struct 'tuple_element'
struct tuple_element<i, foo> {};
^ ~~~~~~~~
1 error generated.
$ clang-3.5 -std=c++11 -lstdc++ test.cpp
(no error)
$ g++-4.9 -std=c++11 test.cpp
(no error)
Run Code Online (Sandbox Code Playgroud) 我在使用C++ 11 std::uniform_real_distribution编译Apple LLVM版本7.0.2(clang-700.1.81)时看到了一些奇怪的行为.调用operator()会在分布范围之外呈现结果.下面的最小样本程序再现了麻烦
// Example program
#include <random>
#include <iostream>
#include <string>
template< int power >
constexpr uint64_t power_of_two(){
return 2 * power_of_two< power - 1 >();
}
template< >
constexpr uint64_t power_of_two< 0 >(){
return 1;
}
std::linear_congruential_engine
< uint64_t, 273673163155, 13, power_of_two< 48 >() >
rng;
std::uniform_real_distribution< double > angle_cosine(-1, 1);
int main()
{
std::cout << angle_cosine.a() << " " << angle_cosine.b() << '\n' << std::endl;
for (int i = 0; i < 4; ++i){
std::cout …Run Code Online (Sandbox Code Playgroud) 我知道如何通过白名单在Travis CI上安装LLVM/Clang/libc ++ 3.8 llvm-toolchain-trusty-3.8,但这不存在(或工作)为3.9.
注意我需要的东西libc++experimental.a,其中包含std::experimental::filesystemfor 的实现libc++.
我真的觉得Travis-CI的做事方式有点不灵活,所以如果有一种完全替代的方式来在构建机器上安装特定版本的东西,请启发我并让我摆脱这些愚蠢的限制.我也不想在Travis上构建每一个工具链依赖,这样就太过分了.
我刚刚coroutine在c ++ 2a中编写了一个测试代码。
我用clang 5.0构建代码:
clang++ testcoroutine.cpp -std=c++2a -I../asio_alone -fcoroutines-ts -stdlib=libc++
Run Code Online (Sandbox Code Playgroud)
该代码工作正常。
现在,我想静态链接libc ++。so,以便可以在其他PC上运行a.out,我用google搜索过,但只找到了-static-libstdc++。
我不能使用,-static-libstdc++因为libstdc++不支持coroutine。
如果我使用-static-libstdc ++:
clang++ testcoroutine.cpp -std=c++2a -I../asio_alone -fcoroutines-ts
-static-libstdc++
testcoroutine.cpp:26:10: fatal error: 'experimental/coroutine' file not found
#include <experimental/coroutine>
^~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?
测试代码:
#define ASIO_STANDALONE
#define ASIO_HAS_STD_CHRONO
#ifdef _WIN32
#pragma warning (disable:4819)
#pragma warning (disable:4503)
#pragma warning (disable:4996)
#pragma warning (disable:4100) // unref parameters
#define _CRT_SECURE_NO_WARNINGS
#define NOMINMAX
#define _CRT_NONSTDC_NO_DEPRECATE
#define WIN32_LEAN_AND_MEAN
#endif
#ifdef _WIN32 …Run Code Online (Sandbox Code Playgroud) vcpkg在Linux上默认使用GCC安装包。我看到官方文档提到了自定义三元组方法,但没有提到clang工具链。
如何指定clang和libc++作为vcpkg的默认工具链?
Xcode 10.2现在包含<filesystem>标头。但是,使用编写代码时std::filesystem,我遇到了许多额外的链接错误。
Undefined symbols for architecture x86_64:
"std::__1::__fs::filesystem::path::__filename() const", referenced from:
std::__1::__fs::filesystem::path::filename() const in dump_zip.cpp.o
std::__1::__fs::filesystem::path::filename() const in libxp_parse.a(zipped.cpp.o)
std::__1::__fs::filesystem::path::remove_filename() in libxp_parse.a(zipped.cpp.o)
std::__1::__fs::filesystem::path::has_filename() const in libxp_parse.a(zipped.cpp.o)
std::__1::__fs::filesystem::path::has_filename() const in libxp_parse.a(acf.cpp.o)
Run Code Online (Sandbox Code Playgroud)
我认为需要链接一个额外的库以支持文件系统,但是我无法确定它的位置或位置。知道这叫什么吗?
编辑:libc ++表示这libc++fs是必需的-但是,它似乎并未随Xcode一起分发,至少没有在默认搜索目录中分发。