My system: macOS Catalina(10.15.4)
Brew config
Clang: 11.0 build 1103
Git: 2.21.0 => /usr/local/bin/git
Curl: 7.64.1 => /usr/bin/curl
Java: 1.8.0_101
macOS: 10.15.4-x86_64
CLT: 11.4.1.0.1.1586360307
Xcode: N/A
Issue: can't include some C++17 headers: execution, filesystem
while can include the other like: any, variant.
Most of C++17 features like structured binding, template parameters deduction etc works.
Example. Trying to build a file with the following code snippet:
#include <numeric>
#include <vector>
#include <iostream>
#include <iterator>
#include <string>
#include <sstream>
#include <utility> //std::pair
#include <tuple> // std::tie
#include <algorithm> // std::clamp
#include <optional> // std::optional
#include <map>
// ... other stuff
#include <execution>
namespace parallel_algoritmhs {
void show() {
std::vector<int> v = {1,2,3,4,5,6};
std::for_each(std::execution::par, v.begin(), v.end(), [](auto& e) {e+=100;});
int main() {
//... use
}
I am building with:
g++ -std=c++17 -fsanitize=undefined -fno-sanitize-recover=all -o main c++17.cpp
Update:
I have tried suggested:
clang -std=c++17 -fsanitize=undefined -fno-sanitize-recover=all -o main c++17.cpp
clang++ -std=c++17 -fsanitize=undefined -fno-sanitize-recover=all -o main c++17.cpp
And getting the same result.
If I comment out code snippet related to different execution strategies, while leaving other code snippets like:
#include <any>
namespace any {
void show() {
std::any v = 42;
v = 4.2;
v = std::string{"hello"};
std::cout << std::any_cast<std::string>(v) << '\n';
}
}
namespace map_cpp17 {
void show() {
std::map<int, std::string> myMap{ { 1, "Gennady" }, { 2, "Petr" }, { 3, "Makoto" } };
auto node = myMap.extract(2);
node.key() = 42;
myMap.insert(std::move(node));
std::map<int, std::string> m1{ { 1, "aa" }, { 2, "bb" }, { 3, "cc" } };
std::map<int, std::string> m2{ { 4, "dd" }, { 5, "ee" }, { 6, "ff" } };
m1.merge(m2);
std::map<int, std::string> m; m.emplace(1, "aaa"); m.emplace(2, "bbb"); m.emplace(3, "ccc");
auto [it1, inserted1] = m.insert_or_assign(3, "ddd"); std::cout << inserted1; // 0
auto [it2, inserted2] = m.insert_or_assign(4, "eee"); std::cout << inserted2; // 1
}
}
Everything compiles
With
#include <execution>
getting:
fatal error: 'execution' file not found
#include <execution>
I wonder what might be the problem behind that and how to fix this.
Thank you!
Update 2:
brew info llvm:
llvm: stable 10.0.0 (bottled), HEAD [keg-only]
Next-gen compiler infrastructure
https://llvm.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/llvm.rb
==> Dependencies
Build: cmake ✔, python#3.8 ✘
Required: libffi ✘
==> Requirements
Build: xcode ✘
==> Options
--HEAD
Install HEAD version
==> Caveats
To use the bundled libc++ please add the following LDFLAGS:
LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"
llvm is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
Update 3:
clang --version
Apple clang version 11.0.3 (clang-1103.0.32.59)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
You're not actually using the Clang you installed. The official LLVM Clang doesn't have a version 11.0! LLVM is only on version 10.0 (check brew info llvm). You're using Apple Clang, which comes with its own installation of libc++. Presumably to catch this exact type of problem, Apple Clang responds to clang --version/clang++ --version with the "future" version 11.0. However, Apple's distribution is actually a bit behind the state of the art, and it simply isn't updated to these features.
When you install LLVM with Homebrew, it doesn't automatically set it up the new clang/clang++ to be easily callable, because things might expect clang to specifically mean "Apple Clang" and break if that changes. You should add /usr/local/opt/llvm/bin (which Homebrew symlinks into the LLVM installation) to your PATH (which is where your shell and other programs search for programs). In an already running shell session
export PATH="/usr/local/opt/llvm/bin:$PATH"
will switch to using the newly installed LLVM Clang until you exit the session. Putting this line in a shell startup file, like ~/.bash_profile, will set up this adjustment to be applied every time you open a new shell.
Alternatively, like #Eljay does, you could just manually type out the full path to the new clang/clang++ (/usr/local/opt/llvm/bin/clang/-++), thereby bypassing the search into PATH, but that's a pain. In any case, you'll know you got it right if clang --version/clang++ --version gives you 10.0.0.
I have the following very simple program that seems to fail on the Intel compiler but not gcc when using boost::lexical_cast (boost version 1.67.0):
#include <boost/lexical_cast.hpp>
#include <string>
#include <iostream>
float getSomeNumber()
{
return 10.0;
}
int main(int argc, char** argv)
{
std::string mystring("Hello: " + boost::lexical_cast<std::string>(getSomeNumber());
std::cout << mystring << std::endl;
return 0;
}
When compiling, Intel returns the following error:
/boost/1.67.0/include/boost/type_traits/is_complete.hpp(45): warning #70: incomplete type is not allowed
ok_tag<sizeof(T)> check_is_complete(int);
detected during ....
...
/boost/1.67.0/include/boost/type_traits/is_complete.hpp(51): error: template instantiation resulted in unexpected function type of "boost::detail::ok_tag<1U> (int)" (the meaning of a name may have changed since the template declaration -- the type of the template is "boost::detail::ok_tag<sizeof(T)> (int)")
...
detected during:
instantiation of "boost::detail::check_is_complete" based on template argument <void> at line 51
instantiation of class "boost::is_complete<T> [with T=void]" at line 484 of "/Path/to/boost/include/boost/type_traits/is_convertible.hpp"
...
instantiation of "Target boost::lexical_cast<Target, Source>(const Source &) [with Target=std::string, Source=float]" at line 11 of "boostTest.cc"
The best I can tell from this error is it seems like the compiler can't complete the template resolution, but then the very end it seems like it does? I tried compiling the same thing under gcc (version 4.8.5) and it worked fine. This code also previously worked fine under boost 1.64.0 with both gcc and Intel.
Is this a bug in the Intel Compiler, or perhaps a bug in boost? Is there a way to modify my program as a workaround?
Software versions
gcc: 4.8.5
Intel Compiler: 2015.3.187
Boost: 1.67.0
OS: RHEL 7.5 (Maipo)
Compile line:
icpc/gcc --std=c++11 boostTest.cc -o boostTest -Ipath/to/boost/include -lstdc++
I have a C++ program that will not compile under OS X 10.8.5 with the g++ compiler. The problem seems to be with the math.h header file.
This is the version of g++ is
g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/Users/densmore3/local/usr/local/bin/../libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/lto-wrapper
Target: x86_64-apple-darwin14.0.0
Configured with: ../gcc-4.9-20141029/configure --enable- languages=c++,fortran
Thread model: posix
gcc version 4.9.2 20141029 (prerelease) (GCC)
There are 40-50 errors of the type below. The code compiled fine on 10.6. What is going on?
/Users/xxxx/local/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/include-fixed/math.h:203:1: error: ‘__header_always_inline’ does not name a type
__header_always_inline int __inline_isfinitef(float);
Users/densmore3/local/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/include-fixed/math.h:580:27: error: expected initializer before ‘__AVAILABILITY_INTERNAL__MAC_10_0_DEP__MAC_10_9’
extern float __inff(void) __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
Here is a piece of test code that gives the same error as my real code. The error goes away if I remove the math.h include statement.
#include <iostream>
#include <math.h>
#include <stdio.h>
//#include <complex>
//#include <vector>
int main(int argc, const char * argv[])
{
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
The compile command I am using is:
g++ test.cpp
gcc-4.8 is the correct version to use on OS X 10.8.
I read it here that CUDA 6.5 has started support for C++11 :
https://groups.google.com/forum/#!topic/thrust-users/R37GIkMG4tk
But when I compile an example code below, I got
$ nvcc -std=c++11 cu-gcc11.cu -o test
nvcc warning : The -c++11 flag is not supported with the configured host compiler. Flag will be ignored.
cu-gcc11.cu(7): error: explicit type is missing ("int" assumed)
My setting : CUDA 6.5, g++ 4.5, ubuntu 12.04
Codes :
#include <cuda.h>
#include <iostream>
__host__ void test() {
float a = 12.;
double b = 3.;
auto c = a * b;
std::cout << c << std::endl;
}
int main()
{
test();
return 0;
}
C++11 support in nvcc is experimental at this time. In order to properly use it you will need an appropriate configuration. This is not documented anywhere AFAIK, but you should have good results with either Fedora 20 or Ubuntu 14.04, both of which are supported configs for cuda 6.5 and include GCC 4.8.x.
In your case your GCC version is just too old.
I don't think -std=c++11 was available in GCC 4.5. Try -std=c++0x.
I'm having trouble working with lambda functions in the Intel compiler, in particular, the following code won't compile:
template<typename T>
std::function<T (int)> make_func(T x) {
return [=](int index) -> T
{
return x;
};
}
The error I get is
error: namespace "std" has no member "function"
The code compiles and runs fine on my Mac, (macports gcc version 4.5). The error is at work, where we use the Intel compiler version 11.1. It does accept lambda functions (with the -std=c++0x option), such as:
auto lam = [=](int j) -> int {
printf("testing for lambdas: %d\t%d\n", n, j);
return n;
};
int g = lam(7);
The version of gcc installed at work is 4.1.2, so I'm guessing that the standard library is old?
/bin/libc.so.6
says it's version 2.5 compiled with gcc 4.1.2.
Is there a way around this?
thanks in advance for any help
I get the same behavior with icc 11.1 on a system where gcc 4.5.2 is installed.
g++'s header <functional> is protected with #ifdef __GXX_EXPERIMENTAL_CXX0X__ which is not defined when icc is used.
I would consider switching to boost::function in this setup, which of course works with icc.
Well, the code shown doesn't include a single header. And yet you refer to the standard library std::function.
So no, it doesn't compile. As with any other part of the standard library, you need to include the header where std::function is defined: <functional>.