External/Additional include and source directories in Visual Studio 2022 - visual-studio

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?

Related

How to change the location of CMake's generated ALL_BUILD filter and Visual Studio's x64 directory?

What I want to achieve:
A clean build directory generated by CMake for Visual Studio, with build system targets like ALL_BUILD and ZERO_CHECK and additionally created directories like Visual Studio's x64 physically located somewhere else than in the root directory.
What I have tried:
As the accepted answer at CMake: How do I change properties on subdirectory project targets? points out, all I have to do is activating the use of folders with the following line.
set_property(GLOBAL PROPERTY USE_FOLDERS TRUE)
The problem:
This does only create a folder in the visual studio project structure for CMakePredefinedTargets, not in the physical filesystem. And the x64 directory keeps untouched too!
So what do I have to do?

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!

How to include <cuda_runtime.h> in .cpp file

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.

How do I get Visual Studio to output new files in a different directory (ideally the source directory from a out of source cmake build)

I am in the process of adding cmake support to a project and noticed that, after generating an out of source Visual Studio project, adding new files through Visual Studio puts them in the Build directory, and not in the Source directory. This is suboptimal.
Is there any way to change where VS adds new files, and can I set this in a CMakeLists.txt file?
You can choose the ouput directory for CMake like this:
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${MY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${MY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${MY_DIR})
For Visual Studio projects use this:
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${MY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${MY_DIR})

Where do I input DLL dependencies in Visual Studio C++ project?

I am converting some Qt project files (.pro) that run on Linux and Mac into Visual Studio project files (.vcproj) The Qt Visual Studio add-in converted everything fine except the DLL dependencies. Where do I put these in Visual Studio 2008?
If I put the DLLs in Configuration Properties > Linker > Input > Additional Dependencies, I get:
fatal error LNK1107: invalid or corrupt file: cannot read at 0xABC
Where do dynamically-linked dependencies go?
Project Properties -> Linker -> Input -> Additional Dependencies
In that field put xxxx.lib for whatever library you need.
You might want to check what’s the differences between .dll , .lib, .h files ?.
You need to specify the corresponding .lib file at link time. not the dll.

Resources