2

I've been trying to get SFML 2.1 working on my linux mint 15 install on my laptop, and that's when I found I should compile it from the source. So after fumbling through the tutorial on compiling SFML using cmake, I'm finally able to get some code working. But now I'm curious...what did I just do?

When I think of compiling, I think of compiling c++ code into object files, and then linking the object files into an executable. But I don't really understand what it means to compile something like SFML. When I think of a library, I think of a bunch of functions and objects that are made available to me through header files and source files created by another programmer, not necessarily something that needs to be compiled. My knowledge on the compilation and linking process is rather limited, so that might be my biggest issue at this point.

So what does it mean to "compile" a library?

EDIT: After looking at this particular question: How does the compilation/linking process work? I noticed two bits of info that may further refine my question.

Linking: the linker takes the object files produced by the compiler and produces either a library or an executable file.

and

The linker is what produces the final compilation output from the object files the compiler produced. This output can be either a shared (or dynamic) library (and while the name is similar, they haven't got much in common with static libraries mentioned earlier) or an executable.

So perhaps my real question is what does it mean to compile a dynamic library? What am I accomplishing by doing this?

Community
  • 1
  • 1
NickG
  • 23
  • 5
  • There are two types of library. (1) static (2) dynamic. A static library is used to hold functions that are built into your app at build time. A dynamic library is used to hold functions that may be made available (i.e loaded) at run-time. Dynamic libraries can be updated without requiring your app to be rebuilt - they may also be shared between several programs. The advantages of 1 type over another is another topic, easily researchable. – enhzflep Dec 23 '13 at 03:52
  • @enhzflep: So it seems my current understanding of what a library is at the moment only pertains to a static library I guess. I've been reading through this for some more info, [link](http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html), and it seems to accurately describe what I'm seeing on my system in /usr/local/lib/ directory at least. Thanks for the info, it's given me a little push in the right direction for research, but I still haven't found out where compiling comes into the picture regarding shared (or dynamic) libraries. – NickG Dec 23 '13 at 17:47
  • Ahh. I think I'm starting to understand your confusion. The header files for the library tell the compiler how to parse your code and to confirm that it conforms to the expected signature of the function in the library. I.e you can't call `sin("90°");` since sin expects a double, ,rather than a char*. But, the header file only includes data-type definitions and the expected calling params. By building the library first, you save potentially hours of build-time for a program. wxWidgets takes over 2 hours to build on a raspberryPi - a program using its (pre-compiled .so) compiles in 5 minutes. – enhzflep Dec 23 '13 at 23:59
  • You also avoid distributing the source-code to anyone that would otherwise be allowed to use it's functionality. So, you basically get (a) speed of building (b) ability to update without rebuilding in the case of dynamic libraries (c) ability to distribute all required binary code in the case of static libraries and (d) a level of protection of your intellectual work by not distributing the source-code. Building the library simply turns the text-based source code into a binary format suitable for achieving the above aims. – enhzflep Dec 24 '13 at 00:03
  • If do static linking, will the compiler then optimize code and inline functions from the library if it thinks this is efficient? (I imagine this would be impossible when you use dynamic linking). – mnr Mar 17 '19 at 14:32

0 Answers0