sun.com | docs.sun.com | How To Buy | My Sun | Worldwide Sites |  |

| Previous Contents Index Next
The code fragment in Example 4-1 is accompanied by a `common.h` header file. The code in the `common.h` header file is used in many of the code samples in this guide and is shown in Example 4-2. Example 4-2 The `common.h` Header File
    #ifndef __CMM_COMMON__
    #define __CMM_COMMON__

    #include <cmm.h>

    extern void print_member(cmm_member_t const *P_Member) ;

    #endif
For instructions on installing header files, see Installing Libraries and Header Files. To check that your development host and cluster are running correctly and that you are able to compile and run code using the CMM API, an example, `test_master.c`, is provided. This example uses: The `common.h` header file in Example 4-2 The `print_member()` function from the `common.c` code fragment in Example 4-1 This worked example is shown in Example 4-3. Example 4-3 Example `test_master.c` Program
    #include <stdio.h>
    #include <stdlib.h>
    #include <cmm.h>

    #include "common.h"

    int main(void)
    {
        cmm_member_t member_info;
        cmm_error_t  code;

        code = cmm_master_getinfo(&member_info);
        if (code != CMM_OK) {
            printf("Could not get master info: %s\n", cmm_strerror(code));
            exit(1);
        }

        print_member(&member_info);
        exit(0);
    }
An example Makefile is also provided in this section. This example Makefile enables you to run the `test_master.c` code in Example 4-3, using: The `common.h` header file in Example 4-2 The code fragment, `common.c` in Example 4-1 This example Makefile is shown in Example 4-4. Example 4-4 Makefile for the ``test_master.c` Program`
    CFLAGS = -I/opt/SUNWcgha/include
    LDFLAGS = -L/opt/SUNWcgha/lib \
              -lrt -lcgha_cmm

    all: master_test

    master_test.o: master_test.c
            $(CC) -c $(CFLAGS) master_test.c

    common.o: common.c common.h
            $(CC) -c $(CFLAGS) common.c

    master_test: master_test.o common.o
            $(CC) $(LDFLAGS) -o master_test master_test.o common.o
For more information on setting up a Makefile, see Setting up a Makefile. The Foundation Services is supplied with source code examples in the `SUNWnhcmd` developer package. These examples are installed in subdirectories of the `/opt/SUNWcgha/examples/` directory. For more information, see CMM API Code Examples.
Previous Contents Index Next

Copyright 1994-2004 Sun Microsystems