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

     

    Execution

    Code Block
    Shell> make -f Makefile connect1.sc

    When running after creating the Makefile like this, connect1.c is newly created. (Depending on the extension option, change it to C/C++ according to the user environment.)

 

Compling

Now add a convention to the Makefile to make it the executable connect1.

Image Added

Of course, it is okay to use pre-compilation protocols and compile conventions in the connect1 protocol. Here, it will be explained separately. In the above, because the connect1 protocol requires connect1.c in the make step, the protocol for connect1.c is found in the Makefile.

Since there is a corresponding protocol in the Makefile, it operates in the order of precompiling first and then cc compiling. However, when actually compiling, it will get the following error:

No Format
$ make -f Makefile connect1
apre -t c connect1.sc
-----------------------------------------------------------------
Altibase C/C++ Precompiler.
Release Version 6.5.1.3.0
Copyright 2000, ALTIBASE Corporation or its subsidiaries.
All Rights Reserved.
-----------------------------------------------------------------
cc -o connect1 connect1.c
connect1.c:9:29: error: ulpLibInterface.h: No such file or directory
connect1.c: In function 'main':
connect1.c:68: error: storage size of 'ulpSqlstmt' isn't known
..........................................................
make: *** [connect1] Error 1