0

I am working on a plugin in which I need to #include a header file (let's say some_file.h) which in turn includes environ.h. Now, when I build my plugin, the build fails with some errors in the environ.h file and some other dependent files. Here's a code sample from environ.h where the error is occurring:

#ifndef PLATFORM
#ifdef WIN_ENV
#define PLATFORM "winpltfm.h"
#elif __OS2__
#define PLATFORM "os2pltfm.h"
#elif defined(unix) || defined(__unix)
 #define PLATFORM "UnixPlatform.h"
#else
#error You must define the PLATFORM macro     <------- Error-1
#endif
#endif

#include PLATFORM                             <------- Error-2

The Error-1 is: #error you must define the platform macro and Error-2 is easy to guess: Expected <filename> or "filename".

The strange thing is that some other plugin where some_file.h is included works fine i.e. builds successfully. This made me think that there must be some build settings which might be different.

Can anyone suggest what should be done in such a case to remove the errors from the environ.h header file?

Note: I am working on MAC OS X in Xcode.

Sankalp
  • 2,796
  • 3
  • 30
  • 43
  • `__OS2__` isn't getting defined. Is it expected to be defined by the compiler? For a test, you can added a `#define __OS2__` before your `#include "environ.h"`, and see the problem go away for that translation unit. – jmstoker Oct 03 '13 at 19:20
  • Simple `#define __OS2__` starts complaining even more. So, I added `#define __OS2__ 1` before including the `some_file.h`. Now, it says `os2pltfm.h file not found`. Is this the standard file for OSX? – Sankalp Oct 03 '13 at 19:28
  • You're missing a define around `__OS2__`, which is why defining it to `1` worked. I'm not familiar enough with Xcode to recommend a solution, but it would seem that you need to pass the path to os2pltfm.h to your compiler. Also a define switch for `__OS2__`. – jmstoker Oct 03 '13 at 19:35
  • What do you mean by "switch for `__OS2__`"? – Sankalp Oct 03 '13 at 19:43

1 Answers1

0

I continued my comments to this answer so it's easier to explain...

First, instead of #elif __OS2__ it should be #elif defined(__OS2__) that's why during your test #define __OS2__ didn't work, but #define __OS2__ 1 did.

EDIT: From your comments you noted that environ.h is a standard file, but it seems odd how they are checking for the OS2 define. They are forcing it to be defined to a value rather than just being defined.

Second, as evident from your test, the compiler isn't defining __OS2__ for you, and there might be another header that is, but isn't currently included in the tranlation unit that picks up some_file.h. If you've confirmed that OS2 isn't defined by another header file in your project you can define a macro for the preprocessor by following these steps given by this SO answer:

The build setting you need to change is called 'Preprocessor Macros' and it can be found in the 'Build Settings' tab of the Project Settings pane (use the search box to find it). Select each target in turn in the left-hand side of the Project Settings pane then modify the Preprocessor Macros setting.

The setting is specified as a space-separated list of preprocessor macros in the form 'foo' or 'foo=bar'.

Third, it seems your include path to os2pltfm.h is wrong or missing in your compiler settings.

You can include the file following the instructions given in this SO answer:

All you have to do is add the -I flag to your build setting under "Other C Flags"

So in your target's build setting search for "Other C Flags" and add -I/path-to-include/

Community
  • 1
  • 1
jmstoker
  • 3,315
  • 22
  • 36
  • This (`environ.h`) is a standard file, so I guess there is nothing wrong with the file data. There may be something wrong with the compiler settings. Also, I am able to get this `os2pltfm.h` file anywhere. The strange thing that I talked about is that including `some_file.h` in some other plugin works without any complaints. – Sankalp Oct 03 '13 at 19:54
  • I looked for the preprocessor macros in the other plugin but could not find this specific macro defined there.. – Sankalp Oct 03 '13 at 19:58
  • Are these other plugins you have written? Or third parties? If they are third party, it's possible the authors were adding the OS2 definition as a argument to the compiler rather than actually putting it into code. That is a common practice to make the code portable. – jmstoker Oct 03 '13 at 20:02
  • Yes, these plugins have been written by our team only. So, by adding macro definition as an argument, you mean adding it in the build settings, right? – Sankalp Oct 03 '13 at 20:05
  • Correct. Ultimately it turns into a -D__OS2__ switch used by gcc/g++ if I understand the backend of XCode correctly. – jmstoker Oct 03 '13 at 20:10
  • I added to my answer, how to add an include path. – jmstoker Oct 03 '13 at 20:23