Using Separate Libs for Debug and Release in VC++ - c++

I'm downloading GLFW for use with Visual Studio 2010. I see that the download has a separate folder for Debug and Release builds (each folder has two Libs and one DLL), but the filenames in both folders are the same. How should I configure Visual Studio to pick the right file, since I would expect that renaming a Lib or DLL would interfere. My research has been relatively unfruitful, and I think it may have to do with ifdef commands or something. Thanks in advance.

Visual Studio build properties (including the directories where it searches for files) are all build configuration specific. On the project configuration dialog, just press the drop-down to switch from Debug to Release. The settings you change will affect that particular build configuration and no others.
If you don't have this dropdown, then you're using the non-advanced interface, which no human being should ever use. Switch to the advanced interface.

Related

How to make swapping between Debug/Release less painful in this cross-platform project?

We have a C++ CMAKE project. I work on it under Windows using Visual Studio 2019. My coworkers work under Ubuntu using QTCreator.
Here is what my current steps look like for swapping from a DEBUG build to a RELEASE build:
First set up VTK:
Open the release VTK build folder in Visual Studio and build the "INSTALL" subproject to overwrite the installed debug version of VTK with the release build.
Then set up our project:
Edit my account's PATH environment variable to point to the location of the new sub-project DLLs where Visual Studio will put them. (myProject\lib\analytics\Debug to myProject\lib\analytics\Release)
Without telling Windows where the sub-project's DLLs are, trying to execute the program does not work. Not sure if there's a way to tell Visual Studio to look for the DLLs automatically.
Edit the top-level CMAKE of the project:
SET(BUILD_MODE Release)
set(CMAKE_BUILD_TYPE "RELEASE" CACHE STRING "Sets release build by default")
Open Cmake-GUI and clear the cache, then run "Configure" and "Generate"
If I do not clear the cache, Cmake Gui has consistently used older/incorrect settings resulting in unusual build issues.
Open the project under Visual Studio, changing the build type at the top to my new choice.
Hit "Rebuild" on ALL_BUILD.
With all those steps done, I have managed to swap from a Debug to a Release build.
Is there some way to simplify this process and make it easier to swap between the two?
I am not very familiar with Visual Studio or Cmake, so I'm not sure what functionality I'm missing out on.
There should be no need to change reconfigure the cmake, project when using a multi configuration generator. This of course assumes that the VTK package provides imported targets via find_packag(VTK) that properly work with different configurations. You should be able to verify this by checking the import libraries for different configurations of one of your targets in Visual Studio: there are different import libs for the Release and Debug configurations, you're good to go.
As for enabling your program to find the dlls depending on the confiruation, when using the "Play Button" (Visual Studio Debugger):
You should be able to use generator expressions to modify PATH variable in the environment depending on the configuration.
The following assumes the dlls are located in .../lib/<vtk_component_name>/(Debug|Release) directories.
# should evaluate to "C:/Users/..../buildarea/.../lib"
# Note: it's very likely find_package(VTK) already provides necessary info
set(VTK_BASE_DIR "...")
set(VTK_PATH "")
foreach(VTK_COMPONENT IN ITEMS
data-manager
execution
...
)
# use vtk Release configuration for everything but the debug config
set(VTK_PATH "${VTK_BASE_DIR}/${VTK_COMPONENT }/$<IF:$<CONFIG:Debug>,Debug,Release>;${VTK_PATH}")
endforeach()
set_target_properties(my_exe PROPERTIES
VS_DEBUGGER_ENVIRONMENT "PATH=${VTK_PATH}$ENV{PATH}"
)

How can I tell Visual studio where my additional .dll files are?

I have recently switched my IDE to Visual Studio 2019 for C++ projects. I easily followed a tutorial into setting up a new library like SFML into visual studio, and tell it where the additional include and library directories are.
But there is something else that is required for it to work, which are the .dll files. Every page I followed, even the Documentation by the SFML website, it says that they have to be in the same directory as my project. That means I need to copy-paste the 7-8 files into my project directory. This really makes the folder look untidy. I would like to create a new folder and tell Visual Studio where those files are. I tried going doing this
Project -> Properties -> Linker -> Input -> Additional dependencies
Usually, the lines that would work are
sfml-system-d.lib
sfml-window-d.lib
...
I tried doing $(ProjectDir)valid path\ sfml-files.lib but this gives me the linker error, saying that It could not find the file.
If I simply move the .dlls into a folder without doing anything, the code would compile and link fine. But when it runs, Windows gives me a pop-up box with the same error message.
Here is how it currently looks
Looks really messy, I just want to be able to move them into dependencies like how src contains the source files.
How can I achieve this?
As it is now, it works perfectly fine. The issue only occurs when I try to create a new folder.
I hope I have covered the important information required for a good answer, If not please let me know what more I should add
Microsoft Visual Studio 2019
Currently running 64-bit platform with Debug configuration. Hence the -d suffix
You could create a path environment for your specified directory, which is like drescherjm’s suggestion. The steps:
Right-click “This PC” -> “Properties”-> “Advance System settings”
Click “Environment Variables”
In the System Variables group, edit “Path”
Add your directory, for example: ”D:\ SFML-2.5.1\bin”
Restart your visual studio and re-open your project
The easier solution might be to put them in the x64 subdirectory. This allows you to have various builds side by side (x86/x64, debug/release).
Since this x64 directory is where the EXE is located, it is the first directory searched for DLL's. It will take precedence over the Path solution suggested in the other answer. The Path directories are searched last of all.

Visual Studio ignoring include directories

I am running Visual Studio Community 2017 and Windows 10. I have a project for which I have added an include-file directory under Project > Configuration Properties > VC++ Directories > Include Directories, but Visual Studio simply ignores the directory and will not find the include files. It finds the files if I hard-code the directory into the #include statement. I checked the .vcxproj file and the directory shows up there. I just updated/corrected Visual Studio to the most recent version and have since re-booted, but the problem remains. Help, please!
First, ensure that MFC is enabled in project properties > Configuration Properties > General
use of mfc must be set to static or dynamic library.
then to ensure that cl.exe is using all of the include directories that you specify, you need to go to project properties > c/c++ > general and change suppress startup banner to no /nologo.this will give you the full cl command for each source file, showing exactly what visual studio is attempting to do with the code and configuration options that you give to it.
Additional ideas for troubleshooting this kind of issue:
When using vs2015 you can try to add '#include <somenoneexistingfile.h>' to the top of any .c/.cpp and right-click on it to open a context menu and select "Open Document <somenoneexistingfile.h>. This will open a dialog showing you the actual paths being used for including. Note: This specific approach doesn't work with vs2019 or later.
Besides this, you can check if:
you edited the actual configuration (Debug/Release) which you are starting, i.e. maybe you only edited the additional-include-path for the debug-build but are trying to compile a release-build.
you edited the actual platform (x64 vs x86) which you are starting, i.e. maybe you only configured the additional-include-path for x86 but are trying to compile the x64 platform.

error LNK1181: cannot open input file 'kernel32.lib'

I have a project on VS 2012. latest SDK is installed on the WIN 8 x64 computer, the project is targeting WIn32.
I have a clean build in Debug, but when I go to release I get the 1181 LNK error - cannot open input file kernel32.lib.
I have the file on the computer in several location, and in the VC directories there is $(WindowsSdkDir_71A)lib and $(WindowsSdkDir)\lib.
Using process monitor I've tried to rebuild and see where devenv.exe is looking for the file
** UPDATE:
In debug it looks in the right place.
in release it doesn't look for the sdk,
but I see this:
Y:\MyProjectFofler\$(LibraryPath)\kernel32.lib PATH NOT FOUND
and also several successful reads from the win8.0 sdk (which should be ok, but the result is the same, and I need it to read from the V7.1A SDK folder...)
What can it be and what might be the solution for this error ?
Thanks.
I ran into this using Visual Studio 2017. I was trying to get the Visual Studio project configurations to reference the external library .lib files I wanted. I managed to trigger this error when I removed any reference to the system libraries. I later figured out this can be corrected by including one of their macro values (though you can specify an absolute direct path, but that's probably not the best coding convention and prone to brittleness).
On the Visual Studio project, right-Clicking on the project item in the Solution explorer panel (not the Solution itself, which is the topmost item), then select Properties. From there do the following:
VC++ Directories --> Library Directories : $(ProjectDir)lib; $(LibraryPath)
Note the $(LibraryPath) value will include extra values such as inherited from parents, and from what I can tell this is a verbose option. My folder project contained a folder called 'lib' which is why I had the first value there before the semicolon.
There are other common options I have used to specify the Library Directories value:
$(VC_LibraryPath_x86)
$(WindowsSDK_LibraryPath_x86)
$(NETFXKitsDir)Lib\um\x86
If you look at the section VC++ Directories --> Library Directories, you can click on the entry line and select 'Edit', then you can watch live previews of what Macros values will be evaluated and resolved to. If you need additional or more specialized values, click on the Macros button to look for more options.
Link to image of Visual Studio 2017 Library Directories configuration

How to make a single static library from multiple static libraries?

We recently converted a C++ project from Visual Studio 6 to Visual Studio 8. Everything went well until we reached the compilation of a project who put all the static libraries inside one big static library. By default after the conversion between the two version of projects the project didn't do anything (no big static library was created, it only said that the project was up-to-date).
We found a working solution by adding a dummy (empty) file to the project (it had no other files before, in the Visual Studio 6 solution). Everything went well and we managed to compile the project with the new development environment (Visual Studio 8).
My question is: Is there any other way to do this, without dummy files added to the project?
Thanks in advance for your responses
You can use the method described in the answer by nobugz also with multiple configurations and different directories for debug and release input libs. Just add all input libs, debug and release, and use "exclude from build". In the debug configuration exclude all release input libs from the build, in the release configuration exclude all debug input libs.