问题
I have some trouble compiling some code with nvcc. It heavily relies on templates and the like so error messages are hard to read. For example currently I'm getting a message
/usr/include/boost/utility/detail/result_of_iterate.hpp:135:338: error: invalid use of qualified-name ‘std::allocator_traits<_Alloc>::propagate_on_container_swap’
which is not really helpful. No information on where it came from or what the template arguments were. Compiling with e.g. gcc shows some really nice output with candidates and template arguments etc.
Is it anyhow possible to get those with nvcc too? Or at least for the host code? It is impossible to compile with gcc only as cuda functions are used which can't be eliminated.
This question is NOT about that particular error, but on how to get more details from nvcc on ANY error. This one should only serve as an example
Condensed working example (compile with nvcc -std=c++11):
#include <memory>
#include <boost/utility/result_of.hpp>
struct foo{
int operator()(int x){ return x + 42; }
};
typename boost::result_of < foo(int) >::type
bar(int x){ return foo()(x); }
int main(int argc, char**argv){
return bar(argc);
}
Or even less code:
template<typename T>
struct TriggerError{
private:
template<typename _Tp>
static float helper(_Tp*);
static int helper(...);
typedef decltype(helper((T*)0)) privateWrong;
public:
typedef privateWrong SomethingWentWrong;
};
#include <boost/utility/result_of.hpp>
struct foo{
int operator()(int x){ return x + 42; }
};
typename boost::result_of < foo(int) >::type
bar(int x){ return foo()(x); }
int main(int argc, char**argv){
return bar(argc);
}
It seems, that cudafe++ replaces the "type" token with "TriggerError::SomethingWentWrong" for some reason. So this seems to be a CUDA bug.
nvcc --version: Cuda compilation tools, release 7.0, V7.0.27
gcc --version: gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
回答1:
On the main question: There is no flag or anything that makes nvcc output more template information than there already is. The error shown is a syntax error rather than a template instantiation error but it is caused by a bug in CUDA 7.0.
Information on the bug for reference:
The bug occurs only in CUDA 7.0. It was not there in CUDA 6.5 and is fixed in CUDA 7.5RC and up. It only affects C++11 compilation mode (trying to compile the above code in C++98 is supposed to fail) The bug also occurs only with boost 1.5x (possibly 1.50 latest 1.52) where the decltype usage for boost::result_of was introduced. A more minimal example: Compilation error with nvcc and c++11, need minimal failing example
There are 3 possible work-arounds:
- Use
std::result_of
(c++11) - Include
<boost/utility/result_of.hpp>
as the very first include - Use the boost TR1 protocol and define
BOOST_RESULT_OF_USE_TR1
来源:https://stackoverflow.com/questions/31940457/make-nvcc-output-traces-on-compile-error