Importing Dlls in Visual Studio - c++

I am able to create Dlls and am able to access their header files by manually adding the file path of the .lib file to Project Properties -> VC++ Directories -> Library Directories as well as Proj Properties -> C/C++ -> Additional Include Directories. Everything works properly when I do this, BUT every time I open my project on a new machine I have to manually change all of these paths.
I tried setting them to relative paths instead (i.e. ..\ProjectName\Debug) but this did not work. Is there any way to include the necessary library files in my project so that the project will work automatically no matter which machine it is on?

Relative paths should be fine. It didn't work for you because you set incorrect paths I guess.
If .. confuses you and you are not sure what directory it refers to, you can use macros that are defined within Visual Studio IDE like $(SolutionDir) or $(ProjectDir). Note that these macros include / at the end so when you specify path by using them it looks like this: $(SolutionDir)dep/include.
Hope this helps.

Related

Visual Studio 2022 intellisense includePath errors

when using the intellisense prompt of VS2022 to automatically include the header file in the code in the Cpp file, the following error always occurs
#include "../Config/UGConfigManager.h"
Is there any way to replace the path "../" with a full path? Like this:
#include "Game/Config/UGConfigManager.h"
EDIT:
In UE5, you need to change NMake's IncludeSearchPath instead of VC++ Directories in Properties -> NMake
You need to add an include path to the "Game" folder.
To set an include path you now must right-click a project and go to:
Properties -> VC++ Directories -> General -> Include Directories
Then add the include directory like so:
C:/foobar/Game
First try using an absolute path. And if that works you will want to use a Macro. Macros allow users to define paths without being specific to their own computer (So other people can use it).
Perhaps what you need is $(ProjectDir) but I can't tell since I don't know where "Game" is relative to your project files.
But as an example:
$(ProjectDir)/Game
It's worth pointing out that what you are doing is interacting with the compiler option /I on the MSVC compiler. Visual Studio is just a gui abstracting it away for you.
Here are the docs on /I (Additional include directories)

How to add Include directories in Visual Studio while cross-compiling to a Raspberry Pi?

I'm working on a c++ project on my Raspberry Pi. I'm using Visual Studio 2017 to cross-compile the project to my Raspberry.
But when I try to compile the project, I get the error"cannot open source file" in lots of header files.
I already managed to compile simple projects, but now I need to Include Directories and I don't know the proper syntax to set, on Visual Studio's project properties page, the Include Directories to tell the compile where the header files are stored.
For the PCL library, e.g., I was able to include directories using '$(INCLUDE_PCL)'.
But when I try to include pi's directory '/usr/Include/ni' I can't correctly set the absolute path. Here's an screenshot of my properties page (https://ibb.co/G2dszrx). I haven't set the Linker directories yet, since I'm currently getting errors on the compiling phase.
Does anyone knows how to set absolute path to include directories correctly?
EDITED:
Trying to figure this out, I created a new project (Proj) in which I include the file 'try.cpp' stored in the raspberry's "home/pi/projects" folder. This project is in the "/home/pi/projects/Proj" folder.
In the project property page, I have:
Configuration Properties>General>Remote Build Root Directory --> ~/projects
Configuration Properties>General>Remote Build Project Directory --> $(RemoteRootDir)/$(ProjectName)
C/C++>General>Additional Include Directories --> $(RemoteRootDir)
When I compile the project this path gets created correctly, and the project is saved at the correct place, even if go further into more folders in the remote build project directory, but it can't find the include file "try.h".
How can Visual Studio know where to save the project using '$(RemoteRootDir)', but is not able to add that path include directory?
After some searching I managed to correctly add the Additional Include Directories, and Additional Libraries.
Firstly I was also using OpenNI, to work with the PCL. After many tries, I discovered that OpenNI was not correctly installed. So I managed to install it with apt-get.
Secondly, If you want to include the "/home/pi/someDIR" directory at the Raspberry device, just add "/home/pi/someDIR" to Visual Studio's additional include directories.
For you still trying to achieve this, Merlyn Oppenheim, from visual studio, set up a sample project using VS 2019 and Raspberry PI template -> https://github.com/merlynoppenheim/sample-rasp-inc-headers
For this sample project the Visual Studio properties page should have:
C/C++ -> General -> Additional Include Directories = '/home/pi/projects/vcpkg/packages/sqlite3_x64-linux/include;%(AdditionalIncludeDirectories)'
C/C++ -> Linker -> General -> Additional Library Directories = '/home/pi/projects/vcpkg/packages/sqlite3_x64-linux/debug/lib;%(AdditionalLibraryDirectories)'
C/C++ -> Linker -> Input -> Library Dependencies = 'wiringPi;sqlite3;pthread;dl'

Where is Visual Studio source file directory change option

I've been trying for hours to change the source path. I couldn't find anything on project properties, and I couldn't find anything on the internet either.
I want to put all my source files in a directory named "src"
like $mysolution-path)/src and I also want to put library files in the /lib directory, but I can't do it.
Where is this option? Is there an option like this. I want to keep my work clean and tidy, but it seems like it's impossible in Visual Studio unlike in IntelliJ IDE.
One way of doing it:
remove your files from the VS project
move the files in explorer
add the files to the VS project
In Project properties -> Configuration Properties -> C/C++ -> General there is the voice: "Additional Include Directories". You can specify there all the folders you are using for your project, thus you just need to create the folders you need manually and then add the paths there.
About lib files, under Project properties -> Configuration Properties -> Linker -> General there is the voice: Additional Library Directories. Just add there the paths to the lib folders.

How to configure visual studio 2008 to select the correct .lib based on configuration?

The distribution of assimp comes with a lib folder. This folder has the following sub folders :
assimp_debug-dll_win32
assimp_debug-dll_x64
assimp_release-dll_win32
assimp_release-dll_x64
Each of those folders has a single file, assimp.lib. How can I include the correct lib based on my configuration (debug/release)? Currently, assimp is in a folder outside of my project and I've added the paths to Tools->Options->VC++ Directories->Library files, but I'm not sure its working.
You should add the library directories to the project itself rather than as a global setting in visual studio.
To do this, you can right click on the project in the solution explorer. Then under the VC++ directories section, add in the correct path to assimp. You should just add the path that corresponds to the current (i.e. debug or release/win32 or x64) setup to this list. There should be a drop down at the top to select the current configuration that you are editing.
This applies to VS2010 anyway, I'm not 100% sure about VS2008. The library path may be under Project Settings -> Linker ->General -> Additional Library Directories if the VC++ directories section does not exist.
You should be branching the include paths for each build configuration using properties -> linker -> additional include directories. this will solve your problem.
a secondary option is to use #pragma comment(lib,"<lib name>") and use the path to the library you want to link to, then using #if/#endif you can branch based on the current build version.
you can test it using dependency walker, process explorer or any debugger.
You could do it using preprocessor directives:
#ifdef __DEBUG
#pragma comment(lib,"c:/Path/assimp_debug-dll_win32/assimp.lib")
#else
#pragma comment(lib,"c:/Path/assimp_release-dll_win32/assimp.lib")
#endif

How to make the visual studio 2008 IDE look at the right place for header files. Compiling Qt/C++ program

I am building an app on Qt 4.6.2 using visual studio 2008. I need to include the header <QtGui\QDir>.
Problem : The QDir header includes several headers. Once of them is qfile.h. Now the ide/compiler is unable to include this file and the error I get is this
c:\devprojects\myprojects\nttoolkit\trunk\external\qt\include\qtcore../../src/corelib/io/qfile.h(45)
: fatal error C1083: Cannot open
include file:
'Qt/include/QtCore/qiodevice.h': No
such file or directory
I cannot change the path in the file qfile.h since it is an external file to my project. How do I get it working.
Thanks.
The various places the preprocessor searches for include files is described in the Remarks section here.
Typically for an "SDK" like Qt people will change their VC++ Directories, Projects, Options under Tools | Options | "Projects and Solutions" | "VC++ Directories" so that the Include Files and Library Files lists include suitable Qt directories. That way, when the preprocessor searches for Qt include files, it will look in the right places and when the linker looks for .LIB files it will find them also.
One downside to changing those lists is that they apply to all projects built from that version of Visual Studio. That can be a pain in the neck if you have different projects that use different versions of an SDK. In those sorts of situations one solution is to create environment variables called INCLUDE and LIBPATH and then launch devenv with the /useenv switch to override the VC++ Directories settings from Tools | Options.
Finally, a third option is to provide the additional include and library folders via the project properties. In Project | Properties | C++ | General the first property is "Additional Include Directories". Values placed there are passed to the preprocessor via the /I switch. Similarly the Project | Properties | Linker | General tab has an "Additional Library Directories" property which gets passed to the linker via the /LIBPATH switch.
This third option seems attractive because it lets you set these additional directories on a project by project basis. The downside is that it "hard-codes" some directory names in the project. That can be a real pain if you move the project to a new machine where the Qt files are in a different directory or when you have to move the Qt directories to a different hard-drive, etc.
In VS2010, I go to:
Project Properties -> VC++ Directories -> Include Directories
And set the location of directories containing headers I need to include. I don't currently have access to a VS2008 install, but I think there is a similar configuration option available.