我有一个导入cmath的简单C++程序。 #include <cmath>
int main() {
return 0;
} 我正在尝试使用以下命令编译它。 clang++ -o test main.cpp -std=c++14 但是,我得到了以下错误 In file included from main.cpp:2:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:317:9: error:
我重复了两次相同的计算,但是在一个中,我得到了一个浮点异常,而另一个没有。
#include <iostream>
#include <cmath>
#include <fenv.h>
using namespace std;
int main(void)
{
feenableexcept(-1);
double x,y,z;
x = 1.0;
y = (1.0/(24.3*24.0*3600.0))*x;
cout << "y = " << y << endl;
z =
考虑到,请考虑下面的程序。
#include <cmath>
#include <cstring>
int main()
{
constexpr auto a = std::pow(2, 10);
constexpr auto b = std::strlen("ABC");
}
正如预期的那样,MSVC++和clang++无法编译它,因为constexpr变量是从未声明为constexpr的函数初始化的。
然而,g++会编译这一点。g++的版本似乎并不重要。
g++是如何做到这一点的?这是否正确(允许)编译器行为?
出于某种原因,clang++ (但不是g++)抱怨:
constexpr double invdecayf1m(double x) {
return -log1p(-x);
}
告诉我
non-constexpr function 'log1p' cannot be used in a constant expression
return -log1p(-x);
为什么未在<cmath>中声明为
我有一个运行macOS 10.12的Jenkins构建服务器。 我正在使用最新的Clang10(不是AppleClang)和CMake 3.17编译一个C++应用程序。 我得到的错误是: The C++ compiler
"/Users/XXX/llvm/bin/clang++"
is not able to compile a simple test program.
It fails with the following output:
ld: unknown option: -platform_version
clang-10: error: linker fa
我知道g++支持常量表达式数学函数。我想在clang++上做到这一点。所以我写了一段简单的代码。
#include<iostream>
#include<cmath>
int main()
{
constexpr auto a(std::floor(4.3));
std::cout<<a<<std::endl;
}
然后使用clang++-libc++ -std=c++1y编译它,得到以下错误:
error: constexpr variable 'a' must be initialized by a constant
问题解决了=>参见末尾的更新
我正在尝试使用std::function,但它看起来只是包含<functional>,而不是提供定义。我试图编译以下代码:
#include <functional>
std::function<int(int)> f = nullptr;
使用c++11作为编译选项:
% clang++ -c -std=c++11 t.cc
原因:
t.cc:3:6: error: no type named 'function' in namespace 'std'
std::function<i
我已经将系统更新到macOS Catalina10.15.6,我遇到了https://stackoverflow.com/a/61519060/3616359描述并解决的问题。我遇到了如下问题: /usr/local/include/boost/math/special_functions/fpclassify.hpp:552:17: error:
no member named 'isnan' in namespace 'std'; did you
mean simply 'isnan' 我只是在/Library/Developer/Comm
我花了几个小时试图找出为什么我不能编译使用的应用程序,因为它的全局名称空间中没有成员相关的几个错误:
In file included from lib/spdlog/include/spdlog/fmt/bundled/format.h:38:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:325:9: error: no member named 'isless' in the global namespace
using ::isless;
~~^
/Library/De
当我使用Mac终端和skm库在C++中编译一个简单的hello world程序时,我得到了这个警告。我是个新手,所以不知道该怎么做。
ld: warning: dylib (/Users/chriscommon/.splashkit/lib/macos/libSplashKit.dylib) was built for newer macOS version (10.15.4) than being linked (10.15)
ld: warning: object file (/Users/chriscommon/.splashkit/clang++/lib/macos/libSplash
在我尝试安装的任何R包中,都会收到以下错误消息: ld: library not found for -lintl
collect2: error: ld returned 1 exit status
make: *** [utf8.so] Error 1 我不确定如何使其成为reprex,但我正在运行:R版本4.0.2 (2020-06-22)平台: x86_64-apple-darwin19.5.0 (64位)在macOS Catalina 10.15.5下运行 这个错误消息(ld: library not found for -lintl)是什么意思,我如何修复它才能安装R包(我尝试过
在试图在MacOS Big上编译一个基于for循环的简单范围时,我收到了以下警告:
warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
我尝试使用clang++和g++,但两者都发出了相同的警告。是否有一种不用使用C++11和别名就可以使用-std=c++11进行编译的方法?
编辑:我不喜欢使用-std=c++11的原因是我希望编译器默认为C++11或更高版本。
考虑下列方案:
#include <cstdio>
#include <cmath>
int main()
{
int d = (int)(abs(0.6) + 0.5);
printf("%d", d);
return 0;
}
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
我需要在我的项目中使用C++ 17的文件系统头。据我所知,苹果最终推出了Xcode 11和macOS Catalina。我使用的是最新的(beta 3) Xcode 11,我使用的是macOS Catalina公共beta 2,所以理论上它应该能工作。但出于某种原因,它不是,Xcode提供了如下错误:
'~path' is unavailable: introduced in macOS 10.15
如果我将构建设置中的C++标准库设置为来自libc++的libstdc++,那么这些错误就消失了,我得到了一个警告:
include path for stdlibc++ head
Apple仅支持前两个主要操作系统版本。这导致了Docker和Homebrew放弃了对这些的支持。在撰写这篇文章时,Catalina macOS是当前版本,而最后支持的版本是macOS Catalina。对于macOS Catalina,最低硬件要求是MacBook Pro/Air Mid 2012。许多仍然很好的电脑都不及格。但是如何在旧的Mac上设置Docker和DDEV,这只能运行例如macOS High Sierra to。