You are not logged in.
I'm a little confused about which files get included when compiling a program in C.
I made a file named "screen.h". It's pretty obvious that the compiler is trying to use a different "screen.h" than mine, especially since it compiles fine when I rename my file to "screenblarg.h".
I am making a video game using the Allegro Game Library. Here is the command I use to compile the source files:
gcc -O2 -Wall -Wextra -ansi -pedantic -c filename.c -I/usr/include
I "properly" include the necessary files, using quotes and angled brackets, for example, in "main.c":
#include <allegro.h> /* System header */
#include "screen.h" /* Local header */
I'm especially confused because there is no "screen.h" in "/usr/include".
Does this behavior make sense to anyone? Please let me know if it would help to see the actual code. Thank you!
Last edited by drcouzelis (2010-08-11 02:00:11)
Offline
Use gcc -v to see where it's searching for include files.
Also, -I/usr/include is unnecessary, as gcc will search there for includes by default.
Offline
Use gcc -v to see where it's searching for include files.
Also, -I/usr/include is unnecessary, as gcc will search there for includes by default.
Thank you for your response. I don't see anything in the output of "gcc -v" that would say where it is searching for header files. (it's from the standard Arch Linux package, by the way)
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.5.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --prefix=/usr --enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-gnu-unique-object --enable-lto --enable-plugin --disable-multilib --disable-libstdcxx-pch --with-system-zlib --with-ppl --with-cloog --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info
Thread model: posix
gcc version 4.5.0 20100610 (prerelease) (GCC)
As for including "-I/usr/include", I understand that it's not necessary. It comes from the Allegro command "allegro-config --cflags" in my makefile, which I added to make compiling my program a bit more portable.
There are two other files on my computer named "screen.h". I tried renaming them, but my program would still not compile.
A search on the Internet doesn't say anything about a common "screen.h" file in Linux.
Does the compiler "see" header files (such as a "screen.h") in the libraries that are in "/usr/lib"? Or something? O_o
Offline
I got it!
At the top of my "screen.h" header file, I was naturally doing this:
#ifndef SCREEN_H
#define SCREEN_H
In "allegro.h", "SCREEN_H" is defined as the current screen height.
Problem solved! And I learned a lot about GCC compile options. Thank you for your assistance.
Offline