1827876 Members
1532 Online
109969 Solutions
New Discussion

Linking sql$mod with C

 
Kaufmann François
New Member

Linking sql$mod with C

Hi there,

Things works perfect with Pascal but I'm not able to do the same in C...

I have a SQL Module file wich i compile with:
$SYS$SYSTEM:SQL$MOD71/ANSI_PARAMETER sql$test.sqlmod

sql$test.sqlmod (extract):
MODULE SQL$TEST
LANGUAGE C
AUTHORIZATION SQL_SAMPLLE
PARAMETER COLONS
PROCEDURE sql$commit
sqlcode;
commit;

and an C file wich I compile with:
cxx test.c

test.c (extract):
#include
long sqlcode;
void sql$commit( long *sqlcode );
void main() {
sql$commit( &sqlcode );
printf( "%ld\n", sqlcode );
}

Then I link both with:
cxxlink test,sql$test,SYS$COMMON:[SYSLIB]sql$user71/lib

And I got the following error:
%LINK-W-USEUNDEF, undefined symbol void sql$commit(long *) referenced
in psect $LINK$ offset %X00000060
in module TEST file TEST.OBJ;1

Thanx in advance for any help.

François
9 REPLIES 9
Ian Miller.
Honored Contributor

Re: Linking sql$mod with C

What happens when you use LINK instead of cxxlink ?
____________________
Purely Personal Opinion
Kaufmann François
New Member

Re: Linking sql$mod with C

Approx the same

%LINK-W-USEUNDEF, undefined symbol CXXL$V60_MAIN_DISPATCH referenced
in psect $LINK$ offset %X00000020
in module TEST file TEST.OBJ;15
%LINK-W-USEUNDEF, undefined symbol SQL$COMMIT__XPL referenced
in psect $LINK$ offset %X00000060
in module TEST file TEST.OBJ;15
Kris Clippeleyr
Honored Contributor

Re: Linking sql$mod with C

François,
And if you link explicitly with SYS$SHARE:SQL$SHR.EXE (or SYS$SHARE:SQL$SHR71.EXE) ?
Regards,
Kris (aka Qkcl)
I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
Kaufmann François
New Member

Re: Linking sql$mod with C

Hi Chris,

the following link statement produces many errors:
cxxlink test,sql$test,sql$user/lib,SQL$SHR/shareable

%LINK-W-RECTYP, file SYS$COMMON:[SYSLIB]SQL$SHR71.EXE;1 record 1 is illegal (3.)
and so on...
Kris Clippeleyr
Honored Contributor

Re: Linking sql$mod with C

François,
It just struck me. The initial warning reports about sql$commit in lowercase.
Could you change your "test.c" file so that SQL$COMMIT is in uppercase.
I think that it has something to do with the C++ compiler preserving the case.
Regards,
Kris (aka Qkcl)
I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
Bojan Nemec
Honored Contributor

Re: Linking sql$mod with C

François,


cxx test.c

and

cxxlink test,sql$test,SYS$COMMON:[SYSLIB]sql$user71/lib


Means that you use C++ not C. C++ encode names and you have to use extern "C" to avoid this. Try with:

#include
long sqlcode;

extern "C" {
void sql$commit( long *sqlcode );
}

void main() {
sql$commit( &sqlcode );
printf( "%ld\n", sqlcode );
}

to avoid C++ name managling.

Bojan
Kaufmann François
New Member

Re: Linking sql$mod with C

Kris,
(sorry for the misspelling in the previous post)

Changed everything in uppercase with no success....

tried before with the /NAMES=AS_IS compiler switch. No success as well.
Kris Clippeleyr
Honored Contributor

Re: Linking sql$mod with C

François,
After some investigation...
Please change the declaration of sql$common in test.c thus:

#ifdef __cplusplus
extern "C" {
#endif
void sql$commit( long *sqlcode );
#ifdef __cplusplus
}
#endif

That worked for me.
Regards,
Kris (aka Qkcl)
I'm gonna hit the highway like a battering ram on a silver-black phantom bike...
Kaufmann François
New Member

Re: Linking sql$mod with C

Hi Kris,

You put me on the way....

I had to change 3 things (2 of them you suggested)
1. Put everything in uppercase to avoid mismatch
2. Define the C like declaration because of using C++ compiler/linker
3. Replace the '$' sign in the external function with '_'

My program now looks like below and does well.
test.c
#include

long sqlcode;

#ifdef __cplusplus
extern "C" {
#endif
void SQL_COMMIT( long *sqlcode );
#ifdef __cplusplus
}
#endif

void main()
{
SQL_COMMIT( &sqlcode );
printf( "return code = >%ld<\n", sqlcode );
}

sql$test.sqlmod
MODULE SQL_HP
LANGUAGE C
AUTHORIZATION SQL_USER
PARAMETER COLONS

PROCEDURE SQL_COMMIT
SQLCODE;
COMMIT;

$ cxx test.c
$ sqlmod sql$test.sqlmod
$ cxxlink test,sql$test,sql$user/lib
$ run test

Many thanks for you help and your quick answers.

Best Regards
François