.h search path

11 May 2011

Simon,

I've been working on a project for a while. In it are several libs. Each lib defines a default "opts.h" type header that has lots of compiler set-up of the type:-

#ifndef XX
#define XX
#endif

By trial and error I found that defining a "opts.h" file along side main.cpp (at that level) that the compiler would find the .h first and include it. If the file wasn't found it would find the "opts.h" within the library and include that.

All has been fine for months while I worked on this. Now, however, I'm working with Daniel. So as a start off wanted to share my work to date with him last night. So, to do this I wanted to publish the test harness program that also contains all the libs.

To do this I first had to publish each lib first. Once all the libs were published I could then publish the entire program and pass to Daniel the URL for that for him to import.

Had a message from him this morning that the program failed to compile. He found and fixed and let me know what was what.

So I went back to mine and tried to compile it. Sure enough, same error. The error is that the opts.h files with the libs are now being included and not the one defined along side main.cpp

The odd thing is that if I select "edit" and actually open the lib for editing the problem goes away. The search path criteria the compiler uses seems to use different rules depending upon a library "just being used" (ie not opened for editing) or not.

Can you provide us library writers some guide as to how the compiler decides the .h search path criteria so that we can set-up the basic defaults that can then be altered by an end user with an externally defined .h file

11 May 2011

Hi Andy,

It is currently undefined what the search order is (it obviously is, but only by implementation). I'll see if we can make this more consistent and explicit. For now, to support your technique, you may just have to put them in edit mode. Note, you won't need to republish them to publish the program; you should be able to "revert" them to avoid the need to do that.

Great to hear you are trying to collaborate on something here. The version control we're working on is currently only for in your workspace so won't help with DVCS-based collaboration quite yet, but puts a lot in place to help get us closer to where this might be possible! Very exciting...

Simon

11 May 2011

I think the easiest solution is just to tell end users "you must create opts.h along side main.cpp, even if you leave that file empty". It's a shame C never had #require and #include (one must have the file exist the other optional but hey, C is as old as the hills and ain't changing in that dept)

It would be really cool if the version control stuff could be told to use an external svn repos ;) But I doubt you'll have that!