How to embed one library into the other?

Asked

Viewed 145 times

7

I have created a C++ game development library. Only my library needs another to display the images on the screen, the SDL2. So every time someone wants to use my library, they would have to link to mine and SDL2. Ex:

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

So I’d like to know if there’s any way around this, rather than having to link the two, the person would just need to link to the library that I created. Ex:

g++ -o main.exe main.cpp -lminha_lib
  • 1

    Even Windows? That I have to impression that on Linux it would be possible to just add the .a of the other library within yours. Or even unpack the static library and repack the other object files with those in your library

  • 1

    I am using Linux, but I would like a solution that works for both systems. I have tried adding . that of the other library in mine but it didn’t work, when compiling the client code gives linkediting error. I was also reading about the second solution that you proposed, but I learned that it is very risky, because if you have two identical symbols (functions or variables) in the two files . a, one of them is lost at the time of repackaging (but I have not tested the hypothesis).

3 answers

2


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

You can see this discussion here: http://forums.libsdl.org/viewtopic.php?p=39289

http://translate.google.com/translate?js=n&sl=auto&tl=pt&u=http://forums.libsdl.org/viewtopic.php? p=39289

The static connection works, but I recommend you use HAVE_LIBC and the Visual Runtime Library C++ in this case. SDL implementations for Visual C++ specific functions can cause problems otherwise.

If attachment is completed, it contains a batch file (gmail didn’t let me send as a .bat. Just rename it. ) And two C files that may be similar to your situation. Download the SDL source 2 and extracts it next to these files. I also included the Sdl_config_windows. h for MSVC 2010 if you create with it. I think the HAVE_X sets for HAVE_LIBC are adapted for 2012.

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

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

And of course this has licensing implications, but it seems that for version 2 this has been modified as presented here: https://wiki.libsdl.org/Installation#Static_linking

http://translate.google.com/translate?js=n&sl=auto&tl=pt&u=https://wiki.libsdl.org/Installation#Static_linking

Static connection SDL 2.0, unlike 1.2, uses the zlib license, meaning you can create a static library directly connected to your program or simply compile the SDL C code directly as part of your project. You’re fully authorized to do that. However, we encourage you not to do so for various technical and moral reasons (see Docs / README-dynapi.Md ) and will not cover the details of how in this document. You may not link SDL 1.2 in most cases due to LGPL licensing, but you should really stop using SDL 1.2 anyway.

  • You can put the content of these links to be visible to everyone?

  • @Jeffersonquesado put the parts I thought were the most important and includes the link to translation.

1

In your library code you include the SDL2 code. It would be a library only when ordering. It’s a scam, but it might work.

  • Gambiarra grande. Even more not knowing what is needed to compile the other library (the question was for the general case, the example only that uses SDL2). You would need to have her build dependencies, which is definitely not appropriate when working at a high level

1

Download the SDL2 library and increment it into your code. I imagine that you have already done this, the same way would be for the user to have to link the two to run the code. If you already add this library within your code file the user will only have to do once.

  • I didn’t understand what you meant by " adding this library into your code file". I would like you to explain it to me in more detail.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.