I am using Visual Studio 2022 (vs2022 17.4.4) and I want to use the {fmt} library in my project. I cloned the repository from {fmt} GitHub, and followed the following procedure:
I added ...\include\fmt to Project → Properties → C/C++ → Additional Include Directories.
I added ...\src to Project → Properties → Linker → General → Additional Library Directories.
I added fmt.cc;format.cc;os.cc; to Project → Properties → Linker → Input → Additional Dependencies.
However, #include <fmt/core.h> still occurs an error.
Cannot open source file 'fmt/core.h'
Could you tell me what to do?
You don't use fmt twice. Either
Include directory ...\include\fmt and #include <core.h>
or
Include directory ...\include and #include <fmt/core.h>
Presumably option 2 is preferred.
Your other settings don't look correct to me either. Why are you adding .cpp files as libraries? Either you need to compile the .cpp file in which case they should be added to the project just like any other .cpp files. Or there is an actual library to build in which case you need to set up a separate project to build it (assuming that it hasn't been built already).
Additional library directories should contain paths to static/dynamic libraries, not source files.
Add PATH_TO_FMT_ROOT/include to C/C++ > Additional Include Directories.
Add the source files provided in the archive (.cc files in PATH_TO_FMT_ROOT/src) to your project's src folder. OR
Build a library out of the source files and include it by providing its path and name in Linker options.
Build the project.
Related
I am doing a remote C++ build from VS2019 to a machine with Centos. When I input the library to the option additional dependencies, the vs2019 always shows g++ : error : libTest.a: No such file or directory , the file libTest.a is a library I wrote to test my solution.
You should properly configure you VSLinux environment.
First, add additional include directory on Properties -> C/C++ -> General -> Additional include directory. Add paths of directories for additional header files for your library.
Second, add additional library directory on Properties -> Linker -> General -> Additional library directory. Add directories where your static/shared libraries are.
Third, put your name of libraries on Properties -> Linker -> Input -> Library dependency. Add the name of your library. Remember, you should remove prefix lib and the extension of the library.
The exact name of the option may differ since I'm not using VS2019 in English.
I'm having problems importing my custom static library into my project. I have my library in the same solution as the project that I am trying to include it in.
In the VC++ Directory section of the project properties I have put "$(SolutionDir);" in the Include Directories and "$(SolutionDir)Debug\;" in the Library Directories. It is my understanding that the "$(SolutionDir);" is a macro that defines the root directory right? As the library shares the same solution as the project it also shares the same root directory and the .lib file that is created is in the Debug folder of the root directory.
In the Linker/Input section, I have put "GameEngine.lib;" in the Additional Dependencies. "GameEngine.lib" is the file name of the .lib that is in the Debug folder of the root directory.
When I'm trying to include anything from the library it just doesn't even recognise it as existing when writing:
#include <GameEngine/Rendering/Model.h>
Doing it the way below shows that it can actually find the file, meaning the path exists and is correct but I get linker errors doing it this way.
#include "../GameEngine/Rendering/Model.h"
I am using Visual Studios 2017.
Link to GitHub repo: https://github.com/TheHoester/OpenGLGameEngine.git
Thank you
You need to make sure you set the directories for all build configurations. You have only set the include directories for the "x64" platform so building the "Win32" platform won't work. After adding the directories to the "Win32" platform your project builds correctly.
Note that it is more usual to use "VC++ Directories" for system includes and libraries and to use "C/C++/General/Additional Include Directories" and "C/C++/Linker/General/Additional Library Directories" for linking to your own libraries. There isn't any problem that I'm aware of for using the "VC++ Directories" settings though, just make sure not to modify any of the existing paths in there.
My work mate has shared a project that compiles correctly on his machine. But I have to manually set include folders that are 'sub-folders' of project and 'libs' using Tools / Options / Projects and Solutions / VC++ Directories / Include (or Lib) files.
I am wondering why my work mate is not getting an include or lib file compilation error while I am getting compilation errors? Why I have to correct it as said above? Is there any other location/file than VC++ Directories to specify lib and include folders that my work mate is using?
You can set directories that will be searched by #include <> in:
Project Properties -> Configuration Properties -> VC++ Directories -> Include Directories
You can set directories that will be searched by #include "" in:
Project Properties -> Configuration Properties -> C/C++ -> General -> Additional Include Directories
the former is for system headers and the latter is for you're own or additional third party headers.
be aware these settings are Configuration (Debug/Release etc.) & Platform (Win32/x86/arm etc.) specific.
If I understand it right your work mate include a file like "file.h" from a project subfolder in the project like:
#include "file.h"
and set the subfolder in the project settings. If you not use the project settings you have to set the settings on your self like you do.
If you write:
#include "subfolder/file.h"
it also should work on yout system without setting the project settings (onlye maybe setting $(ProjectDir))
If you use extern libs which are not saved in the project directory you can set SystemVariabel (google for windows) and use this in the project to make it easier to share.
e.g.
You want to load a lib from folder C:/somelib so you can set up a system variabel "SomeLibPath" with this directory and setup yout project settings with $(SomeLibPath). So over workers have only to setup this system variabel for correct include.
Hope it helps.
I'm trying to incorporate the Boost libraries into my program, specifically lexical_cast and geometry. I include them using #include"boost/boost/geometry.hpp" and #include"boost/boost/lexical_cast/lexical_cast_old.hpp".
When I run the code I get the fatal error "Cannot open include file: 'boost/geometry/geometry.hpp': No such file or directory" which leads me to another .hpp file in the Boost library which includes another library, but uses #include<...> instead of #include"...".
When I replace it for "..." the error for this one goes, but it is replaced with the next library included using #include<...> instead of #include"...".
I feel like this could lead me down a rabbit hole of replacing nearly all instances of #include<...> with #include"..." which would take ages. Is there a setting I can change or a piece of code I could include that would sort this out?
Or could I just get rid of all the other unnecessary libraries and change the ones I need (I know that, that would still be a lot as they seem to rely on each other).
I have Boost library version 1.58.0.
First you should read about the difference between #include "filepath" and #include <filepath> here.
Personally, I'm working with Boost from Visual Studio as follows:
Go to Project properties → C/C++ → General → Additional Include Directories, and add a path to the boost library root (in my case C:\Program Files (x86)\Boost_1_53).
Include a .hpp file in your sources, like #include <boost/lexical_cast/lexical_cast_old.hpp>
If you're using non headers-only libraries you should also add path to Boost libraries in Project properties → Linker → General → Additional Libraries Directories.
In Visual Studio 2012, right-click on your project and select "Properties".
In the properties dialog, select "Configuration Properties" and then "VC++ Directories".
You will need to add the Boost include path to the "Include Directories" list.
If you're using all header-only libraries then you're done. Otherwise, you will need to add the Boost library path to "Library Directories".
For example:
Boost library - c:\boost\boost_1_58_0 (run booststrap.bat and b2 as administrator).
Add strings $(THIRD_PARTY)\boost\boost_1_58_0\include and $(THIRD_PARTY)\boost\boost_1_58_0\ to VC++ Directories → Include Directories
I wonder why one of my projects has VDSERR.h listed under "External Dependencies" and another hasn't and gives me an "undefined symbol" compiler error about a symbol which is defined in there. How can I include this file in the other project as well?
The External Dependencies folder is populated by IntelliSense: the contents of the folder do not affect the build at all (you can in fact disable the folder in the UI).
You need to actually include the header (using a #include directive) to use it. Depending on what that header is, you may also need to add its containing folder to the "Additional Include Directories" property and you may need to add additional libraries and library folders to the linker options; you can set all of these in the project properties (right click the project, select Properties). You should compare the properties with those of the project that does build to determine what you need to add.
To resolve external dependencies within project. below things are important..
1. The compiler should know that where are header '.h' files located in workspace.
2. The linker able to find all specified all '.lib' files & there names for current project.
So, Developer has to specify external dependencies for Project as below..
1. Select Project in Solution explorer.
2 . Project Properties -> Configuration Properties -> C/C++ -> General
specify all header files in "Additional Include Directories".
3. Project Properties -> Configuration Properties -> Linker -> General
specify relative path for all lib files in "Additional Library Directories".