It is currently Mon Nov 20, 2017 8:49 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Sun Nov 05, 2017 7:32 pm 
Offline

Joined: Mon Jan 30, 2017 5:20 pm
Posts: 300
Location: Colorado USA
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 [url]lazyfoo.net[/url] 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.


Top
 Profile  
 
PostPosted: Sun Nov 05, 2017 7:37 pm 
Online

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19234
Location: NE Indiana, USA (NTSC)
Assuming your Linux is Debian, Ubuntu, or Mint, try this:

sudo apt install libsdl2-dev


Top
 Profile  
 
PostPosted: Sun Nov 05, 2017 11:49 pm 
Offline

Joined: Thu Jun 04, 2009 9:07 am
Posts: 30
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`


Top
 Profile  
 
PostPosted: Mon Nov 06, 2017 6:23 am 
Offline

Joined: Mon Jan 30, 2017 5:20 pm
Posts: 300
Location: Colorado USA
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.


Top
 Profile  
 
PostPosted: Mon Nov 06, 2017 8:29 am 
Offline
User avatar

Joined: Sat Jul 04, 2015 9:58 am
Posts: 568
Location: -29.794229 -55.795374
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.


Top
 Profile  
 
PostPosted: Mon Nov 06, 2017 9:00 am 
Offline

Joined: Sun Mar 27, 2011 10:49 am
Posts: 206
Location: NYC
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.

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.

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).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group