LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-14-2015, 10:22 AM   #1
ybl84f1
LQ Newbie
 
Registered: Mar 2015
Location: CT
Distribution: Debian
Posts: 19

Rep: Reputation: Disabled
How the heck does gcc parse include files?


Right up front - noob here and just learning Linux. I'm having trouble getting a simple C program to compile and must be missing something about how #include and gcc -I works...

I'm playing with Eclipse on the latest Debian and yes my "Hello World" program runs just fine. I wanted to play with D-BUS and didn't even make it past step 1 successfully which was simply adding

Code:
#include <dbus.h>
to my code, nothing else. (I believe I have all the proper DBUS packages installed for development).

After poking around I found how to add the path for the DBUS headers to Eclipse for gcc which resulted in:

Code:
-I/usr/include/dbus-1.0/dbus
when gcc is invoked. This seems to work fine as it eliminated the prior error of not finding dbus.h.

However now I get:

Code:
Invoking: GCC C Compiler
gcc -I/usr/include/dbus-1.0/dbus -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/hw.d" -MT"src/hw.d" -o "src/hw.o" "../src/hw.c"
In file included from ../src/hw.c:14:0:
/usr/include/dbus-1.0/dbus/dbus.h:29:34: fatal error: dbus/dbus-arch-deps.h: No such file or directory
compilation terminated.
make: *** [src/hw.o] Error 1
The file /usr/include/dbus-1.0/dbus/dbus.h contains:

Code:
ifndef DBUS_H
#define DBUS_H

#define DBUS_INSIDE_DBUS_H 1

#include <dbus/dbus-arch-deps.h> 
#include <dbus/dbus-address.h>
#include <dbus/dbus-bus.h>
#include <dbus/dbus-connection.h>
#include <dbus/dbus-errors.h>
#include <dbus/dbus-macros.h>
#include <dbus/dbus-message.h>
#include <dbus/dbus-misc.h>
#include <dbus/dbus-pending-call.h>
#include <dbus/dbus-protocol.h>
#include <dbus/dbus-server.h>
#include <dbus/dbus-shared.h>
#include <dbus/dbus-signature.h>
#include <dbus/dbus-syntax.h>
#include <dbus/dbus-threads.h>
#include <dbus/dbus-types.h>

#undef DBUS_INSIDE_DBUS_H
So some data points:

1) Of all the files listed above in dbus.h note that strangely only dbus-arch-deps.h is not in the /usr/include/dbus-1.0/dbus directory. That file is located in:

Code:
/usr/lib/x86_64-linux-gnu/dbus-1.0/include/dbus/dbus-arch-deps.h
2) Thinking there was a mistake installing the packages I made a sym link in the /usr/include/dbus-1.0/dbus directory pointing to the actual file above. This didn't change anything. Being even more clever I simply copied the "missing" file to the directory but this also didn't result in anything.

3) I then added the path /usr/lib/x86_64-linux-gnu/dbus-1.0/include/dbus to Eclipse but still get the same error:


Code:
Building file: ../src/hw.c
Invoking: GCC C Compiler
gcc -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include/dbus -I/usr/include/dbus-1.0/dbus -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/hw.d" -MT"src/hw.d" -o "src/hw.o" "../src/hw.c"
In file included from ../src/hw.c:14:0:
/usr/include/dbus-1.0/dbus/dbus.h:29:34: fatal error: dbus/dbus-arch-deps.h: No such file or directory
compilation terminated.
make: *** [src/hw.o] Error 1
(Note I've invokved gcc from the command line with the same options just to make sure it wasn't Eclipse).

4) Just for fun I commented out #include <dbus/dbus-arch-deps.h> in dbus.h however the "No such file or directory" error occured again by simply moving on to the next file dbus-address.h.



So my questions:

1) Why can't gcc find bus-arch-deps.h when I include the path to it?

2) Why, even when I copy the actual file into the /usr/include/dbus-1.0/dbus where dbus.h is located (and where I know gcc is looking) can it not find it?

3) Does this have anyting to do with perhaps needing pkg-config? When I searched for this issue I found some stuff about that utility.

Ugh it's frustrating burning so much time on something I'm sure is simple. Thanks ahead of time for any help.

Last edited by ybl84f1; 03-14-2015 at 10:26 AM.
 
Old 03-14-2015, 11:18 AM   #2
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328

Rep: Reputation: 74
try
Code:
#include <dbus/dbus.h>
and check the output of
Code:
pkg-config --cflags dbus-1
 
Old 03-14-2015, 12:37 PM   #3
ybl84f1
LQ Newbie
 
Registered: Mar 2015
Location: CT
Distribution: Debian
Posts: 19

Original Poster
Rep: Reputation: Disabled
No joy on

Code:
#include <dbus/dbus.h>

gcc -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include/dbus -I/usr/include/dbus-1.0/dbus -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/hw.d" -MT"src/hw.d" -o "src/hw.o" "../src/hw.c"
../src/hw.c:14:23: fatal error: dbus/dbus.h: No such file or directory
compilation terminated.
(That's actually how I started)

Regarding pkg-config --cflags dbus-1

Code:
-I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include
I notice both paths do not have the final directories appended at the end (dbus in both cases)

Code:
steve@debian:/usr/include/dbus-1.0/dbus$ ls
dbus-address.h            dbus-gvalue-parse-variant.h  dbus-python.h
dbus-arch-deps.h          dbus.h                       dbus-server.h
dbus-bus.h                dbus.h~                      dbus-shared.h
dbus-connection.h         dbus-macros.h                dbus-signature.h
dbus-errors.h             dbus-memory.h                dbus-syntax.h
dbus-glib-bindings.h      dbus-message.h               dbus-threads.h
dbus-glib.h               dbus-misc.h                  dbus-types.h
dbus-glib-lowlevel.h      dbus-pending-call.h
dbus-gtype-specialized.h  dbus-protocol.h
Code:
steve@debian:/usr/lib/x86_64-linux-gnu/dbus-1.0/include/dbus$ ls
dbus-arch-deps.h
 
Old 03-14-2015, 12:50 PM   #4
gengisdave
Member
 
Registered: Dec 2013
Location: Turin, Italy
Distribution: slackware
Posts: 328

Rep: Reputation: 74
as you can see, the flags passed to gcc are wrong, you should regenerate the Makefile, but I never used Eclipse, so I can't give more details
 
Old 03-14-2015, 01:23 PM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,757

Rep: Reputation: 7300Reputation: 7300Reputation: 7300Reputation: 7300Reputation: 7300Reputation: 7300Reputation: 7300Reputation: 7300Reputation: 7300Reputation: 7300Reputation: 7300
-I <search_path> is a path where gcc will look for files specified in #include "<include_path>/filename.h". Usually <search_path> is a full path, but sometimes it is relative. include_path usually a relative path, so actually you need to have: <search_path>/<include_path>/filename.h. gcc will not parse the string between ", just add it to the search path.
so you need either
Code:
-I /usr/include/dbus-1.0 and #include "dbus/dbus.h"
 or
-I /usr/include/dbus-1.0/dbus and #include "dbus.h"
the first one is preferred.
http://gcc.gnu.org/onlinedocs/cpp/Search-Path.html

Last edited by pan64; 03-14-2015 at 01:25 PM.
 
1 members found this post helpful.
Old 03-14-2015, 04:44 PM   #6
ybl84f1
LQ Newbie
 
Registered: Mar 2015
Location: CT
Distribution: Debian
Posts: 19

Original Poster
Rep: Reputation: Disabled
Thanks for your explanation - it compiles! I must have been perfectly out of sync specifying the directory and sub-directory between the -I compiler path and the path in the #include, changing both and it never working. Ugh I feel like a dork.

Also a footnote, Eclipse has two seperate include-path settings, one for Debug and one for Release. You have to select the drop-down dialouge to select All Configurations, otherwise it may be in one and not the other.

Appreciate everyone's help.
 
  


Reply

Tags
dbus, gcc, include


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Where does gcc look for include files? stf92 Programming 2 06-02-2013 06:04 AM
[SOLVED] Recursively include headers in include option for gcc kvm1983 Linux - Newbie 5 09-04-2012 03:21 PM
Does gcc with different version include some different default header files? cplus Programming 5 07-10-2011 05:09 AM
gcc 4:4.1.1-15 (Debian 4.0 r4a_Etch) cannot find include files. No man pages. somdeb Linux - Newbie 4 05-07-2009 01:20 PM
Where is my other gcc include files ?? DevandeAsk Ubuntu 1 01-30-2006 08:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:45 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