VC++ 2019 and lib subdir path ?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
binbinhfr
Posts: 78
Joined: May 9th, 2019, 10:57 pm

VC++ 2019 and lib subdir path ?

Post by binbinhfr » March 31st, 2020, 7:09 am

Hi,
(infact I mean "Hi Albinopapa", because you seem to be the only one around here ;-) )

I am using the SDL2 lib for graphics, and thinking about how I would "deliver" my program as a package, I wonder how I can do to specify that, for any installation path, the libs and dlls will always be found in the .\lib directory of the installation dir (i.e. the directory where the .exe file would be launched).

For the moment, if I put the dlls/libs in the same directory as the EXE, everything is fine, but I cannot manage to put the dlls/libs in a subdir...
It seems to be in relation with the difference between implicit and explicit dll...

There seems to be a SetDllDirectoryA function, but I cannot make it work...

I also wonder how, in VS2019, you can make a "setup.exe" file, containing all the stuff needed for a one-way-installation...

Slidy
Posts: 80
Joined: September 9th, 2017, 1:19 pm

Re: VC++ 2019 and lib subdir path ?

Post by Slidy » March 31st, 2020, 10:41 am

Sorry to disappoint you by not being albinopapa.

As the docs for SetDllDirectoryA mention, it only affects subsequent calls to LoadLibrary(Ex).

Windows will only load DLLs that are located in the same directory as the .exe and in some special system directories. It is possible to load DLLs in another directory yourself at runtime but it's a pain in the ass and I highly recommend you just stick with packaging your EXE/DLL in the same folder.

This is the packaging solution most people go with, you can check your installed programs on your own PC to see for yourself.

binbinhfr
Posts: 78
Joined: May 9th, 2019, 10:57 pm

Re: VC++ 2019 and lib subdir path ?

Post by binbinhfr » March 31st, 2020, 11:35 am

Thanks for your answer, and I am happy to see that Albinopapa and Chili are not the only living souls around here ;-)
This is the packaging solution most people go with, you can check your installed programs on your own PC to see for yourself.
That's what I did, I checked in C:\Program Files (x86)\Steam\steamapps\common where all my steam games are installed, and some of them are using SDL2.

And you are right ! all the DLL are in the same directory as the EXE...

So subject closed. Thx.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: VC++ 2019 and lib subdir path ?

Post by albinopapa » May 15th, 2020, 7:28 pm

I know this is old, but stumbled across this again while searching for something else. One thing that I've read about lately is portability and dynamic libraries, not just dlls but whatever linux uses as well. Because C++ doesn't require a certain ABI it's possible that these dynamic libraries may not work when compiled from one two different operating systems or even compilers. I think this is one reason why so many libraries are written in C, it still remains the most portable because I've read that it DOES define a standard ABI.

Anyway, the reason I'm writing this.

The main reason for a dynamically linked library was to save on memory from programs that may use the same library and running at the same time. Think about all the DLLs in Windows. If you use any of the WindowsSDK stuffs, your going to need the same code as many of the other programs on Windows at the same time. A game is quite different I would think. How many applications are going to be running at the same time using the SDL library? How many are going to be using that particular copy of the SDL library since it's in your EXE folder? Probably not more than one, the one that comes with the EXE.

So honestly it makes little sense to compile these third party libraries into anything but statically linked libraries. That way you'll only need the .lib file during compilation, but won't have to worry about distributing the .lib files to end users. I suppose a drawback to that is if the third party library gets a bug fix, you'd also have to recompile and send out updates, whereas if you stay with a dynamic linked library you could just recompile the DLL and send that as the update instead of the whole project.

With all that, I'm wondering how compatible the modules will be between compiler vendors and operating systems. Will I be able to share my C++ modules from Visual Studio on Windows with users of GCC on LInux?
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

binbinhfr
Posts: 78
Joined: May 9th, 2019, 10:57 pm

Re: VC++ 2019 and lib subdir path ?

Post by binbinhfr » May 16th, 2020, 8:14 pm

So I understand that you are voting for static link :-D
I must have a look at this and see how it can be done with SFML.

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: VC++ 2019 and lib subdir path ?

Post by albinopapa » May 16th, 2020, 9:03 pm

Just my own opinion on the matter. This may be one reason why a lot of libraries are header only, this way you can easily just include the header or headers in your own project and build alongside your own project and not have to worry about static or dynamic linking.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

binbinhfr
Posts: 78
Joined: May 9th, 2019, 10:57 pm

Re: VC++ 2019 and lib subdir path ?

Post by binbinhfr » May 17th, 2020, 12:35 pm

Yes, I love headers lib.
Boost claims to be one of them, but infact, some parts of boost needs cpp and compilation and link.

Post Reply