How can I use dlls in Linux?
Moderator: Moderators
-
- Posts: 318
- Joined: Mon Jan 30, 2017 5:20 pm
- Location: Colorado USA
How can I use dlls in Linux?
So prepare for a whole lot of questions. I want to include SDL.h on a program in C++, simple enough, but I can never find the .h file that is shown in the lazyfoo.net tutorials. Whenever I try to install SDL through the shell, I never know where it is installing or if it is even installing the SDL.h file. Instead, The website makes you install “libraries” which I couldn’t be more clueless to what those are, I want a .h file! But anyway, where do I get the .h file, is it just something you have to make on your own and it doesn’t even exist anywhere on the internet? I’m aware that to some people who have experience with this, I sound like a complete idiot, but that’s because I’m used to consoles like the NES where their is nothing between your program and the CPU. How do I use DLLs in Linux, is it the same as in Windows? Even then, I don’t know how, but Windows is better documented then basically every Linux distro out there.
Re: How can I use dlls in Linux?
Assuming your Linux is Debian, Ubuntu, or Mint, try this:
sudo apt install libsdl2-dev
sudo apt install libsdl2-dev
Re: How can I use dlls in Linux?
On Linux, dynamic libraries have the '.so' extension (for 'shared object') and are also what you link with. For me on Ubuntu (which I *think* installed with the command tepples gave, it's been awhile), the include is "#include <SDL2/SDL.h>" and then the link command has `pkg-config --cflags --libs sdl2`
-
- Posts: 318
- Joined: Mon Jan 30, 2017 5:20 pm
- Location: Colorado USA
Re: How can I use dlls in Linux?
What’s a link command? is it the same as the #include<SDL2/SDL.h>? The link command looks more like something I would use in the shell, or whatever the Linux version of the command prompt is called. I have a pretty clear understanding of command prompt on Windows, but not the terminal on Linux. I have a hard time calling it a terminal because I’m pretty sure the definition of terminal is a kind of keyboard and monitor that uses one computer and multiple terminals can use on computer.
Re: How can I use dlls in Linux?
The little difference with Linux is that many developers use the source code as documentation.
I have solved some obscure doubts I had by looking at the sources. I even talked with a guy in a forum and he said what seemed to be kind of a mantra: "Use the source luke!".
The terminal I think is called this way because it is a terminal emulator, working as the hardware you described.
I have solved some obscure doubts I had by looking at the sources. I even talked with a guy in a forum and he said what seemed to be kind of a mantra: "Use the source luke!".
The terminal I think is called this way because it is a terminal emulator, working as the hardware you described.
-
- Posts: 271
- Joined: Sun Mar 27, 2011 10:49 am
- Location: Victoria, BC
Re: How can I use dlls in Linux?
If you wanna develop on Linux (or, honestly, use it for more than the most basic stuff), you'll pretty much need to learn the terminal/shell/command line/whatever you want to call it.DementedPurple wrote:What’s a link command? is it the same as the #include<SDL2/SDL.h>? The link command looks more like something I would use in the shell, or whatever the Linux version of the command prompt is called. I have a pretty clear understanding of command prompt on Windows, but not the terminal on Linux. I have a hard time calling it a terminal because I’m pretty sure the definition of terminal is a kind of keyboard and monitor that uses one computer and multiple terminals can use on computer.
Anyway, a big difference between the Linux world and the Windows world is that in Linux you generally don't care where on the file system software and libraries are: that's handled by the package manager. A side effect of this is that, if you can at all avoid it, you shouldn't install software manually - that's a power user move.
When you run a command like the one tepples gave you, the SDL2 libraries and headers are installed into the place where the system keeps libraries and headers. That's all you really ought to need to know. When you compile a C program with an include statement like "#include <SDL/SDL.h>", GCC (the C compiler) knows to look for SDL/SDL.h in the place where the system keeps headers.
Building a C program actually happens in two steps: compilation, and then linking. Compilation takes each C file and turns it into an object file (.o) - assembly basically, but each object file is self-contained; places where it has to call functions in other C files are just stubs at this point. Then the linker joins all the different object files together.
A "library" like SDL usually comes in two parts: the header files (.h), which tell the compiler what the names and types of the different functions/structures that the library provides are; and the shared object files (.so), which actually contain the compiled code - these are what DLLs are in Windows!
How are you compiling your code? If you're using an IDE, it should give you some way to specify the arguments you want to pass to the linker, and that's where you'll tell it to try to link with SDL. If you're using the command-line, the "link command" is actually one of your invocations of GCC, and again, you just need to give it an argument to tell it to link with SDL (I think "-lSDL2" should be fine but Hangin10's way should work too, you just need to put it in backticks: "gcc -o myprogram `pkg-config ...` obj1.o obj2.o ...", I think).