cplsqlopenvms

Unable to link pre-compiled file


I am using OpenVMS V8.4 as an Oracle 10g database server with CXX built in compiler as well as PROC compiler provided by oracle.

I have written this sample C program:

sample.c

#include<stdio.h>
exec sql include sqlca;  // adds Oracle PLSQL library
                         // same as #include<sqlca.h>

main() {
    printf("Hello, World!\n");
}

then I compiled it

DEVSERVER> PROC SAMPLE.C SAMPLE.PC

The command works find and I can then use the built in CXX compiler:

DEVSERVER> CXX SAMPLE.PC

The command works without any error and I can now use the built in LINK command:

DEVSERVER> LINK SAMPLE

now I can run the file by:

DEVSERVER> RUN SAMPLE

and I get the expected output:

Hello, World!

So, that's all fine. But my program does not do anything useful yet. So, lets connect to a database schema first. I modified SAMPLE.C to :

#include<stdio.h>
exec sql include sqlca; 

main() {
    printf("Hello, World!\n");

    exec sql connect scott identified by tiger;
    // I skipped checking for sqlca.error since LINKer wont even allow
    //  me to create EXE of this file
}

Now, I pre-compile as before:

DEVSERVER> PROC SAMPLE.C SAMPLE2.PC
DEVSERVER> CXX SAMPLE2.PC
DEVSERVER> LINK SAMPLE2

and here is where I get this error:

%ILINK-W-NUDFSYMS, 1 undefined symbol:
%ILINK-I-UDFSYM,  CX3$Z6SQLCXTPPVPJP6SQLXD384K7FP
%ILINK-W-USEUNDEF, undefined symbol CX3$Z6SQLCXTPPVPJP6SQLXD384K7FP refernced
        source code name: "sqlcxt(void **, unsigned int *, sqlexd *, const sqlcxp *)"
        section: .text
        offset: %X0000000000000350 slot: 2
        module: SAMPLE2
        file: DEV$SERVER[SOURCE]SAMPLE2.OBJ;1

The same error occurs whenever I try to execute any SQL statement within a block of exec sql in the code.

What am I doing wrong?


Solution

  • You are running into a chain reaction of problems: Compilation (c++ name mangling) and linking:

    https://docs.oracle.com/cd/E11882_01/server.112/e56697/ch6.htm#VMSAR516

    Note the CODE=CPP parameter. That omission is likely your first major headache. It looks like you are the victim of C++ name mangling. It is likely your compiler is translating

     sqlcxt(void **, unsigned int *, sqlexd *, const sqlcxp *)
    

    into

     CX3$Z6SQLCXTPPVPJP6SQLXD384K7FP
    

    Then note the command procedures in the documentation for linking to the Oracle libraries.