c++11,gcc,cuda,future , nvcc/CUDA 6.5 & c++11(future) - gcc 4.4.7


nvcc/CUDA 6.5 & c++11(future) - gcc 4.4.7

Question:

Tag: c++11,gcc,cuda,future

When I compile the following code containing the design C++11, I get errors - it does not compile. I've tried with different flags, but I haven't found a solution.

My setting: CUDA 6.5, gcc 4.4.7 I am not able to change the settings. How can I still make this work?

#include <stdio.h>
#include <vector>
#include "KD_tree.h"
#include "KD_tree.cpp"
#include <iostream>
#include <algorithm>
#include <cmath>
#include <future>
#define MYDEVICE 0

using namespace std;


int main()
{
    //do something..... 

    cudaDeviceProp devProp;
    cudaGetDeviceProperties(&devProp, MYDEVICE);
    printDevProp(devProp);
    int max_threads = devProp.warpSize;

   //do something else ... 

    return 0;
}

I've tried compiling with different flags:

nvcc -std=c++11 cudaMain.cu KD_tree.cpp -arch=sm_20 -o tree.out
In file included from cudaMain.cu:14:
simple_kd_tree.h:12:19: warning: extra tokens at end of #include directive
cudaMain.cu:19:18: error: future: No such file or directory


nvcc --std=c++11 cudaMain.cu KD_tree.cpp -arch=sm_20 -o tree.out
In file included from cudaMain.cu:14:
simple_kd_tree.h:12:19: warning: extra tokens at end of #include directive
cudaMain.cu:19:18: error: future: No such file or directory


nvcc --std=c++11 cudaMain.cu KD_tree.cpp -arch=sm_20 -c -o tree.out
nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified

Do I have to split the c++ part? How would I do this exactly?


Answer:

C++11 support is added officially in CUDA 7.0. And you need GCC version 4.7 or later to have C++11 support. See details here: http://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-compiler-new-features


Related:


“Emulating” std::declval issues. Works (kind of) in g++, fails to compile in clang++


c++,c++11,decltype
Trying to better understand std::declval, I came up with the following "toy model" code: #include <iostream> #include <typeinfo> struct Bar { Bar(double); // some non-default ctor double f(); // some function of which return type we want to get }; using Barref = Bar&&; // emulating std::declval<Bar>() int main() {...

Tell C++ that pointer data is 16 byte aligned


c++,gcc,sse,memory-alignment
I wrote some code with static arrays and it vectorizes just fine. float data[1024] __attribute__((aligned(16))); I would like to make the arrays dynamically allocated. I tried doing something like this: float *data = (float*) aligned_alloc(16, size*sizeof(float)); But the compiler (GCC 4.9.2), no longer can vectorize the code. I assume this...

Atomic/not-atomic mix, any guarantees?


c++,multithreading,c++11,atomic
Let's I have GUI thread with code like this: std::vector<int> vec; std::atomic<bool> data_ready{false}; std::thread th([&data_ready, &vec]() { //we get data vec.push_back(something); data_ready = true; }); draw_progress_dialog(); while (!data_ready) { process_not_user_events(); sleep_a_little(); } //is it here safe to use vec? As you see I not protect "vec" by any kind of...

Type function that returns a tuple of chosen types


c++,templates,c++11,metaprogramming
I've implemented a type function Tuple that turn a list of My_enum values into an std::tuple of corresponding types: #include <tuple> enum My_enum{ t_int, t_double }; // Bind_type is a type function that given a My_enum returns the corresponding type template<My_enum E> struct Bind_type; template<> struct Bind_type<t_int>{ using type =...

How to have gcc warn about conversions from uint32_t to uint64_t?


c++,gcc,compiler-warnings
Let's take the following simple example: #include <vector> #include <cstdint> using ::std::vector; using ::std::uint64_t; using ::std::uint32_t; int main(int argc, char *argv[]) { vector<uint64_t> v; uint32_t i = 1; v.push_back(i); return 0; } When I compile it with: g++ -std=c++11 -Wall -Wconversion -Wpedantic a.cpp I don't get any conversion error. However,...

C++ why does SFINAE fail with only a class template parameter?


c++,templates,c++11,sfinae
I'm using SFINAE in the style of this answer in order to call a generic vector object by using an appropriate member function. For example, the following code calls operator[](int) const first, and if that doesn't exist then operator()(int) const: template<int I> struct rank : rank<I-1> { static_assert(I > 0,...

How to check which symbols on my shared library have non-position independent code (PIC)?


linux,gcc,debian,powerpc
I'm trying to build a .deb package with debuild -i -us -uc -b and in the end I see: Now running lintian... warning: the authors of lintian do not recommend running it with root privileges! W: libluajit-5.1-2: hardening-no-relro usr/lib/powerpc64le-linux-gnu/libluajit-5.1.so.2.1.0 E: libluajit-5.1-2: shlib-with-non-pic-code usr/lib/powerpc64le-linux-gnu/libluajit-5.1.so.2.1.0 W: luajit: hardening-no-relro usr/bin/luajit-2.1.0-alpha W: luajit: binary-without-manpage...

How to match one of multiple alternative patterns with C++11 regex [duplicate]


c++,regex,c++11
This question already has an answer here: Strange results when using C++11 regexp with gcc 4.8.2 (but works with Boost regexp) [duplicate] 1 answer With Perl, the following results in a match: echo xyz | perl -ne 'print if (/.*(yes|no|xy).*/);' I'm trying to achieve the same thing with a...

In c++11 what should happen first: raw string expansion or macros?


c++,c++11,preprocessor,rawstring
This code works in visual c++ 2013 but not in gcc/clang: #if 0 R"foo( #else int dostuff () { return 23; } // )foo"; #endif dostuff(); Visual C++ removes the if 0 first. Clang expands the R raw string first (and never defining dostuff). Who is right and why?...

__cplusplus < 201402L return true in gcc even when I specified -std=c++14


c++,gcc,g++,c++14,predefined-macro
The directive: #ifndef __cplusplus #error C++ is required #elif __cplusplus < 201402L #error C++14 is required #endif The command-line: g++ -Wall -Wextra -std=c++14 -c -o header.o header.hpp My g++ version: g++ (tdm-1) 4.9.2 The error C++14 is required is generated even when I added -std=c++14, I don't know why. Please...

Dereferencing a temporary unique_ptr


c++,c++11,unique-ptr
unique_ptr<A> myFun() { unique_ptr<A> pa(new A()); return pa; } const A& rA = *myFun(); This code compiles but rA contains garbage. Can someone explain to me why is this code invalid? Note: if I assign the return of myFun to a named unique_ptr variable before dereferencing it, it works fine....

Sorting vector of Pointers of Custom Class


c++,sorting,c++11,vector
I have vector<FPGA*> current_generation_, which I'd like to sort by FPGA member fitness_ using the sort_members function. Applicable code follows: bool sort_members (FPGA* fpga_first, FPGA* fpga_second) { return (fpga_first->fitness() < fpga_second->fitness()); }; fpga.hpp #include <vector> class FPGA { public: explicit FPGA(int input_gates, int output_gates, int normal_gates); const int fitness(); protected:...

How to check the values of a struct from an image/binary file?


c,gcc,binaryfiles
Is there anyway i can look into the values of a structure after compilation? objdump -td gives the function definitions and only the address where the structure is stored. The problem is i am getting a wrong address for one of the threads/functions in a structure when i run a...

ARM assembly cannot use immediate values and ADDS/ADCS together


gcc,assembly,arm,instructions
I am currently trying to speed up some of my C functions on a Cortex-M0 (Freescale KL25Z) using assembly. I get a problem with this minimal test program: @.syntax unified .cpu cortex-m0 .text .global test .code 16 test: mov r0, #0 adds r0, r0, #1 bx lr When I try...

C++ operator []


c++,c++11,operator-overloading
I am trying to implement the operator [] that is to be used once for Set and once as Get, i need to differentiate between the two cases, as in the case of get, i need to throw an exception if the returned value is equal to -1; whereas in...

How is shellcode generated from C? - With code example


python,c,gcc,assembly,shellcode
I started taking an online course regarding software security. In one of the sections, I was instructed to execute a hidden C function using a buffer overflow. I got to thinking: what would happen if I could pass machine instruction directly to a stack unsafe executable? What I have been...

How to re-write templated function to handle type deduction


c++,templates,c++11
So, I have this search function for the map container: template <typename Key, typename T> void searchInMapByKey(std::map<Key,T> Map, T keyValue) { if(Map.empty()) { std::cout << "Map is empty, nothing to search for..." << "\n"; } else { for(const auto & element : Map) { if(element.first==keyValue) { std::cout << keyValue <<...

Simple thread/mutex test application is crashing


c++,multithreading,c++11,mutex,mingw-w64
I wrote a simple test program which accumulates random samples to a buffer using multiple threads. Each thread uses a stack for reducing the mutex waits. This is for investigating problems in a much larger program. The code currently crashes on mingw-w64 4.9.2 Any idea why? Debugging halts on "signal-received"...

Why is initialization of enum class temporaries with arbitrary values allowed?


c++,c++11
I came across some code like the following in one the CppCon 2014 talks that confused the heck out of me. The audience accepted it without comment, so I presume that it's legal: enum class Foo { Bar }; Foo const v1 = Foo(5); The question is: why does this...

Print addresses of all local variables in C


debugging,pointers,gcc,gdb,memory-address
I want to print the addresses of all the local and global variables which are being used in a function, at different points of execution of a program and store them in a file. I am trying to use gdb for this same. The "info local" command prints the values...

How can I convert an int to a string in C++11 without using to_string or stoi?


c++,string,c++11,gcc
I know it sounds stupid, but I'm using MinGW32 on Windows7, and "to_string was not declared in this scope." It's an actual GCC Bug, and I've followed these instructions and they did not work. So, how can I convert an int to a string in C++11 without using to_string or...

Can't compile C++11 source using GCC 5.1 toolchain


c++,c++11,gcc5
I'm trying to compile a library written with C++11 features using GCC 5.1 on Ubuntu. However, it complains std::unique_ptr is not defined. gcc (Ubuntu 5.1.0-0ubuntu11~14.04.1) 5.1.0 g++ (Ubuntu 5.1.0-0ubuntu11~14.04.1) 5.1.0 CXX flags: -std=c++11 -Wall -Wextra -Weffc++ -pedantic Output: error: ‘unique_ptr’ in namespace ‘std’ does not name a template type std::unique_ptr<...

Constructing priority_queue instance with Compare instance of different type


c++,gcc,constructor,containers
Could anybody please explain why my compiler (GCC) accepts the code below as valid? priority_queue<int, deque<int>, less<int>> pq(greater<int>()); I expect this constructor (for an instance of type having less<int> as Comparator, as specified for priority_queue instance pq) to be incompatible with an instance of greater<int> (passed as constructor parameter), which...

C++ error: deduced conflicting types for parameter 'T' string vs const char *


c++,string,templates,c++11,char
So, I am writing a simple, templated search function for deque container. Here's the code: template <typename T> void searchInDequeFor(std::deque<T> Deque, T searchValue) { for(const auto & element : Deque) { if(Deque.empty()) { std::cout << "Deque is empty, nothing to search for..." << "\n"; } else if(element==searchValue) { std::cout <<...

Mapping const char * to duck-typed T at compile-time or run-time


c++,templates,c++11
I have many classes A, B, C, D, etc that are duck-typed and thus have the same methods and interface but do not inherit from the same class. E.g. class A { public: void foo(); void bar(); } class B { public: void foo(); void bar(); } class C {...

Finding all keys that correspond to same value in std::unordered_map


c++,c++11,stl,c++14
I have an unordered_map looking like this: std::unordered_map<int, std::string> theMap2 = {{1,"a"}, {2,"b"}, {3,"c"}, {4,"a"}}; I want to find all the keys that have same value lets say 1. Any suggestions beside the obvious way: std::vector<int> arrKeys; std::string value = "a"; for (const auto& element : theMap) if (element.secont ==...

Junk varchar entries in MSSQL database using ODBC


c++,sql-server,c++11,odbc
I'm trying to insert a string-variable into a varchar(100)-field, but if the string is longer than 15 elements only junk is inserted (e.g. "0‰?"). First my setup: Development: Win7 (64bit) / VS2013 / C++11 / 64bit Application Database: Win8 (64bit) / Microsoft SQL Server Express 2014 (64bit) Driver: SQL Server...

I think assigning JsonValue values to JsonValues might be very slow, in comparison to having a Value be a key


c++,json,c++11
Json::Value is located in: #include <json/value.h> I have a result Json::Value object being created which will be pushed back to the user. The issue with it is that it takes a super long time to complete, which boggles my mind. I think that there is something off with Json::Value, maybe...

Is executing C++ code in comments with certain Unicode characters allowed, like in Java?


c++,c++11,unicode,comments
I know that executing Java code in comments with certain Unicode characters is allowed. Please see this question for further clarification Executing Java code in comments. So was just curious to know if C++ has such features?

std::move on a C++ class does not move all members?


c++,c++11,move
I understand that using v.push_back(std::move(foo)) will move foo contents to a vector. However I do not understand why the below code : #include <iostream> #include <vector> struct Foo { std::string s; float f; friend std::ostream& operator<<(std::ostream& stream,const Foo& foo) { stream << "{" << foo.s << ":" << foo.f <<...

std::push_heap and std::pop_heap with MoveConstructible objects


c++,c++11,stl,heap,move-semantics
I want to maintain a heap where the payloads are MoveConstructible (because they hold a std::unique_ptr inside.) Although the documentation suggests that the object must be MoveAssignable and MoveConstructible, doing so throws an error both in GCC and Clang. Sample Code I don't use an std::unique_ptr yet, but just disable...

C++11 Allocation Requirement on Strings


c++,string,c++11,memory,standards
I had heard that C++11 was going to require strings to be allocated in contiguous memory. I even thought I saw a stack overflow question on it, but I can't seem to find it. I know that in practice both gcc and Visual Studio do allocate strings contiguously, I'm just...

Can I use STDIN for IPC?


c,gcc,ipc,stdin
Can I use standard input for interprocess communication? I wrote the following gnu c code as an experiment, but the program hangs waiting for input after printing the character defined as val. Neither a newline nor fflush in the sending process seem to alleviate the problem. #include <unistd.h> #include <stdio.h>...

Calling variadic template function with no args failing


c++,c++11
Given the following code: #include <iostream> template <typename... Args> void foo(Args&&... bargs, Args&&... aargs) { std::cout << "Hello" << std::endl; } int main() { foo<int, double>(1, 2.0, 3, 4.0); //OK foo<char>('c', 'd'); // OK foo(); //FAIL } I get the following compiler error: In function 'int main()': 15:9: error: no...

Why is the boolean value within a structure within a vector not being updated?


c++,c++11
This might sound like a very basic question, but I have trying to fix a simple bug for over an hour now and I can't seem to understand what's happening. I have the following structure declaration in my header file: struct StudentBody { string name; Vec2 position; bool disabled; StudentBody(string...

Scoping rules for struct variables in GCC


c,gcc,struct,clang,scoping
Consider the following C program #include <stdio.h> typedef struct s { int x; } s_t; int main() { int x; s_t a; scanf("%d", &x); if (x > 0) { s_t a; a.x = x; } printf("%d\n", a.x); } The a struct variable in the if branch clearly shadows the a...

Reordering vector of vectors based on input vector


c++,c++11,vector,stl,idioms
In a small application, I've been using a std::vector of std::vector<std::string> to temporarily store some data (pulled from a non-SQL database) before processing it and uploading it to a SQL database. Unfortunately, the API from which I am extracting the data does not necessarily return fields in the order specified...

Django MySQLClient pip compile failure on Linux


python,linux,django,gcc,pip
Django documentation as of v1.8 recommends using mysqlclient connector for the framework. I'm attempting to pip install the package on Ubuntu 14.04 with Python 3.4 and running into a GCC error that I'm unable to find reference to. I'm not an expert on compiling software, so was hoping somebody can...

Implicit use of initializer_list


c++,c++11,initializer-list
§[dcl.init.list] 8.5.4/2: The template std::initializer_list is not predefined; if the header <initializer_list> is not included prior to a use of std::initializer_list — even an implicit use in which the type is not named (7.1.6.4) — the program is ill-formed. Does that mean this program is ill-formed? #include <vector> int main()...

Call to implicitly-deleted copy constructor in LLVM(Porting code from windows to mac)


c++,osx,c++11,compiler-errors,llvm
We are in the process of porting some c++ code from windows to mac and are having issues compiling it with LLVM 6.1 using c++11. We are encountering errors all over the place of "Call to implicitly-deleted copy contructor" Some of these errors are popping up in our code. for...

No match for 'operator*' error


c++,c++11
Hello fellow programmers! I was going to write a small program for calculating total pay for different periods of time depending on the amount of hours and the salary that the user enters. I managed to make a small bit of the program but when I try to run it...

Should checking loop conditions be counted towards total number of comparisons?


c++,algorithm,sorting,c++11
I have implemented three different sorting algorithms and now I want to confirm that my approach of counting the total number of comparisons is correct. In my mind, the number of comparisons shouldn't be tied to the conditional branches because if the condition isn't met, the comparison was still made...

How can I simulate a nested function without lambda expressions in C++11?


c++,function,c++11,lambda,allegro
I have the following code: int main(int argc, char **argv) { App app(800, 600); app.add_event_scene(Scene("Event Plot", event_plot)); Image x("sample.png"); struct foo { static void visual_plot() { x.draw(); } }; // Error. app.add_visual_scene(Scene("Visual Plot", foo::visual_plot)); app.run(); return 0; } And I get the following error: ||=== Build: Debug in Joy-Plus-Plus (compiler:...

Native Code: cannot use typeid with -fno-rtti


c++,osx,gcc,android-ndk,vtk
I'm trying to build native code on android because I want to use VTK for my android tablet. However, I am facing some issues when it comes to building one of the vtk examples. I know this problem has been covered here for an objective c issue but I guess...

fatal error: limits.h: No such file or directory


xcode,osx,gcc
On OSX, I can't compile simple programs from the command-line when I use an externally-provided compiler (e.g. gcc-4.8). System headers like limits.h cannot be found. Example error messages: fatal error: limits.h: No such file or directory Or: fatal error: stdio.h: No such file or directory and so on. What's wrong?...

Passing something as this argument discards qualifiers


c++,c++11
Using the below code, i get the following compile error: In static member function ‘static std::string ctedata::Record::getDispatcher<std::basic_string<char> >::impl(const ctedata::Record&, const string&)’: /home/jason/CrownTheEmpire/lib/ctedata/data.h:111:38: error: passing ‘const std::map<std::basic_string<char>, std::basic_string<char> >’ as ‘this’ argument discards qualifiers [-fpermissive] return rec.fieldValues_[field]; ^ In file included from /usr/include/c++/5.1.0/map:61:0, from...

syntax for calling a method on a member with multiple instances


c++11,inheritance,c++14
I the following case template<typename T> class base{ public: void test(){} }; template<typename T> class helper{ public: base<T> t; }; template<typename T, typename ... Ts> class holder: public helper<T>, helper<Ts>... { }; int main(int argc, char *argv[]){ holder<int, short, long> h; h.t.test(); // of course, error here } Which compiles...

Call template function for the value of a pointer out of a template function, in C++


c++,templates,pointers,c++11
I am trying to call a template function for the pointer that was given as template parameter in my calling function. My code is: template <> struct serialize_helper<std::string> { // not important code... } }; template <class T> inline void serializer(const T& obj, StreamType::iterator& res) { if(std::is_pointer<T>::value) { //THIS doesn'...

Same function with and without template


c++,c++11
I am trying to understand a piece of code of C++11. A class contains 2 functions as shown below: class abc { public: void integerA(int x); template<typename typ> void integerA(typ x); }; I am unable to understand benefit of declaring 2 same functions. Why not declare only one template function?...