LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-06-2005, 02:17 PM   #1
farry
LQ Newbie
 
Registered: Mar 2005
Location: UK
Posts: 4

Rep: Reputation: 0
How to specify path for header files?


With gcc, how are you supposed to specify the path for header files?

This is what it's about: I've looked at a tutorial on SDL (Simple DirectMedia Layer) and the first thing that it suggests is to try a few lines of code to check that it can be initialized. (See below). Now in order to get it to find the SDL.h header file and to find functions like "SDL_Init", I had to specify the SDL library TWICE in the gcc command, once with the full path, and once with just the directory name. (I'm using Mandakelinux 10.1.)

$ gcc -isystem /usr/include/SDL -l SDL -o mytest mytest.c

I spent ages ploughing through the gcc manpage, and lots of trial and error before I stumbled onto that syntax. This is not what I want to find myself doing as a newbie. Is that actually the correct way to do it - should the gcc command line really have to be that complicated? Or am I missing something?

Here's the code, by the way.

#include <stdlib.h>
#include "SDL.h"
main(int argc, char *argv[])
{
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}
}
 
Old 04-06-2005, 02:45 PM   #2
Nad0xFF
Member
 
Registered: Apr 2005
Location: Russia, Saint-Petersburg
Distribution: Slackware 10
Posts: 109

Rep: Reputation: 15
#include <stdlib.h>
#include "SDL/SDL.h"
main(int argc, char *argv[])
{
if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
exit(1);
}


?
 
Old 04-06-2005, 02:50 PM   #3
Harmaa Kettu
Member
 
Registered: Apr 2005
Location: Finland
Posts: 196

Rep: Reputation: 30
The "correct" way is to use sdl-config program, like this:
Code:
gcc -o mytest mytest.c `sdl-config --cflags --libs`
 
Old 04-06-2005, 02:52 PM   #4
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
Sometimes (most of the time?) compilation commands are a PITA. That's why we have make!
 
Old 04-06-2005, 03:22 PM   #5
farry
LQ Newbie
 
Registered: Mar 2005
Location: UK
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally posted by Harmaa Kettu
The "correct" way is to use sdl-config program, like this:
Code:
gcc -o mytest mytest.c `sdl-config --cflags --libs`
Thanks. I see that "echo `sdl-config --cflags --libs`" generates:
-I/usr/include/SDL -D_REENTRANT -L/usr/lib -lSDL -lpthread

So I guess that the gcc command line WAS supposed to be that complicated. It never occurred to me that a library would have its own configuration program.

I've had a look at www.libsdl.org, and I can't see any mention of "sdl-config" among the tutorials. I'd hoped that the tutorials would be an easy introduction so that I wouldn't have to read through all the documentation. Oh well.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Including header files and source files for classes Feenix Programming 8 09-28-2005 10:53 AM
gcc header files and cpp files? EchO Linux - Software 3 03-01-2005 01:14 AM
header include path KDE4me Linux - Newbie 6 01-06-2005 06:17 AM
C++ Header files mrpc_cambodia Programming 1 12-05-2004 10:08 PM
c header files in linux in place of header files in windows? harun_acs Programming 1 03-17-2004 02:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration