What is the best way to handle source control of an external dependency for a C++ Visual Studio 2019 Solution using Git? - c++

TL;DR: what is the best way to handle external dependencies in C++ Visual Studio projects in the context of source control? Ideally I want other people/devices to be able to just clone my repository, open the .sln file with Visual Studio 2019 and press F5 to compile without having to modify the compilation links for external libraries etc. each time a new clone is made.
I want to use an external library (GLFW, https://github.com/glfw/glfw) in a C++ Project in a Visual Studio 2019 Solution, and I want the project to be easily sharable via Git, both for other devices and other people.
There seems to be a few different approaches to handling this:
Download the binaries and simply store them in my external/glfw folder. This makes linking and including easy. The downside is that this requires manual updates and I would prefer to not redistribute someone else's binaries.
Use Git submodules/subtree to include the glfw source code in my external/glfw folder. My problem here is that I don't know of an easy way to compile the glfw source code as part of my Visual Studio build process since glfw uses CMake, and it doesn't seem to be possible to add a CMake project to a Visual Studio Solution unless the entire solution uses CMake which I want to avoid.
Make a separate repository just for compiling the external libraries. This repository would exist merely to compile external libraries, and the main repository would then use git submodules/subtree to fetch the appropriate binaries/libraries into external/glfw. The problem with this approach is that the overhead of managing a separate repository just for the purpose of compiling external libraries seems excessive.
Approach 2 holds the most appeal as it is simple yet flexible, however, I have been unable to make it work in Visual Studio since I can't seem to add a CMake Project to an existing solution. Is there a way to compile external CMake projects when needed, and have that script automatically execute when I press F5 in Visual Studio?

I'd suggest what you seem to have partially deduced. Instead of using your existing Visual Studio project/solution directly, convert your build to CMake and use a submodule.
Converting basically entails writing a CMakeLists.txt file with your build instructions, and you'll have one line in there that makes it traverse into the submodule. When you run CMake, it'll configure your code as well as the submodule, and generate a Visual Studio project that compiles and links both.
Added bonus is your code will be one step closer to being cross-platform too, since CMake will just as easily generate build systems for Mac, WSL, Linux, etc.

Related

VS 2019 keeps finding qrc cpp files as modified even when they are not

I work in a project using Qt compiled with Visual Studio C++ compiler.
I noticed after migrating from VS2017 to VS2019 that when building the application, VS always find qrc cpp files as modified and try to rebuild them.
Is not happening for all projects though, only some unit tests.
Does someone notice this behavior?
I've had the same issues when upgrading from vc141 (2017) to vc142 (2019). It's old but the only post I found, so:
The difference in the toolkits is that in vc142 "Custom Build Tools" are now appended to include inherited values. If your project is configured to use a build tool projectwide by default (for example meta objects from QTs signal/slot), the compiler will try to do that as well when trying to rcc the qrc files, and ultimately failing without throwing an error.
Simply removing ;%(Outputs) in Properties->Custom Build Tool->General->Outputs solved it for me.

Visual Studio 2017 - Disable CMake for dependencies

I have a Visual Studio 2017 Solution that has some header-only dependencies that are multiplatform and use CMake.
I do not need CMake at all, but I keep getting a lot of warnings and issues because Visual Studio 2017 insists on using CMake, exploring these projects, etc.
Is there a way to completely disable the CMake feature for this solution/project?
Update:
I load the project as a solution not as a CMake project.
It is a header-only library and it does not require CMake to work. It is just using it for testing and other purposes.
I keep the dependency as a git submodule so I don't want to make changes to it. It is correctly working by adding it to the main project as an include path, etc.
The only thing I want I want is to avoid is CMake autodiscovery in these directories because I have no use for it.
For instance:
Add Eigen to your project as a submodule in a directory called Eigen. (This is a header-only library)
Write some code in your solution and reference the header files (you need to add the correct include paths, etc.)
You will see that CMake will pick Eigen (when it is not actually necessary)
You will get warnings and Targets, etc.
Don't open the CMakeLists.txt with File->Open->CMake. Choose File->Open->File. You can also try to uninstall the visual studio c++ tools for cmake portion of Visual Studio 2017 via the installation tool.
In Solution Explorer, locate CMakeLists.txt, right-click it.
Select Custom Build Tool->General.
Erase everything from there. Make sure you have a backup just in case ...

ITK Library dependencies error

I've been trying to use ITK with visual studio but i've been getting problems with the ITK itself. After sucessfully configuring and compiling ITK with Cmake and creating a new project accordingly, Visual studio can't find the paths of the libraries. I've tried specifying the paths on visual studio directories and even manually introducing them into the code but the problem is: There are hundreds of dependencies within ITK, it would take me weeks to link it all together manually, isn't there a way to make this process easier, or to avoid it at all?
Thank you in advance!
Error message
You might need to reconfigure ITK, but this time disable Module_ITKVtkGlue. Then recompile ITK, and then try compiling your project again. I assume you used CMake to generate your project. An example can be found here.

Using a DLL with unmanaged code in Visual Studio 2010?

I'm fairly new to C++ and an trying to figure out to use the TagLib library for a project I am working on. I'm working with unmanaged C++ in Visual Studio 2010 on Windows 7 64bit. I've never used an external library before so I'm very confused on how to go about this.
From this blog entry I got the libtaglib.a and taglib.dll files. I ran across this SO question on how to use TagLib, but it deals with QT Creator, not Visual Studio and I'm not knowledgeable enough about the subject to understand what is being said to translate it into what needs done for Visual Studio.
So, some questions:
Is it even possible to do this with unmanaged code?
What exactly is the function of a .a file?
Most importantly, how do I go about using the taglib.dll in my program??
I've been all over Google looking for a way to do this, but my major problem is that everything I run across is over my head. Please let me know if more info is required. Any help is very much appreciated! Thanks!
I seem to have gotten it working successfully. Here's a rough outline of what I did:
1.) I used CMake to generate the Visual Studio solution.
2.) I attempted to build the tag project in the VS solution, but it failed.
3.) I made the corrections to a few source files as outlined here: http://old.nabble.com/taglib-fails-to-compile-with-MS-VC%2B%2B-2010-td29185593.html
4.) I built the tag project again in release mode. This time it was successful.
5.) I copied the resulting dll, def, and lib files to the same directory as the source files for my project.
6.) I copied the header files from the taglib source to a subdirectory in my project (not sure if this entirely good practice)
7.) In my project settings, I set the subdirectory with the header files as an additional include directory.
8.) I added the dll, exp, and lib files to my project by just going to Add>Existing Item.
9.) I added some code from the taglib examples and built it. Everything worked so I think I got it.
One caveat I ran into, since the DLL was built in release mode, my project had to be run in release mode or it would crash. I'm guessing that if I replaced the DLL with one built in debug mode I could run my program in debug mode, but I have not tried this.
You cannot use libraries specific to GCC (you can tell because they have .a extensions) with Visual Studio. You will have to build the library from source in order to use it with MSVC. Once you have done that it's a simple matter of adding the .lib generated from the build process to your project and things should work out of the box. (Note that it's a .lib you need whether you're compiling for dynamic linking or not -- doesn't matter in msvc land)
EDIT -- after looking at TagLib itself --
In order to compile TagLib you'll need to get the CMake build system, and TagLib itself, and have CMake build you a visual studio solution. Using that solution you'll be able to build the .libs and .dlls you need. Note that because TagLib is a KDE library, you'll probably need to also build some QT bits in order for everything work work successfully. However, I don't have specific experience with the library so I'm not going to be all that helpful here.
Yo do not have to recompile the source (to create the .lib file) if you have the .dll file. With dumpbin /exports and lib (both came with Visual Studio) yo can create a lib that you can link with your application. In this link you can see a nice explanation: http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio/
But as Billy Said, probably you would need other parts of QT to use this library.

Cross-platform svn management (Makefiles & Visual Studio)

I'm working on a little game called freegemas, it's an open source version of the classic Bejeweled written in C++ and using gosu as the graphic API. I've been developing it under Ubuntu Linux as usual, but the other day I wanted to give it a try and I compiled it on Windows using Visual Studio 2005 (which I had never used before). The program worked flawlessly.
To compile it on Windows I manually copied all the source and header files to a new project on MSVC, but I would like to adapt the SVN so I don't have to recreate the project every time I want to compile it.
Therefore, the question would be: What's the best way of organizing the svn so I can have, on the one hand, a Makefile to compile the project in Linux, and, on the other side, the MSVC project's files? Right now I've got a simple folder called trunk with all header, source and resource files on it.
I've never used Visual Studio before, so I don't know which files are the most important either. Maybe some of those files are auto-generated and do not need to be svn-versioned.
Thanks in advance.
You could just keep the project files in a seperate directory "winbuild" or similar. Still, to maintain them would require manual interaction (ie adding every new file manually). The only files you would need to upload to svn are the *.vcproj (for MSVC 2005/2008) and *.vcxproj (MSVC 2010).
Alternatively, you could opt for a cross-platform solution like CMake, which could generate makefiles and Visual Studio project files from a common CMakeLists.txt, which is the only "project file" that would have to be maintained (instead of your makefile). Especially for a simple (?) project like yours (some headers+sources). There would be no need to include any makefiles or vcproj files at all, just the CMakelists.txt file would suffice.
There are others like CMake (SCons, boost.jam, jam, premake, etc.)
It should be feasable, but requires some testing and trial-and-error.