CUDA 6.5 with g++ does not support c++11? - c++

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.

Related

C++20 modules on clang (Windows): typeinfo error in simplest example

File first_module.cppm
export module first_module;
int foo(int x) {
return x;
}
export int e = 42;
export int bar() {
return foo(e);
}
Pre-compiling (no problems):
$ clang++ --std=c++20 -fmodules --precompile first_module.cppm -o first_module.pcm
Compiler information:
$ clang++ -v
clang version 10.0.0
Target: x86_64-pc-windows-msvc
File first-main.cc
import first_module;
int main() {
return bar();
}
Compiling (no problems):
$ clang++ --std=c++20 -fmodules first-main.cc -fmodule-file=first_module.pcm first_module.pcm
Everything is ok.
File second-main.cc
import first_module;
#include <iostream>
int main() {
std::cout << bar() << std::endl;
}
Compiling same way:
$ clang++ --std=c++20 -fmodules second-main.cc -fmodule-file=first_module.pcm first_module.pcm
Result: ton of errors like:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\include\eh.h:56:14: error: reference to 'type_info' is ambiguous
_In_ type_info const& _Type,
^
note: candidate found by name lookup is 'type_info'
note: candidate found by name lookup is 'type_info'
I have feeling that I am doing something wrong, because I have newest MSVS (updated recently), newest clang, but something still not working on Windows on trivial examples.
Or may be this is known bug? Tried to google it, no results.
The core problem resides in that your current Clang installation it's working with the MSVC toolchain and there's a known issue when you compile using #include directives with the Microsoft toolchain with Clang using the modules feature.
You can find it here, opened since 2018
https://github.com/llvm/llvm-project/issues/38400

Can't compile C++ 17 structured bindings

The following code
#include <iostream>
#include <tuple>
int main()
{
auto [i, c, d] = std::make_tuple(1, 'a', 2.3);
std::cout << "i=" << i << " c=" << c << " d=" << d << '\n';
return 0;
}
doesn't get compiled on my computer. I get these error messages:
error: use of undeclared identifier 'i'
error: expected unqualified-id
and some more of the same type.
I'm using: Mac OS X 10.11.6 El Capitan, CLion. I did choose the C++ 17 option when I created the project and my CMakeList.txt has this line:set(CMAKE_CXX_STANDARD 17).
clang --version - Apple LLVM version 8.0.0 (clang-800.0.42.1)
What do I need to do to compile this code?
As #Eljay said in the comments, older versions of clang did (do) not have complete C++17 support.
I have reproduced this issue w/o CLion.
On a 10.11.6 machine, using "Apple LLVM version 8.0.0 (clang-800.0.42.1)"
clang++ -std=c++1z junk.cpp
gives the errors that the OP reported. (Note that -std=c++17 is not a valid option here - that came later)
On a 10.14.2 machine, using "Apple LLVM version 10.0.0 (clang-1000.10.44.4)"
clang++ -std=c++17 junk.cpp
compiles w/o error.

C++ math.h on OS X 10.8.5

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.

Error when compiling gcc 4.6.1 C++0x threading code on MacOSX Lion

When compiling the following code:
#include <iostream>
#include <thread>
using namespace std;
void hello()
{
cout << "Hello World!" << endl;
}
int main()
{
cout << "starting" << endl;
thread t(hello);
t.join();
cout << "ending" << endl;
return 0;
}
using:
$ g++-4.6.1 -std=c++0x -pthread threading.cpp
I get the following error:
threading.cc: In function ‘int main()’:
threading.cc:13:2: error: ‘thread’ was not declared in this scope
threading.cc:13:9: error: expected ‘;’ before ‘t’
threading.cc:14:2: error: ‘t’ was not declared in this scope
This is on MacOSX Lion with a custom built gcc 4.6.1. All the other c++0x features that are valid for gcc 4.6 works like a charm. Is this a MacOSX specific error?
std::thread (and the rest of the C++11 thread library) is only available for some of the platforms supported by gcc 4.6.1. Unfortunately for you, MacOSX is not one of those platforms.
My commercial Just::Thread library provides the C++11 thread facilities for 32-bit MacOSX with gcc 4.5, but gcc 4.6 is not supported yet.
See http://gcc.gnu.org/PR50196 - Mac OS X doesn't support some parts of pthreads that we rely on. Building the latest version won't help, but it might be fixed for GCC 4.7

Compiling with operator() under GCC 3.3 Problem in Boost

I have the following snippet:
#include <boost/random/lognormal_distribution.hpp>
#include <boost/random/lagged_fibonacci.hpp>
int main() {
const double mean = 0.0;
const double sigma = 1.0;
boost::lognormal_distribution<double> lognorm_dist(mean, sigma);
boost::lagged_fibonacci44497 engine;
// the following line give error in GCC 3.3
const double value = lognorm_dist.operator() <boost::lagged_fibonacci44497>((engine));
}
It compile fine under
i686-apple-darwin9-g++-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465)
But under:
g++ (GCC) 3.3.3 (SuSE Linux)
It gave the following error:
Mycode.cc:10:error: `operator()' not defined
How can I fix the problem?
Why not just lognorm_dist( engine );? Providing "function-like" syntax is the whole point of operator(). That said, lognorm_dist.template operator() <boost::lagged_fibonacci44497>((engine)) should solve your compilation issues if I am not mistaken.