I want to make a text based adventure game for a friend, so everything requiered should be for example on a USB stick.
I know I have to include the libraries to the file, but how do I find the requiered and link them to the original gamefile.
In the moment I use these libraries:
#include <iostream>
#include <string>
#include <chrono>
#include <thread>
#include <atomic>
#include <condition_variable>
I looked online for the library files and didn’t find them.
I searched long and didn’t any tutorial.
Edit: Im using gcc, visual studio code and on windows
2
Answers
You do not need to share those libraries with your friend if all your friend wants to do is run your game. Once you have finished your game, you compile it into an executable (eg. a .exe file in Windows) and all your friend has to do is run the executable.
If you were to use other third-party libraries, then you might have to include them as .dll files together with your executable. However this should not be the case with standard libraries.
Hope this helps.
You need to distribute a few
.dll
s alongside the executable, in the same directory.ntldd -R my_program.exe
will give you a list of DLLs. Out of those, ignore anything that’s not in your compiler’sbin
directory (note that the paths printed byntldd
can be wrong if you have those DLLs in other directories in PATH; so ignore the paths and compare just the filenames).On my MinGW distribution, this gives me
libgcc??.dll
,libstdc++??.dll
, andlibwinpthread??.dll
.#include
s are not "libraries", see Is iostream a header or a library. They don’t have one-to-one correspondence with the DLLs.Out of the three DLLs above,
libstdc++
is the entirety of the C++ standard library,libwinpthread
is the low-level threading librarylibstdc++
uses under the hood,libgcc
contains low-level utilities used by GCC, and the C standard library mostly resides in system-provided DLLs (eithermsvcrt.dll
orucrtbase.dll
, depending on MinGW flavor; you don’t need to ship those).A static linking (via the
-static
flag) is also an option, which will give you a single self-contained .exe.But eventually you’ll run into the libraries with licenses that discourage static linking (LGPL forces you to share source if you link statically), and/or build systems that don’t produce static libraries out of the box (e.g. OpenAL; which uses LGPL), so better not get used to it. Also allowing the user to update the libraries by themselves is a good idea.