How to include <cuda_runtime.h> in .cpp file - visual-studio

I have problem to include <cuda_runtime.h> in .cpp file. Error: Cannot include file: cuda_runtime.h: No such file or directory.
I am trying to complie code from Rob Farber ( http://www.drdobbs.com/architecture-and-design/222600097?pgno=1 ).
I have compiled few cuda codes before but <cuda_runtime.h> was allways included in .cu file.
I am using VS 2008 Express.
Q: Do I have to link VS somehow different so it knows where to look for <cuda_runtime.h>?

In Visual Studio 2008, add the path of the include files in Visual C++ directories.
"Installation Path"\NVIDIA GPU Computing Toolkit\CUDA\"version"\include\
Here is the procedure:
In Visual Studio 2008, go to
- Tools -> Options -> Projects And Solutions -> Visual C++ Directories.
- Select include files from the drop down list named "Show Directories For".
- Add new item by clicking the yellow button below the drop down list.
- Paste the include fles path here.
- Verify the correctness of path by clicking the check button on left of yellow button
- Click ok and restart visual studio.
Now Visual Studio 2008 will know where the include file is located.

Instead of setting up a hard-coded path - which you will most likely have when locating CUDA installation on your machine - you can also add cudart.lib as additional dependency for the linker.
Right click on the project > Properties > Linker > Input > Additional Dependencies. Add cudart.lib there.

Related

External/Additional include and source directories in Visual Studio 2022

In order to use external code (QGeoView in this case) I copied the demo code (main.cpp, mainwindow.cpp, the .ui file, etc.) into my Visual Studio project root alongside the QGeoView lib directory.
This alone left me with compiler errors like "Cannot open include file: 'QGeoVies/QGVMap.h'" which I resolved by adding the lib/include directory to the 'Additional Include Directories' in the C/C++ -> General menu in the project properties.
Now I obviously get linker errors since the source files that belong to the just added headers aren't compiled yet.
Where exactly can I add the additional source directory (project root/lib/source in my case) for Visual Studio to find and compile the source files?

can't build old VS2010 project with VS2013. (build tool for VS2010 cannot be found.)

I have installed VS2013 on my computer about 2 years ago(and removed VS2010 I guess) and today I tried to open my old VS2010 project (MV1.sln) that I used to work with about 5 years ago.
When I tried to open it, it just says "more than one project in the solution was not loaded correctly. refer to the output window"(translated from Korean). The output window says
D:\My_Path\MV1\MV1.vcxproj : error : can't read project file "MV1.vcxproj"
D:\My_Path\MV1\MV1.vcxproj(34,5): can't find imported project "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\BuildCustomizations\CUDA 4.0.props". Check if the path specified in <import> declaration is correct and file exists in the disk.
So I checked the MV1.vcxproj file's line 34 which reads
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 4.0.props" />
which seems to be correct path because the value $(VCTargetsPath) is being used before line 34 in the same file and I can easily guess it points to C:\Program Files (x86)\MSBuild (I can see Microsoft.Cpp.props folder and BuildCustomizations\CUDA 4.0.props file referred to in the .vcxproj file)
I had CUDA4.0.props file which specifies include path and library path for CUDA4.0 under C:\Program Files (x86)\Microsoft Visual Studio 10.0 (I kept those files there at that time) but copied it to the location specified in vcxproj file to make it appear there.
I found some similar questions and answers but they seem to be different from my case. What can be the most correct method other than making a new project and copying and specifying everything one-by-one?
I found the file name should have a space in 'CUDA 4.0.props' so I changed the file name(MSBuild/Microsoft.Cpp/V120/BuildCustomizations/CUDA 4.0.targets) , then it complained about CUDA 4.0.targets file missing, so I copied MSBuild/Microsoft.Cpp/v4.0/BuildCustomizations/CUDA 4.0.targets (it was there since 5 years ago) to MSBuild/Microsoft.Cpp/v4.0/V120/BuildCustomizations/CUDA 4.0.targets. Now I can see the files in the project browser but when I build the project, it says
error MSB8020: The build tools for Visual Studio 2010 (Platform
Toolset = 'v100') cannot be found. To build using the v100 build
tools, please install Visual Studio 2010 build tools. Alternatively,
you may upgrade to the current Visual Studio tools by selecting the
Project menu or right-click the solution, and then selecting "Upgrade
Solution...". C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets 64 5 MV1
But in my VS2013 I don't see such "Upgrade Solution" or upgrade menu. So I looked for method to change the toolset and found
Visual Studio 2013 error MS8020 Build tools v140 cannot be found and seleted VS2013 and it tries to build now.
(though I have fix some errors cannot link external symbol _CUDAInit.. etc.)

Visual Studio 2013 not using include path

I have a simple empty Visual Studio 2013 C/C++ project to which added two files:
MyCode.cpp
MyCode.h
Inside MyCode.cpp, I have as the first line,
#include "mex.h"
mex.h is a MATLAB file located in C:\Program Files\MATLAB\MATLAB Compiler Runtime\v717\extern\include
I have gone to Project Properties -> C/C++ -> General and added "C:\Program Files\MATLAB\MATLAB Compiler Runtime\v717\extern\include" to my "Additional Include Directories".
And yet, VS never finds the file!
File 'mex.h' not found in current source file's directory or in build system paths.
It seems that the build system paths are not being updated with my additional include path.
I've tried using relative paths as well, deleting the .sdf file, and closing/reopening Visual Studio. It simply won't add the path.
For reference, this works fine in Visual Studio 2010.
Help!

Including a dependency in VS2010 - Visual Leak Detector

I'm trying to use Visual Leak Detector 1.9h beta in a Visual C++ project on Visual Studio 2010. When I build and run my project I get the following error:
The program can't start because
vld.dll is missing from your computer.
Try reinstalling the program to fid
this problem.
The README that comes with VLD states for Visual C++ 8 and 9:
Go to Tools ->
Options -> Projects and Solutions ->
VC++ Directories. Select "Include
files" from the "Show Directories For"
drop-down menu. Add the include
subdirectory from the Visual Leak
Detector installation directory. Move
it to the bottom of the list. Then
select "Library files" from the
drop-down menu and add the lib
subdirectory from the Visual Leak
Detector installation directory.
Again, move it to the bottom of the
list.
The menus suggested is deprecated in VS2010. What would be the equivalent for VS2010?
I tried the following without success:
Right click on the project \ properties \ Configuration Properties \ C\C++ \ General \ Additional Include Directories -> add ";C:\Program Files (x86)\Visual Leak Detector\include"
Right click on the project \ properties \ Configuration Properties \ Linker \ General \ Additional Library Directories -> add ";C:\Program Files (x86)\Visual Leak Detector\lib\vld.lib"
but as you can guess, it didn't work...
The error message you got isn't fixable with any of the settings you're browsing through. It is a straight-forward runtime error, Windows just cannot find the DLL that the tool needs.
First thing you need to do is find out where the installer put the vld.dll file. You are clearly running a 64-bit operating system. First look in c:\windows\system32, move it to c:\windows\syswow64 if you find it there so that 32-bit programs can find the DLL. Also check if the installer messed with the system environment PATH variable (Control Panel + System, Advanced), you may have to restart Visual Studio to make the change effective. Adding the install directory to this variable would be another solution. The last ditch make-it-work effort is to copy vld.dll into your build directory.

Compiling a simple Qt "Hello World!" application within Visual Studio 2010 Express?

I'm trying to build a basic Qt "Hello, world!" application inside Visual Studio.
I got the moc step to work (I think), but now I am at a loss as to how to fix this linker error:
1>moc_mainwindow.obj : error LNK2001: unresolved external symbol "public:
static struct QMetaObject const QMainWindow::staticMetaObject"
(?staticMetaObject#QMainWindow##2UQMetaObject##B)
I've done a lot of searching but I am at a loss.
Here are my include directories:
i:\Qt\4.6.3\include\QtCore;
i:\Qt\4.6.3\include\QtGui;
i:\Qt\4.6.3\include;
i:\Qt\4.6.3\include\ActiveQt;
reease;
.;
i:\Qt\4.6.3\mkspecs\win32-msvc2008
Here are the libraries I am linking against:
i:\Qt\4.6.3\lib\QtGui4.lib;
i:\Qt\4.6.3\lib\QtCore4.lib;
gdi32.lib;
comdlg32.lib;
oleaut32.lib;
imm32.lib;
winmm.lib;
winspool.lib;
ws2_32.lib;
ole32.lib;
user32.lib;
advapi32.lib;
libpng.lib;
msimg32.lib;
shell32.lib;
kernel32.lib;
uuid.lib;
Does anyone have any ideas?
qmake will generate the moc voodoo from the header file in .pro file. As you aren't using qmake, by the sound of it, but a native visual studio project, this is probably the cause of the problem.
If you use qmake to generate your visual studio project all your problems will go away and life will be sweet. Probably!
I am using the open 2010.05; obviously you want to substitute the correct path for your version.
set up the environment
start 2010 command environment from the start menu
-set include=%include%;C:\Qt\2010.05\qt\include
-set lib=%lib%;C:\Qt\2010.05\qt\lib
-set path=%path%;C:\Qt\2010.05\qt\bin
-set QMAKESPEC=win32-msvc2010
write code, create files etc
generate the initial pro and makefile and fire up VS
-qmake -tp vc
-qmake
you should now have a makefile - check that it works by running:
-nmake
now launch visual studio
-VCExpress.exe /useenv
-XXX.vcxproj can now be opened
If this doesn't work you may need to build qt at against visual studio. This is very straightforward - go to the qt directory (from within the visual studio express command window) and type:
configure.exe -platform win32-msvc2010 -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-multimedia -no-qt3support -fast
You cannot install the Qt VS plugin on the Express edition of VC++. Assuming you got the moc to compile, you also need to make sure you're including the appropriate libraries (*.lib files) at link time. This goes under Project properties > Linker > Input > Additional Dependencies.
You will need qtcore4.lib at a minimum.
Also make sure the Qt library path is in your library search path. On my computer it's c:\qt\4.6.2\lib.
I was able to get QT to work with Visual C++ Express 2010 using http://rajorshi.net/blog/2009/01/using-qt-with-msvc-express-2008/ and http://portfolio.delinkx.com/files/Qt.pdf as guides. Just in case anyone still is having problems.
Have you create the visual studio project using qmake first? The problem seems to be the moc compilation. Do you have qt plug-in installed and the qt path in enviromental variables? Can you add you hello world code so I can have a look at it?
You need to add commands to generate QT metaclasses, then also include the generated files in your project as c++ code.
Generating the QT metaclasses:
First, add your QT bin path into the Executable Directory. (This is in Configuration Properties > VC++ Directories)
Add your Header files that contain Q_OBJECT macros to the project.
Multi-select your header files, then right click on a header file, click Properties.
Change "Item Type" from "C/C++ Header" to "Custom Build Tool".
Set Command line to this: moc.exe "%(FullPath)" > "$(ProjectDir)MetaObjects\moc_%(Filename).cpp"
Set Description to this: QT: Generate $(ProjectDir)MetaObjects\moc_%(Filename).cpp (optional)
Set Outputs to this: $(ProjectDir)MetaObjects\moc_%(Filename).cpp
Run Build just to make it generate the metaobject code
Add the generated C++ files from the Project Directory Metaobjects folder into your project

Resources