我正在尝试使用clang ++在OS X 10.7下编译VCMI.
我配置项目是CXX=clang++因为Apple的gcc似乎没有识别所需的-std=c++0x标志.
我添加-stdlib=libc++了CXXFLAGS因为没有那个铿锵甚至找不到#include <array>.
目前我有: CXXFLAGS= -std=c++0x -stdlib=libc++ -Wall -Wextra -Wcast-align -Wpointer-arith -Wno-switch -Wno-sign-compare -Wno-unused-parameter -Wc++11-extensions
问题是我得到以下错误:
clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated
clang: warning: argument unused during compilation: '-ggdb'
StdInc.h:1:9: warning: #pragma once in main file
#pragma once
^
In file included from StdInc.h:3:
In file included from ./../Global.h:32:
In file included from /usr/bin/../lib/c++/v1/algorithm:594:
In …Run Code Online (Sandbox Code Playgroud) 所以我花了最近20个小时尝试在OS X 10.8下运行,我终于让它编译没有错误,但是当我尝试编译一个使用Boost.test的测试用例时,我又回来了在一个受伤的世界里.我应该提一下,我自己编译boost而不是使用二进制文件的原因是因为我想使用c ++ 11和libc ++.
当我编译boost时,我这样称为b2:
./b2 toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-std=c++11 -stdlib=libc++" link=static
Run Code Online (Sandbox Code Playgroud)
它编译所有文件.然后我有这段代码
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE Addition
#include <boost/test/unit_test.hpp>
int addition(int i, int j)
{
return i + j;
}
BOOST_AUTO_TEST_CASE(universeInOrder)
{
BOOST_CHECK(addition(2, 2) == 4);
}
Run Code Online (Sandbox Code Playgroud)
我尝试编译
clang++ -std=c++11 -stdlib=libc++ -g -Wall -v -I/Users/cb/Downloads/boost_1_51_0 tests/arithmetic.cpp -o tests/arithmetic /Users/cb/Downloads/boost_1_51_0/stage/lib/libboost_unit_test_framework.a`
Run Code Online (Sandbox Code Playgroud)
它失败了,给我这个错误:
"/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -o tests/arithmetic /var/folders/pg/4wcxn1j12c3188vqrv0x4w9r0000gn/T/arithmetic-UFmO1B.o /Users/cb/Downloads/boost_1_51_0/stage/lib/libboost_unit_test_framework.a -lc++ -lSystem /usr/bin/../lib/clang/4.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"boost::unit_test::unit_test_main(bool (*)(), int, char**)", referenced from:
_main in …Run Code Online (Sandbox Code Playgroud) 我想使用libc ++ STL库而不是默认的GNU STL从源代码构建OpenCV.LibC++提供更好的C++ 11和C++ 14支持.有可能吗?
我正在尝试构建Android应用程序.当我运行zip对齐工具来优化APK时,我收到以下错误消息:
zipalign: error while loading shared libraries: libc++.so: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我试着安装libc ++
sudo aptitude install libc++
Run Code Online (Sandbox Code Playgroud)
它说:找不到包"libc +".
我终端的快照
尝试在 Mac OS Sierra 中编译我的软件时,我遇到了关于未知编译指示的问题(请参阅下面的代码段)。据一位同事称,该软件可以在 Mac OS X Yosemite 中编译,使用相同的 clang 版本 (4.2.1)。使用的编译标志是:-std=c++11 -stdlib=libc++. 使用stdlibc++不是一个选项,因为它不包括std::shared_ptr.
error: unknown warning group '-Wmaybe-uninitialized', ignored
[-Werror,-Wunknown-pragmas]
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
Run Code Online (Sandbox Code Playgroud)
这是打印出来的 g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
Run Code Online (Sandbox Code Playgroud)
不确定从哪里开始,非常感谢任何输入。
#include <set>
int main()
{
auto coll = std::multiset{ 1, 2, 2, 3, 4, 4, 7 };
}
Run Code Online (Sandbox Code Playgroud)
上面的代码可以用vc++ 2019和编译g++ 9.0,但不能用clang++ 8.0as 编译clang++ -std=c++2a -stdlib=libc++ main.cpp
为什么libc ++不支持多集上的类模板参数推导?
流式传输stringstreamlibstdc ++扩展?这个程序与编译gcc-4.2,gcc-4.7-2 (using -std=c++03)和铛3.2使用-std=c++11和libstdc++(感谢安迪警车,见注释).它不clang 3.2使用-std=c++11和编译-stdlib=libc++.
#include<iostream>
#include<sstream>
int main() {
std::stringstream s; s << "b";
std::cout << "ss: " << s << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
通过查看ofstream的构造函数,它可以采用a std::basic_streambuf<CharT, Traits>*或a basic_ostream& st.字符串流是一个std::basic_istream,但两者都是std::basic_ios<CharT, Traits>如此,我猜它应该工作.
以下更改使代码在clang下编译:
std::cout << "ss: " << s.str() << std::endl;
Run Code Online (Sandbox Code Playgroud)
做正确的方法是什么?cout << s;还是cout << s.str();?
我尝试使用clang和libc ++链接作为我的项目编译cln,它使用ginac(它本身使用cln)需要某些c ++ 11特性.在我尝试的过程中,我发现,与libc ++而不是stdlibc ++的链接应该可以解决问题,所以我最终使用以下命令来配置:
./configure CXX=/usr/bin/clang++ CXXFLAGS="-stdlib=libc++ -std=c++11" LDFLAGS="-stdlib=libc++"
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.但是,在调用make时,我收到以下错误消息:
Making all in src
/bin/sh ../libtool --tag=CXX --mode=compile /usr/bin/clang++ -DHAVE_CONFIG_H -I. - I../autoconf -I../include -I../src -I../include -I../src -stdlib=libc++ -std=c++11 -MT cl_alloca.lo -MD -MP -MF .deps/cl_alloca.Tpo -c -o cl_alloca.lo `test -f 'base/cl_alloca.cc' || echo './'`base/cl_alloca.cc
libtool: compile: /usr/bin/clang++ -DHAVE_CONFIG_H -I. -I../autoconf -I../include - I../src -I../include -I../src -stdlib=libc++ -std=c++11 -MT cl_alloca.lo -MD -MP -MF .deps/cl_alloca.Tpo -c base/cl_alloca.cc -fno-common -DPIC -o .libs/cl_alloca.o
In file included from base/cl_alloca.cc:4:
In file included from …Run Code Online (Sandbox Code Playgroud) libc ++是否维护一个进程范围内部状态,其中代码的一部分中发生的操作可以通过调用std ::*类(例如std :: set)来影响代码的某些远程部分?为了更具体一点,我见过这样的崩溃(仅显示堆栈跟踪的顶部):
std::__1::__tree<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::__insert_unique(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 156, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
解决方法是升级不直接参与崩溃的库,以纠正C++ ABI问题.我很惊讶ABI问题可能会对原因造成影响,并且想知道标准库本身是否有某些状态已损坏?
考虑以下计划:
#include <cstdio>
#include <cmath>
int main()
{
int d = (int)(abs(0.6) + 0.5);
printf("%d", d);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
g++7.2.0输出0(参见此处的现场演示)
g++6.3.0(参见此处的现场演示)
prog.cc: In function 'int main()':
prog.cc:6:26: error: 'abs' was not declared in this scope
int d = (int)(abs(0.6) + 0.5);
^
prog.cc:6:26: note: suggested alternative:
In file included from prog.cc:2:0:
/opt/wandbox/gcc-6.3.0/include/c++/6.3.0/cmath:103:5: note: 'std::abs'
abs(_Tp __x)
^~~
Run Code Online (Sandbox Code Playgroud)
clang++5.0.0输出1(在此处查看现场演示)
clang++3.6.0(点击此处观看现场演示)
prog.cc:6:19: error: use of undeclared identifier 'abs'; did you …Run Code Online (Sandbox Code Playgroud) libc++ ×10
c++ ×8
clang ×4
c++11 ×2
libstdc++ ×2
stl ×2
android ×1
android-ndk ×1
apk ×1
aptitude ×1
boost ×1
c++17 ×1
macos ×1
macos-sierra ×1
opencv ×1
pragma ×1
stringstream ×1
templates ×1
ubuntu-14.04 ×1