Here is the problem...
For school project I need to write parallel application using CUDA C. Even the most simple example will not compile. I'm using Windows7 and MS visual studio. The code is taken from the book: CUDA by example. An introduction to general purpose GPU computing.
#include<iostream>
#include<cuda.h>
using namespace std;
__global__ void kernel(void){
}
int main(){
kernel<<<1, 1>>>();
cout << "Hello world" << endl;
return 0;
}
Here are the errors:
1>c:\users\administrator\documents\visualstudio2010\projects\test\test\test.cpp(6): error C2144: syntax error : 'void' should be preceded by ';'
1>c:\users\administrator\documents\visualstudio2010\projects\test\test\test.cpp(6): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\administrator\documents\visualstudio2010\projects\test\test\test.cpp(10): error C2059: syntax error : '<'
Do I need to set nvcc.exe as default compiler instead of cl.exe? If that is the case, how to do it?
Any help is much appreciated!
CUDA code needs to be written in a .cu file and compiled with the NVCC compiler. You are seeing the above errors because you have written your code in a .c or .cpp file and are trying to compile it with a C++ compiler (the Visual C++ compiler).
You have chosen the right book to learn CUDA from. However, you are not following all the steps given in the book. Please have a look at the details of compilation in the book :-)
Related
I'm using Visual Studio 2013 to create a new MFC Application.
I created the application using the setup wizard, left it on all the default values.
When testing if it even runs before adding anything it gave the compile error:
IntelliSense: identifier "D3DCOLORVALUE" is undefined
followed by a lot of:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Why would this be happening in a stock standard application straight out of the wizard? And how would I get this working?
d2dbasetypes.h was giving the error when trying to define D2D_COLOR_F.
I googled the base type (D3DCOLORVALUE) and found that it's supposed to be in "D3D9Types.h"
I added #include "D3D9Types.h" to the top of the d2dbasetypes header file and it seems to have fixed the problem.
I don't know why this isn't included in the generated code by default...
I'm getting a weird error when trying to call a vector element's function. For example, if I do this
However it works fine if I do this:
The code runs fine in Visual Studio, so is this a bug with Eclipse CDT?
P.S. ignore the endl bug
EDIT:
Compiler error from Visual C++
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\Include\vector(1494) : error C2528: '_Ptr' : pointer to reference is illegal
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\Include\vector(1658) : error C2528: '_Pval' : pointer to reference is illegal
Compiler error from MinGW
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_vector.h:87:68: error: using invalid field 'std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_M_finish'
c:\mingw\lib\gcc\mingw32\4.8.1\include\c++\bits\stl_vector.h:87:68: error: using invalid field 'std::_Vector_base<_Tp, _Alloc>::_Vector_impl::_M_end_of_storage'
Note that it compiles fine in Visual Studio
EDIT 2:
ok so...now it works for some reason. Yes I was wrong for choosing the back() method as an example, because it was failing for any method I tried. But for some reason, after a couple days of this problem, Eclipse fixed itself, and now the only error message I get from this code is
..\src\main.cpp:48:21: error: 'class std::basic_string<char>' has no member named 'back'
I wouldn't be surprised if the issue came back though, but I guess it really is a problem with Eclipse, either with the IDE itself or with my environment/linker settings
It appears that std::basic_string::back is new in C++11. So unless you compile in C++11 mode (using -std=c++11 for gcc, for example), it's not going to compile. Here's the complete test code I used:
#include <iostream>
#include <string>
#include <vector>
int main() {
std::vector<std::string> strings;
strings.push_back("test");
std::cout << strings[0].back() << '\n';
}
So, you'd have to configure your Eclipse to use C++11 mode, also.
I have run the following code in Borland Turbo C++ and can run successfully:
#include<stdio.h>
int main()
{
int a;
int& b=a;
a=10;
printf("%d",a);
return 0;
}
But when I try to run it in code block or visual studio or dev C++ I get the following error message:
[Error] expected identifier or '(' before '&' token
I would like to use code block or visual studio but I can not fix up this error. What is the wrong am I doing.
(My apologies if this post sounds silly/stupid. I thought I'd ask here. Ignoring these core bits never made anyone a better programmer.)
Thanks everyone.
Probably you are trying to compile it using C compiler.
Try with C++ compiler like g++ it works!
i've just started to learn the basics of HLSL using C++, im following the tutorials on a book, the first basic shader is:
float4 VS_Main( float4 pos:POSITION):SV_POSITION
{
return pos;
}
but i get a lot of errors at compile time:
error C2146: syntax error: ';' missing before the identifier 'VS_Main'
error C4430: missing type specifier, int assumed. Note: default-int is no longer supported
error C2146: syntax error : ')' missing before the identifier 'pos'
error C2059: syntax errorlooks like a function definition, but there is no formal parameter list.
error C2059: syntax error: '{'
it really looks like the compiler cant handle HLSL at all...maybe VS2012 express doesnt support HLSL?
thanks in advance
HLSL is not C++. You should compile shaders with shader compiler, and C++ with C++ compiler — do not mix. There are two options for compiling HLSL.
Use command-line utility fxc.exe that is included in DirectX SDK (docs and usage here at MSDN). It generates a file that you should load in runtime by some of the ways described here.
Compile your shader at runtime by using D3DCompileFromFile function.
There are pros and cons about each of the variants. In short, pre-compiling at build time gives you some time gain at runtime, while compiling at runtime is more flexible and comfortable at development stage (no need to remember to recompile it or to use post-build scripts) but is more error-prone. Choose by yourself.
The code looks fine for HLSL. If you want to compile it from within VS2012 set the ".fx" file to build using the HLSL shader compiler. Right click the file select properties. Then select General and Item Type should be set to HLSL compiler.
If you really want to make shaders using C++ you could look into C++AMP to see if it may suit your needs.
it really looks like the compiler cant handle HLSL at all...maybe VS2012 express doesnt support HLSL?
No C++ compiler does. It is not supposed to be handled by the compiler.
You need to turn it into a resource and copy it into the bin directory using post-build scripts, and load the HLSL at runtime.
See also: http://www.directxtutorial.com/Lesson.aspx?lessonid=11-4-5
Libtiff is a C library, but I want to use it with a C++ project in Qt Creator. Does anyone know how to do this? I get compile time errors when I try to use the C library, so I'm not sure what to do.
The compile time error I get is:
c:\libtiff\libtiff\tiff.h:69: error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int
for the line:
typedef TIFF_INT8_T int8;
plus a bunch of more similar errors. Someone please help.
You need to wrap the include statements on an extern C block --
extern "C"{
#include "tiff.h"
}
This tells the compiler to view those files as C, not C++, so you should not get strict C++ errors.