0

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?

Ahmad
  • 12,336
  • 6
  • 48
  • 88
  • Somewhere, probably in a shareable image, is the code that implements the database calls. Since your "do nothing" example didn't contain an actual reference to that code that needed to be resolved, the linker cheerfully went on it's merry way without complaint. Linking to a shareable image is typically done with an options file. [Ref](http://h41379.www4.hpe.com/doc/83final/4548/4548pro_001.html). (Perhaps `LIBCLNTSH.EXE` is lurking somewhere.) – HABO May 10 '18 at 13:37
  • @HABO can you please elaborate on what shall I do to resolve this issue? Should I locate the mentioned file? Then what? – Ahmad May 10 '18 at 13:48
  • Does the Oracle™ documentation contain a section on building applications? Are there sample programs included in the Oracle™ installation? – HABO May 10 '18 at 14:48
  • @HABO can you point me to a website/tutorial that goes through these steps? How do I know if the Oracle installation contains the sample files? I found details for Windows and Linux, but not OPENVMS – Ahmad May 10 '18 at 15:57
  • I've avoided using Oracle™ thus far. The linking documentation is [here](https://docs.oracle.com/cd/E11882_01/server.112/e56697/ch6.htm#VMSAR502). Information about examples follows [here](https://docs.oracle.com/cd/E11882_01/server.112/e56697/ch6.htm#VMSAR513). That exceeds my knowledge of the subject. – HABO May 10 '18 at 18:12

3 Answers3

1

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.

user3344003
  • 20,574
  • 3
  • 26
  • 62
  • Whatever CODE=CPP is doing, it looks like a parameter for the pre-compiler. The source looks like C, but is compiled with a C++ compiler. No surprise, the names are mangled. If he knows the right libraries or shareable images the name mangling will be no problem at all. Neither on Alpha nor on I64, which is the platform here. As can be seen the VMS linker nicely demangles the mangled name. Using the Oracle provided command procedures very likely ensures that the correct libraries are used. To answer the initial question: you are mixing C and C++ and do not use the provided command procedures. – user2116290 May 12 '18 at 13:16
1

Just use the C compiler on your OpenVMS server, most likely it's installed too. Oracle's ProC is C too, so you won't be dealing with a lot of CXX quirks. Unless, there're other not mentioned factors that require you to use C++...

As for CXX, depending on which version you use, there used to be a requirement to use CXXLINK instead of LINK command for linking C++ code. Obviously, when mixing C and C++ code, you need to take care of extern "C" for C functions defined in your code.

qustogusto
  • 21
  • 2
0

@user3344003's response brings back memories. :-) Yes, he's correct - the name of the procedure created to process the EXEC SQL is being name-mangled, but as it's generated (in assembler, IIRC) by the SQL pre-processor you have to work around this a bit.

The way we used to handle this, back in the day, was to have a separate .c file with a bunch of procedures, each of which performed either a single SQL statement or a logical group of SQL statements needed to perform a task. We also had a .h file with prototypes which matched the routines in the .c file. The header would be #included into the .cpp file, with the function prototypes in the header given an appropriate extern "C" to specify C calling conventions and no name mangling.

Another possibility, which I never tried but which might work, would be to simply put a prototype for sqlcxt(void **, unsigned int *, sqlexd *, const sqlcxp *) into your code, prefaced with extern "C". Might be worth a try, but I can only vouch for the .c file method.

Best of luck.