Including Header files

Hi
Am a mainframe guy and new to these stuffs.
Now ,I want to compile a C++ program in Sunstudio.
My question is how & where to add the header files ?
What is the extension to be used for the header files ?
Please someone help me in this regard.

[I had replied to this yesterday but it didn't appear to show up in the thread]
The header file is added to the 'Header files' in the same project For Sun Studio, I am pretty sure that the header files listed in the project
is not used by the compiler to find the header files.
That list of header files is merely a convience for the programmer
as a reference and to quickly find and open header files used in the project.
You need to tell the IDE which directories to search for header files
(that are not standard header files)
I am presuming that the header file(s) the compiler is complaining about is not a standard library header file,
but instead is a header file associated with the source code you are compiling or are associated with
a 3rd party library required by the program.
The #include semantics, as ralphw mentioned, can be a little complex.
As a quick follow up to ralphw's response
generally #includes of the form
#include "foo.h"
indicates that the header file is in the same directory as your project source files.
Normally the compiler can find this file with some simple seach heuristics so
I suspect the offending include line is of the form:
#include <foo.h>
The <> brackets indicates that the header file is in a directory to be specified
in one of the listed include directories.
Include directories may be intrinsic to the compiler implementation
such as standard libraries and/or libraries added by the compiler vendor;
or they may be header files for 3rd party libraries or your own libraries
stored in some directory other than the application program you are compiling.
For 3rd party libraries or your own libraries, provide a list of
directories to seach for included header files.
for command line mode, in almost all c/c++ compilers these directories are listed with
the -I command line argument.
In SunStudio 12, you list the include directories in
your project properties / Parse configuration / Sun C++ compiler / General / Preprocessor definitions
If you have further questions on this, it would be helpful to know
if you are attempting to compile some preexisting code
or are you creating code from scratch.
(It sounds like you are compiling preexisting code that
presumably has been compiled correctly in some other implementation
and are trying to port it to Sun Studio.
If this is the case, it sounds like you simply need to add the
path of the directory containing the offending header file to
this list of include directories.)
It would also be helpful to know the fully qualified
file name of the offending .h file,
and the form of the #include line in the file that is being compiled.
If the #include line is of the form
#include <dir/foo.h> then you need to add the
path of the 'dir' parent directory to the include directories list.

Similar Messages

  • How to include header files from different directories?

    Hi,
    Sorry for the newb question, but I can't figure this out. I'm trying to compile a simple piece of code (C++) that uses header files in a directory different from the Project directory; header files are in /opt/csw/postgresql/include/pqxx. I've tried a few different things, adding that directory to the include directives under Resource Files, add existing files from a folder, etc etc. Whenever I try to build, dmake bails with status -1. I can't seem to get this working, can someone explain how to use header files from different directories?
    Thanks,
    SlowToady

    Header files are usually specified relative to a base directory. If the base directory is not a system directory -- /usr/include or the compiler installation directory -- add a command-line directive
    -I path/to/base/dirfor each such directory.
    The path can be absolute, such as
    -i /opt/csw/postgresql/includeor relative, such as
    -I ../../my/includeIn your source code, specify the header file relative to the base directory, and be sure to use quotes, not angle brackets. Example:
    #include "header.h"  // right
    #include <header.h>  // wrongThe angle brackets are used for system headers, like <iostream> or <stdlib.h>.
    The rules above are common to all compilers on Unix and Linux, and generally to all C and C++ compilers.
    For more details, read about the -I option in the C++ Users Guide. You can find the guide by pointing your browser to the "docs" directory in the compiler installation, or go here:
    http://docs.sun.com/app/docs/doc/819-5267
    All command-line options are described in Appendix A.

  • How to include header files with different extensions

    Hi,
    When i include a header file with extension .ch (myincludefile.ch), the compiler gives error messages but when i change the extension to .h, the problem disappears.
    Can anyone help me getting rid of this problem?
    For example, for the line below, I get a warning such as, "attempt to redefine MY_CONST without #undef". Remember when i change the extension to .h, the problem disappears.
    #define MY_CONST 500 /* Constant */
    Thank you very much

    I don't see how the name of the file could cause or prevent error messages, except when template declarations are involved. So let's assume for now that the file has a template declaration.
    The Templates chapter of the C++ Users Guide explains about including or separating template declarations and their definitions.
    If you have only a template declaration in a file and the compiler needs the definition, it will look for another file with the same base name and include it automatically. For example, if you have files foo.h and foo.cc, and foo.h has a template declaration, the compiler will include foo.cc automatically, even if you didn't intend for that to happen. You can wind up with multiple delcaration errors that way.
    When looking for a file containing template definitions, the compile will not include a .h file, so as not to create recursive inclusion. If changing the file name to .h causes your problem to disappear, it seems like an unwanted automatic inclusion is the problem.
    You can try two things to find out:
    1. Compile with the -H option. The compiler will output an indented list of all included files. See if you are getting a file you didn't intend, or the same file twice.
    2. Compile with option -template=no%extdef. It disables the automatic search for template definitions.
    If you find an unintended included file this way, you will probably have to change the names or organizaiton of some of the files. Our implementation of the C++ standard library depends on NOT using the -template=no%extdef option, which might mean you can't use that option.

  • What package contains /usr/include header files?

    (Sorry for the x-post; put it in the wrong place originally.)
    I'm trying to find out which package contains the header files located in /usr/include/. I'm trying to compile some stuff and these headers aren't found. Any ideas? This is Solaris 10 x86 8/07.

    Alan, thanks for the reply -- I've sorted it out.
    I was looking for the "standard" headers in /usr/include/ such as stdio.h, sys/stat.h, to name a few. Found them in the SUNWhea package.

  • C header files include environment setting

    Hi, Guys
    When I try to compile a directory applicatoin that should use header file located in /usr/ucbinclude/sys/dir.h on solaris 8.
    If I just code in my C code as:
    #include <sys/dir.h>
    The compiler can't find it.
    If I code in my C code in full path name as:
    #include </usr/ucbinclude/sys/dir.h>
    compiler can find it.
    Who can tell me, how I can set export include header file in my profile to support
    #include <sys/dir.h> to work?
    I know I can set LD_LIBRARY_PATH to support share lib, but how I can set include environment?
    Thank you!

    The normal way to handle this is with the -I option on the compile line:
    cc -I/usr/ucbinclude -c myprog.c ...
    Is there a reason you can't use the -I option?

  • Java package and c++ header files

    What is the difference between importing java package and including header files in c++?

    I do not know .. have been away from C/C++ for a long time...
    As much as I remember you can only import one header file each time... also when you import a header file you can just call methods from the header file automatically ...
    However I could be very wrong on this .. really lost touch from C/C++ ...
    regards,
    Sim085

  • Problem while including the header file in C source code in CIN

    While Creating code interface node....
    In the C source code we are supposed to include the Header file "extcode.h".In my system i have installed
    Turbo C. I couldn't able to find the above header files.When i am trying to use the above header file i am getting error,what could be the reason

    Hi,
    You need to point your turbo C to ..\labview\cintools which is where you will find the extcode.h and other h file and also the lib file.
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • How to include the RNDISFN.h header file in the WIN CE Build ?

    I need to include the header file RNDISFN.h in the build of the WIN CE OS. By default the file is not included.
    What do i need to include  in the OS design to have the Header file compiled ?
    Who can help ?  (thx in advance to all these brave people that help in this forum)

    Hello Mads, please check my answer to your previous question...
    [click]
    Regards,
    Mariusz

  • A question about /usr/include/sys/select.h header file

    good day! i hope i can get some help about this and i would be very grateful if my question will be answered. i have a question regarding the select.h header file that we include in our programs when we use the select(3C) function.
    * Select uses bit masks of file descriptors in longs.
    * These macros manipulate such bit fields.
    * FD_SETSIZE may be defined by the user, but the
    * default here should be >= NOFILE (param.h).
    29 #ifndef FD_SETSIZE
    30 #define FD_SETSIZE 1024
    31 #endif
    its says here in the header file that the value of FD_SETSIZE may be defined by the user and i need to know how. i've already tried declaring a constant at the beggining of the program but it didn't work...
    example:
    #undef FD_SETSIZE
    #define FD_SETSIZE 2048
    the FD_SET macro generates an error if a value larger than 1024 is passed from in the first argument. i need to increase its value in order for me to wait for more than 1024 socket descriptors on select function. how can i increase or modify its value? thanks in advance...

    AFAIK, the only way to change the FD_SETSIZE value is by building your own version of the libc.a and linking it statically to your executable. Not good at all IMHO.
    The sources of Solaris 8 contain the implementation of select(3C) with both standard and 'large' (64K) FD_SETSIZE.
    AFAIK, 64-bit version of the libc.so contains the 64K-descriptors version of the select(3C), so you may consider building your application with -xarch=v9 flag to get 64-bit application...
    As for poll(2) - there is a manual page (man -s 2 poll) and some notes in the Answerbook. poll(2) is the actual system call that is used by select(3C), which is an interface function, so there is no functional difference between these two.
    There is a potential problem with portability of your code if you are using poll(), but it looks like you have no choice... sorry about it...

  • A questions about /usr/include/sys/select.h header file

    good day! i hope i can get some help about this and i would be very grateful if my question will be answered. i have a question regarding the select.h header file that we include in our programs when we use the select(3C) function.
    * Select uses bit masks of file descriptors in longs.
    * These macros manipulate such bit fields.
    * FD_SETSIZE may be defined by the user, but the
    * default here should be >= NOFILE (param.h).
    29 #ifndef FD_SETSIZE
    30 #define FD_SETSIZE 1024
    31 #endif
    its says here in the header file that the value of FD_SETSIZE may be defined by the user and i need to know how. i've already tried declaring a constant at the beggining of the program but it didn't work...
    example:
    #undef FD_SETSIZE
    #define FD_SETSIZE 2048
    the FD_SET macro generates an error if a value larger than 1024 is passed from in the first argument. i need to increase its value in order for me to wait for more than 1024 socket descriptors on select function. how can i increase or modify its value? thanks in advance...

    AFAIK, the only way to change the FD_SETSIZE value is by building your own version of the libc.a and linking it statically to your executable. Not good at all IMHO.
    The sources of Solaris 8 contain the implementation of select(3C) with both standard and 'large' (64K) FD_SETSIZE.
    AFAIK, 64-bit version of the libc.so contains the 64K-descriptors version of the select(3C), so you may consider building your application with -xarch=v9 flag to get 64-bit application...
    As for poll(2) - there is a manual page (man -s 2 poll) and some notes in the Answerbook. poll(2) is the actual system call that is used by select(3C), which is an interface function, so there is no functional difference between these two.
    There is a potential problem with portability of your code if you are using poll(), but it looks like you have no choice... sorry about it...

  • Header files  not being included in JNI

    I've written a java program which interfaces with some C code.In the c code i use certain functions which are defined in a header file that i include in the same c file.The problem i have ,is that the compiler shows an error when it comes across one of those functions.It seems to me that the header file is not being included.Here's what i've done at the start of the jni c code,any help will be greatly appreciated.
    #include<stdio.h>
    #include " mnt/cprog/ca.h"
    JNIEXPORT void JNICALL......
    Can other header files be included over here ,or do they have to be included from the java file?..but the problem there is that the header file is of .h extension.....any suggestions??
    ps..The os is Linux
    ..Derick

    If the header files are not found, the compiler will tell you. At least gcc does so. If only some functions you are using are missing, they are probably not in the header file you are including.
    By the way, there is no way to include headers for your native code through Java. What kind of mechanism should that be?

  • VS2010: Why does my C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include does not get all the needed header files?

    Hello,
    I have installed VS2010 Professional. I have done a full install. The I install the 2010 redistributable and 2010 SP1. So I think I have installed all the needed products. But my include files has only 3 files :(. anmintrin.h, srv.h, wmiatlprov.h. My colleagues
    who have installed the same three products have some 200 header files. My guess these header files are coming from some SDK or so. I have 5.0, 6.0A, 7.0A. 7.1A, 8.0, 8.0A SDKS installed. What am I missing? 
    Please check this http://stackoverflow.com/questions/13656856/cant-get-visual-studio-c-include-file-excpt-h-to-get-installed and there the person tells to practically remove all and install all and another answer says just copy it. My hope is Microsoft
    might have a more logical and technical answer than doing something blindly without rhyme or reason
    A clear cut answer might help the community. 
    thanks
    ananda

    Hi Ananda Vardhana,
    What about your issue now?
    If you have resolved it, you can share the solution here, which will be beneficial for other members with the same issue.
    If you did not, whether you can provide us more information as Barry said for resolving this issue?
    Best regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to count the total lines of the file (including the file header)

    Hi all,
    I am working with Idoc to file scenario(FCC).
    I need to map one of the field with a recound count ie.., count of the total lines of the file (including the file header).
    Eg:Record Count-- mapping area:Total number of records in the file including file header     The total line of the file (including the file header).
    Can i get a help on this.
    Thanks and Regards,
    Manoj

    Hi !
    If there is a tag of your IDOC that occurs the same quantity of times as file lines you have to create in your target file, you could make a Java user defined function in graphical mapping that "caches the entire queue" (use the corresponding option button), that receives as input that field of the IDOC, and returns the "lenght" (.length property value) of that input parameter (it is an array) as output..that should be the file line quantity..you may also add 1 to that count, for the header.
    Hope it helps.
    Regards,
    Matias.

  • Compiler appears to include .cpp source instead/addition to .h header file

    Numerous source files in our project depend upon unix/dcfPosixLocks.h and must be linked with the dcfPosixLocks.o that results from compiling unix/dcfPosixLocks.cpp. While all of these numerous sources files either directly or indirectly #include "unix/dcfPosixLocks.*_h_*" none of them ever #include "unix/dcfPosixLocks.*_cpp_*" (or any other non .h file for that matter). Yet, the C++ compiler incorrectly appears to include unix/dcfPosixLocks.cpp instead of (or in addition to) unix/dcfPosixLocks.h, for example when compiling dcfConstants.cpp (actual invocation and error below). Renaming unix/dcfPosixLocks.cpp to unix/dcfPosixLocks.c (or other names with C/C++ related file extensions) results in similar behavior. We first discovered this problem when we moved from a partially patched Studio 11 on Solaris 9 SPARC to an unpatched Studio 11 on Solaris 10 SPARC, i.e. it works fine on the old system. The problem remains after fully patching Studio 11 on Solaris 10 SPARC and even after fully patching Studio 12 on Solaris 10 SPARC. The implication is that one of the Studio 11 patches broke the C++ preprocessor and has of course been carried over into Studio 12. Since we use gmake to compile multiple sources concurrently, we ruled gmake out as a source of the problem by eliminating concurrent compilation (e.g. -j1 not -j2) and by tracing it to ensure that it was not deciding to compile unix/dcfPosixLocks.cpp (e.g. due to some implicit rule or something like that). Workaround #1, since the dcfConstants.cpp file contains no templates, is to separately preprocess and then compile, i.e. CC -E dcfConstants.cpp 1> .../dcfConstants.i and then CC -c dcfConstants.i -o .../dcfConstants.o. Of course, workaround #1 is dubious in general and completely unworkable where templates are involved. Workaround #2 is to move the unix/dcfPosixLocks.cpp file out of the include path (many of the directories in our include path contain both source and header files). Unfortunately, workaround #2 is problematic from a source control point of view... implies lots of source files being moved unnecessarily from one location to another to artificially distinguish them from header files, breaking historical chains in the process (granted, depends on the abilities of your source control software). Any thoughts or comments? We are hoping that somebody might be able to help us discover the errors in our ways, contribute additional workarounds, and/or confirm that this is in fact a compiler bug. I can try to provide more information as needed. Thank you in advance. -R
    /opt/studio11/SUNWspro/bin/CC -G -KPIC -w -mt
    -D_POSIX_PTHREAD_SEMANTICS -DCXX_SUNPRO -DDCF_NO_STD_MIN -g
    -D_DEBUG -DDCF_ASSERTIONS_ABORT -DDCF_DEADLOCK_ABORTS -DDC F_EXCEPTIONS_ABORT -I. -I/export/home/buildsys/src/build/tmp.3/dcf1/inc
    -I/export/home/buildsys/src/build/tmp.3/dcf1/platform/unix/solaris/inc
    -I/export/home/buildsys/src/build/tmp.3/dcf1/platform/unix/solaris/inc
    -I/export/home/buildsys/src/build/tmp.3/dcf1/platform/unix/inc
    -Iunix/solaris -Iunix
    -I/export/home/buildsys/src/build/tmp.3/dcf1/interfaces
    -I/export/home/buildsys/src/build/tmp.3/dcf1/platform/unix/solaris/interfaces.overlay
    -I/export/home/buildsys/src/build/tmp.3/dcf1/interfaces.overlay
    -c dcfConstants.cpp -o Debug/unix/solaris/dcfConstants.o
    "unix/dcfPosixLocks.*_cpp_*", line 72: Error:
    dcfLocks::oAtomicAccessToLong is initialized twice.
    "unix/dcfPosixLocks.*_cpp_*", line 103: Error:
    dcfMutexAttributes::pSingleton is initialized twice.
    2 Error(s) detected.
    gmake[2]: *** [Debug/unix/solaris/dcfConstants.o] Error 2
    gmake[1]: *** [all-r] Error 1
    gmake: *** [build] Error 2

    I'm having trouble understanding what change in Sun compilers or in Solaris could have resulted in the change in behavior you report.
    For template code, Sun compilers have always used the automatic inclusion model described in the C++ Users Guide section 5.2, "Template Definitions".
    Specifically, if you include a header foo.h that declares one or more templates, the compiler will automatically include foo.cpp (or foo.cc, foo.C, etc) if it needs a definition of one of those templates. That is, it assumes that template definitions missing from foo.h will be in foo.cpp.
    Does that answer your question?

  • JNI header files and /include

    Does anyone know where the JNI classes and what .jar file if need be or just what classes jni.c header file(s)are dependant upon, and do they reside in JRE 1.3.0 or 1.3.1, or do I need the JDK version to obtain these, also isn't there suppose to be a JAVA_HOME/include directory where JNI stuff is or at all, or did that all change in 1.3 and up. I thought I remember there being one 1.17 and 1.2ish JDK's if not JRE installs. Any help would be greatly appreciated. Thanks. Trask.

    and what jar are they in or what is the path to them from JAVA_HOME

Maybe you are looking for