tags:

views:

103

answers:

3

Hello,

gcc 4.4.5 c89

I recently downloaded and installed log4c on my development machine. I put all the headers and includes in the following directories.

project_name/tools/log4c/inc
project_name/tools/log4c/libs

However, as I installed the headers where in the system path:

/usr/include/log4c/*.h

So in my project, when I was including layout.h. layout.h would include the following header in this system path.

#include <log4c/logging_event.h>

I created the same directory structure on the target machine as I did for my development for tools/inc and tools/lib.

However, it wouldn't compile because I hadn't installed the log4c on the target machine so the system path for log4c didn't exist. However, the user of the target machine will not be expected to install log4c. Everything should work out of the box.

So what I think is a good idea is to edit all the headers. from this:

#include <log4c/logging_event.h>

to

#include "logging_event.h"

All the headers are in the inc directory, so I won't be using the system path.

My question is this a good idea to put all the headers into a single directory and edit them to point to this single inc directory?

Many thanks for any advice,

+1  A: 

I'd leave the headers alone -- changing them is potentially error-prone and time-consuming, especially if you want to update your version of log4c at some point.

Am I understanding right that the same headers that are in /usr/include/log4c are also in your project_name/tools/log4c/inc directory? If so, move them to project_name/tools/log4c/inc/log4c, and add an include path to your gcc command line using the -I flag:

gcc -I project_name/tools/log4c/inc myprog.c etc etc

We're moving the files to log4c/inc/log4c so that <log4c/logging_event.h> can still match on the log4c directory under log4c/inc/.

EDIT: I originally typoed -L as the flag, which sets library search paths rather than include file search paths. -I is the correct flag for this case.

Jander
The `-L` command adds a directory to the library search path, which is only used for finding libraries to link, not headers to include (see the man page http://linux.die.net/man/1/gcc)
Jesse Beder
@Jesse: Thank you! I meant `-I`. Correcting in the answer.
Jander
+1  A: 

It looks like the log4c library comes with a directory structure

/src
  /log4c.h
  /log4c
     /lots of *.h and *.c

So it's designed to include its headers as

 #include <log4c.h>

or

 #include <log4c/logging_event.h>

as you've done. It's important to do things this way; if, instead, you just write

 #include <logging_event.h>

and you distribute your library to someone who has a different logging_event.h, the files may get confused, and your poor user will end up including the wrong file.

So I recommend sticking with the directory structure that log4c uses. In your case:

project_name/tools/log4c/inc/log4c/logging_event.h

etc. (as @Jander suggested). The proper way to add the include directory with gcc is -I:

gcc -Iproject_name/tools/log4c/inc foo.c
Jesse Beder
A: 

I don't think it's a good idea to change the headers of a third-party library that you are using. Apart from the possibility of introducing a clash with another header of the same name by removing the prefix "log4c/" it may complicate migration to a new version of the library.

I recommend putting the headers of log4c into project_name/tools/log4c/inc/log4c and include "log4c/layout.h" instead of "layout.h" in your project. This way you project will compile both with installed and your own copy of log4c headers.

vitaut