Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 

Code Block
#include <stdio.h>
main()
{
    printf (“hello, world\n”);
}

This source can be compiled at the prompt as follows.

Code Block
Shell> cc –o a a.c

It can be compiled with make using the simple Makefile script as follows.

Code Block
shell> vi Makefile
a:a.c # User-created protocols and dependencies
	cc -o a a.c # Describes the actual command line to be executed
  1. a:a.c finds a.c to make a (check for changes)
  2. cc -o a.c executes this command when a.c exists
  3. shell> make -f Makefile If the file name is Makefile, -f Makefile can be omitted

A Makefile can be described as a script that navigates through the source and describes the listed commands to create a target as described above.

If there is no change to the same source, the error "make: is up to date" will be output because compilation does not need to be performed.

Example Sources

The example source to proceed uses $ALTIBASE_HOME/sample?APRE?connect1.sc included in the same sources in the directory where Altibase is installed. (Based on Altibase 5.3 or later)

This example was written based on the environment compiling based on the GCC compiler in Linux. Therefore, when using other Unix environments and compilers, a part of Makefile must be written differently for the environment.

Some of the sources are as follows.

Code Block
Shell> vi connect1.sc
int main()
{
    char usr[20];
    char pwd[20];
    char opt [200];


    sprintf (usr, “sys”);
    sprintf (pwd, “manager”);
    sprintf (opt, “DSN=127.0.0.1;CONNTYPE=1;PORT_NO=27584”);

    EXEC SQL CONNECT :usr IDENTIFIED BY :pwd USING :opt ;
    if (sqlca.sqlcode != 0)
       printf (“ConnectErr: %d-%s\n”, SQLCODE,sqlca.sqlerrm.sqlerrmc);

Running the Precompile

The APRE extension of Altibase uses "*.sc". Since this file is not in a format that can be directly interpreted by the C/C++ compiler, it must be converted into C/C++ source with the precompiler provided by Altibase.

  1. Makefile contents

    Code Block
    connect1.sc:connect1.sc
       apre -t c connect1.sc

     


  2. Execution

    Code Block
    Shell> make -f Makefile connect1.sc