How to embed a library inside the other?

7

I've created a library for developing games in C ++. Except that my library needs another one to make the images display on the screen, the SDL2. So every time someone wants to use my library, the person would have to link to mine and SDL2. Ex:

g++ -o main.exe main.cpp -lminha_lib -lSDL2

So I would like to know if there is any way around this, instead of having to link the two the person would only need to link to the library I created. Ex:

g++ -o main.exe main.cpp -lminha_lib
    
asked by anonymous 29.12.2017 / 17:40

3 answers

2

If SDL2 provides a static version of the library you can compile your project by embedding SDL2 into your library, so your end user only needs to link against your library.

You can view this discussion here: link

link

  

Static linking works, but I recommend that you use HAVE_LIBC and   Visual C ++ run-time library in this case. SDL implementations for   The specific functions of Visual C ++ may cause problems in another way.

     

If the attachment completes, it contains a batch file (gmail   did not let me upload as a .bat. Just rename it.) And two C files that   may be similar to your situation. Download the SDL 2 source and   extract it next to these files. I also included the   SDL_config_windows.h for MSVC 2010 if you build with it. I think the   HAVE_X defines for HAVE_LIBC are adapted for 2012.

     

If you run build.bat in the build environment, it must render a DLL   with SDL 2 statically connected and an executable importing some   works from it. I have some x86 specific options to delete   warnings, but change them to x64 to create a 64-bit build.   Work perfectly.

     

In addition, it can be useful if we can see how you fit   together. cl.exe and link.exe invocations and all that.

Of course this has licensing implications, but it seems that for version 2 this has been modified as presented here: link

link

  

Static link   SDL 2.0, unlike 1.2, uses the zlib license, which means you can create a static library connected directly to your program or simply compile the SDL C code directly as part of your project. You are fully authorized to do this. However, we encourage you not to do this for a variety of technical and moral reasons (see docs / README-dynapi.md) and will not cover the details of how in this document. You may not bind SDL 1.2 in most cases because of LGPL licensing, but you really should stop using SDL 1.2 anyway.

    
05.01.2018 / 16:04
1

In your library code you include the SDL2 code. It would be a library only when ordering. It is a gambiarra, but it can work.

    
04.01.2018 / 02:17
1

Download the SDL2 library and increment it in your code. I guess you should have already done this, the same way would be for the user to have to link in two for the code to roll. If you already add this library into the file of your code the user will only have to do it once.

    
31.12.2017 / 00:24