views:

97

answers:

6

How do I stop automake from adding -I. to my compile line?

It seems automake or libtool objects always have a compile command similar to:

g++ -DHAVE_CONFIG_H -I. -I./proj/otherdir -o myprog.o myprog.c

The problem is that I have two header files with the same name....

./proj/otherdir/Header.h
./proj/thisdir/Header.h

Each header has a class named Header, although each is in a different namespace. So when I am building in ./proj/thisdir, the "-I." gets included and I can't get to the header in ./proj/otherdir

I don't know how to get rid of that initial "-I." that appears.

Any hints?

Thanks Chenz

A: 

is there an alias on your g++?

aaron
No, I dont think so. There is no bash alias and no filesystem links.
Crazy Chenz
A: 

Look in the configure.ac or configure.in for your app, should be in there

Bob.T.Terminal
say what? i don't understand. I will say that I wrote the configure.ac myself and I don't set the -I. anywhere in there.Just to be sure I greped my .ac file and my compiled configure script and there is no mention of "-I."
Crazy Chenz
+3  A: 

all you have to do is set in the Makefile.am

DEFAULT_INCLUDES =

and then all is good in the world.

Chenz

Crazy Chenz
+3  A: 

If your API includes different headers when I write

#include <Header.h>

that makes that API confusing and error prone.

Why not define your API like

#include <thisdir/Header.h>

and

#include <otherdir/Header.h>

Then you could even refer to both headers in the same source file if required. And you would know just from reading the include line what it actually includes.

ndim
Not my code. Just trying to get it to build.
Crazy Chenz
+1  A: 

This is not an answer to your automake question, but a suggestion on how to better arrange your build system. What you should be doing is passing "-I ./proj" on the command line, and then from in your code using

#include "thisdir/Header.h"

or

#include "otherdir/Header.h"

This will remove all ambiguity from the code, and it won't matter if you have "-I ." or not. It also allows you to include both headers in the same file, if necessary.

KeithB
Yeah... can't rearrange code. I would upstream a change like that in a heart beat, but it just ain't possible at the moment.
Crazy Chenz
A: 

It doesn't get rid of -I., but you can put relative paths in your #include directives:

#include "../otherdir/Header.h"
#include "../thisdir/Header.h"
Bill
I think that relative paths are sloppy looking. I'd always rather use a -I argument on the compile line. Thanks though!
Crazy Chenz