[an error occurred while processing this directive]

HP OpenVMS Systems

ask the wizard
Content starts here

Mixing COBOL and C, C++ (Mixed Languages)?

» close window

The Question is:

 
I have a simple Cobol program which gives call to a C program. TO make it more
 simple no parameters are passed.
 
COMPAQ COBOL compiler is used to compile the HELLO.COB program
 
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
 
ENVIRONMENT DIVISION.
 
DATA DIVISION.
*! LINKAGE SECTION.
*! 01 NUMB PIC 9(9) USAGE IS BINARY VALUE 2.
 
PROCEDURE DIVISION.
LABEL1.
       DISPLAY '--'.
       CALL "CHECK1".
END PROGRAM HELLO5.
 
CHECK1.C is the C porgram.
 
#include <stdio.h>
 
void CHECK1( );
 
void CHECK1( )
 
printf ("Hello, this is a C prog called from Cobol prog! \n");
 
 
This C porgram is compiled with Compaq C++ compiler cxx, since CC compiler is
 not present.
 
both programs get compiled.
However while linking with command:-
LINK HELLO, CHECK1
Following error is generated-
%LINK-W-NUDFSYMS, 1 undefined symbol:
%LINK-I-UDFSYM,         CHECK1
%LINK-W-USEUNDEF, undefined symbol CHECK1 referenced
        in psect $LINK$ offset %X00000060
        in module HELLO file TRY:[TRY2]HELLO.OBJ;6
 
Kindly let me know a workaround for running the two programs.
 
 
 
 


The Answer is :

    You need extern "C". Also, you should link with CXXLINK.
 
$ cobol hello
$ cc check1
$ link hello,check1
$ run hello
--
Hello, this is a C prog called from Cobol prog!
 
$ cxx check1.c
$ cxxlink hello,check1
$ run hello
--
Hello, this is a C prog called from Cobol prog!
 
$ type hello.cob
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO.
ENVIRONMENT DIVISION.
DATA DIVISION.
*! LINKAGE SECTION.
*! 01 NUMB PIC 9(9) USAGE IS BINARY VALUE 2.
PROCEDURE DIVISION.
LABEL1.
       DISPLAY '--'.
       CALL "CHECK1".
END PROGRAM HELLO.
 
$ type check1.c
#include <stdio.h>
#ifdef __cplusplus	// This to get a C symbol from C++
extern "C" {
#endif
void CHECK1( );
void CHECK1( )
 
printf ("Hello, this is a C prog called from Cobol prog! \n");
 
#ifdef __cplusplus	// This to get a C symbol from C++
 
#endif

answer written or last revised on ( 16-JAN-2004 )

» close window