Newbie-question: include headers for different plattforms

T

TK

Hi,

I'm a C-Newbie and here's my question: how can I include headers for
different plattforms like Mac OS X, Windows 2000 and Suse Linux?

I want to use my program on this three Systems.

Thanks for help.

o-o

Thomas
 
S

smiletolead

It depends on the compiler are using: On windows, the compiler option
/I is used to specify the directories to look for header files. On
linux, the compiler option, -I can be used to specify the header file
search path. If you are using gcc on Mac OS, you can use the option -I
as in linux. Suppose you are compiling your program on linux. You can
include the headers as follows:
gcc yourprogram.c -I<include-dir>
 
T

TK

Hi,

thanks for help.
It depends on the compiler are using: On windows, the compiler option
/I is used to specify the directories to look for header files. On
linux, the compiler option, -I can be used to specify the header file
search path. If you are using gcc on Mac OS, you can use the option -I
as in linux. Suppose you are compiling your program on linux. You can
include the headers as follows:
gcc yourprogram.c -I<include-dir>

Ah, ok.

But I thought there are some preprocessor-directives (with symbols for
an appropriate OS).

o-o

Thomas
 
D

David Resnick

TK said:
Hi,

thanks for help.


Ah, ok.

But I thought there are some preprocessor-directives (with symbols for
an appropriate OS).

o-o

Thomas

If you *really* are doing platform specific stuff, you can
select what is included as follows. Just examples, not sure
these are what you want...

#if defined (_WIN32)
#include <conio.h>
#elif defined(__linux__)
#include <curses.h>
....
#endif

If you need the above and have questions, you should direct
them to newsgroups about the individual operating systems...

-David
 
M

Mark McIntyre

I'm a C-Newbie and here's my question: how can I include headers for
different plattforms like Mac OS X, Windows 2000 and Suse Linux?

Headers are just where functions and so forth are declared. The actual
definitions are in a library, which is binary-compatible only with the
operating system it came from. You can't generally use libraries from
one OS on another OS.

See also FAQ 10.11.
I want to use my program on this three Systems.

Then you must compile it for all three systems - generally by
compiling it /on/ each system in turn.
 
M

Mark McIntyre

But I thought there are some preprocessor-directives (with symbols for
an appropriate OS).

You'd use preprocessor directives like this to customise a header or C
file for different environments, yes. You see this a lot in gnu
projects for instance

It would not allow your code to run on those different environments,
unless you then also compiled it multiple times, and linked it against
platform specific libraries. This is all offtopic here tho.
 
T

TK

Hi,

thanks for help!
If you *really* are doing platform specific stuff, you can
select what is included as follows. Just examples, not sure
these are what you want...

#if defined (_WIN32)
#include <conio.h>
#elif defined(__linux__)
#include <curses.h>
...
#endif

Yes, I'm looking for things like this.

o-o

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top