Trouble with nvcc and c++ strings.

Hello, I’ve got trouble compiling anything using C++ strings and CUDA at the same time.

The problem occurs even in programs as simple as:

#include <string>

int main(int argc, char** argv) {

	return 0;

}

I’m compiling with:

nv test.cu

(either with -cuda or without it)

I get following errors:

/usr/include/c++/4.3/bits/basic_string.h(2462): error: incomplete type is not allowed

		  detected during instantiation of "std::basic_istream<_CharT, _Traits> &std::getline(std::basic_istream<_CharT, _Traits> &, std::basic_string<_CharT, _Traits, _Alloc> &) [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]"

/usr/include/c++/4.3/bits/basic_string.h(2462): error: no instance of overloaded function "std::getline" matches the argument list

			argument types are: (std::basic_istream<char, std::char_traits<char>>, std::basic_string<char, std::char_traits<char>, std::allocator<char>>, <error-type>)

		  detected during instantiation of "std::basic_istream<_CharT, _Traits> &std::getline(std::basic_istream<_CharT, _Traits> &, std::basic_string<_CharT, _Traits, _Alloc> &) [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]"

/usr/include/c++/4.3/bits/basic_string.h(2462): error: incomplete type is not allowed

		  detected during instantiation of "std::basic_istream<_CharT, _Traits> &std::getline(std::basic_istream<_CharT, _Traits> &, std::basic_string<_CharT, _Traits, _Alloc> &) [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]"

/usr/include/c++/4.3/bits/basic_string.h(2462): error: no instance of overloaded function "std::getline" matches the argument list

			argument types are: (std::basic_istream<wchar_t, std::char_traits<wchar_t>>, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>, <error-type>)

		  detected during instantiation of "std::basic_istream<_CharT, _Traits> &std::getline(std::basic_istream<_CharT, _Traits> &, std::basic_string<_CharT, _Traits, _Alloc> &) [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]"

4 errors detected in the compilation of "/tmp/tmpxft_00002ba4_00000000-4_test.cpp1.ii".

g++ and nvcc version information:

g++ (Debian 4.3.1-9) 4.3.1

Copyright (C) 2008 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
nvcc: NVIDIA (R) Cuda compiler driver

Copyright (c) 2005-2007 NVIDIA Corporation

Built on Fri_Nov__7_06:20:13_PST_2008

Cuda compilation tools, release 2.1, V0.2.1221

gcc 4.3 isn’t officially supported–try going back to 4.2 or 4.1.

Worked, thanks a lot!

I’m still having issues with this using the above empty program that just includes .

I’m using Ubuntu 8.04 and CUDA 2.1.

> gcc -v

Using built-in specs.

Target: i486-linux-gnu

Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu

Thread model: posix

gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu3)
> nvcc --version

nvcc: NVIDIA (R) Cuda compiler driver

Copyright (c) 2005-2007 NVIDIA Corporation

Built on Wed_Dec__3_18:29:25_PST_2008

Cuda compilation tools, release 2.1, V0.2.1221
> nvcc test.cu

/usr/include/c++/4.2/bits/basic_string.h(2441): error: incomplete type is not allowed

		  detected during instantiation of "std::basic_istream<_CharT, _Traits> &std::getline(std::basic_istream<_CharT, _Traits> &, std::basic_string<_CharT, _Traits, _Alloc> &) [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" 

/usr/include/c++/4.2/bits/basic_string.h(2441): error: no instance of overloaded function "std::getline" matches the argument list

			argument types are: (std::basic_istream<char, std::char_traits<char>>, std::basic_string<char, std::char_traits<char>, std::allocator<char>>, <error-type>)

		  detected during instantiation of "std::basic_istream<_CharT, _Traits> &std::getline(std::basic_istream<_CharT, _Traits> &, std::basic_string<_CharT, _Traits, _Alloc> &) [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]" 

/usr/include/c++/4.2/bits/basic_string.h(2441): error: incomplete type is not allowed

		  detected during instantiation of "std::basic_istream<_CharT, _Traits> &std::getline(std::basic_istream<_CharT, _Traits> &, std::basic_string<_CharT, _Traits, _Alloc> &) [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]" 

/usr/include/c++/4.2/bits/basic_string.h(2441): error: no instance of overloaded function "std::getline" matches the argument list

			argument types are: (std::basic_istream<wchar_t, std::char_traits<wchar_t>>, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>, <error-type>)

		  detected during instantiation of "std::basic_istream<_CharT, _Traits> &std::getline(std::basic_istream<_CharT, _Traits> &, std::basic_string<_CharT, _Traits, _Alloc> &) [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]" 

4 errors detected in the compilation of "/tmp/tmpxft_00003cf1_00000000-4_test.cpp1.ii".

It works OK using gcc version 4.1.3 20080308 (prerelease) (Ubuntu 4.1.2-21ubuntu1). However, if I replace with with gcc 4.1, then I get these errors:

/usr/include/c++/4.1.3/bits/ios_base.h:408: error: declaration of ‘typedef class std::streampos std::ios_base::streampos’

/usr/include/c++/4.1.3/bits/postypes.h:210: error: changes meaning of ‘streampos’ from ‘typedef class std::fpos<__mbstate_t> std::streampos’

/usr/include/c++/4.1.3/bits/ios_base.h:409: error: declaration of ‘typedef std::streamoff std::ios_base::streamoff’

/usr/include/c++/4.1.3/bits/postypes.h:72: error: changes meaning of ‘streamoff’ from ‘typedef int64_t std::streamoff’

Both and worked with nvcc release 2.0, V0.2.1221 and the same gcc 4.1.

FYI, here’s how I got gcc 4.1 to work on Debian Lenny (which uses 4.3 by default).

  1. sudo apt-get install gcc-4.1

  2. add “–compiler-bindir=/usr/bin/gcc-4.1” to the nvcc command line, then it works (even though /usr/bin/gcc-4.1 is the binary itself, not a directory).

Using the same tricks for gcc-4.2, the build fails.

this will be fixed in the 2.2 release

I was able to fix the problem by editing the following files:

/usr/include/c++/4.3.2/bits/basic_string.h (line 2462)

/usr/include/c++/4.3.2/bits/basic_string.tcc (lines 1120, 1135)

and removing the template for the getline function. Now I can compile my CUDA application with gcc 4.3 on Fedora 10.

Did you manage to fix that? Having the same set of problems…

I’ve faced the same problem, anybody know how to solve?

/usr/include/c++/4.2/bits/basic_string.h(2441): error: incomplete type is not allowed

		  detected during instantiation of "std::basic_istream<_CharT, _Traits> &std::getline(std::basic_istream<_CharT, _Traits> &, std::basic_string<_CharT, _Traits, _Alloc> &) [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]"

/usr/include/c++/4.2/bits/basic_string.h(2441): error: no instance of overloaded function "std::getline" matches the argument list

			argument types are: (std::basic_istream<char, std::char_traits<char>>, std::basic_string<char, std::char_traits<char>, std::allocator<char>>, <error-type>)

		  detected during instantiation of "std::basic_istream<_CharT, _Traits> &std::getline(std::basic_istream<_CharT, _Traits> &, std::basic_string<_CharT, _Traits, _Alloc> &) [with _CharT=char, _Traits=std::char_traits<char>, _Alloc=std::allocator<char>]"

/usr/include/c++/4.2/bits/basic_string.h(2441): error: incomplete type is not allowed

		  detected during instantiation of "std::basic_istream<_CharT, _Traits> &std::getline(std::basic_istream<_CharT, _Traits> &, std::basic_string<_CharT, _Traits, _Alloc> &) [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]"

/usr/include/c++/4.2/bits/basic_string.h(2441): error: no instance of overloaded function "std::getline" matches the argument list

			argument types are: (std::basic_istream<wchar_t, std::char_traits<wchar_t>>, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t>>, <error-type>)

		  detected during instantiation of "std::basic_istream<_CharT, _Traits> &std::getline(std::basic_istream<_CharT, _Traits> &, std::basic_string<_CharT, _Traits, _Alloc> &) [with _CharT=wchar_t, _Traits=std::char_traits<wchar_t>, _Alloc=std::allocator<wchar_t>]"