Highlighted
Absent Member.
Absent Member.
4688 views

link problem in cobol with sql

Jump to solution

[Migrated content. Thread originally posted on 02 March 2011]

helo

l am using the eclipse visual cobol.

i try to build this program :
==============================================================
$set db2(db=sample)
****************************************************************
* Copyright (C) 1998-2002 Micro Focus International Ltd.
* All Rights Reserved
*---------------------------------------------------------------
working-storage section.

* Include the SQL Communications Area. This includes the
* definitions of SQLCODE, etc

EXEC SQL INCLUDE SQLCA END-EXEC

*> DB2 UDB limits database alias names to 8 characters
*> other DB2 servers such DB2/MVS can have database names up to
*> 18 characters which you can still access via DB2 CONNECT
*> by creating an ALIAS name for the database with a max of 8
*> characters

01 ws-db pic x(08).

*> DB2 UDB has a limit of 8 characters for a logon id.
*> Passwords may be up 18 characters but if you may run into case
*> and length problems going to other DB2 servers if you use more
*> than 8 characters or if you use lower case characters in a
*> password

01 ws-usr pic x(08).
01 ws-pass pic x(18).

01 ws-var-pass.
49 ws-var-pass-len pic s9(04) comp-5.
49 ws-var-pass-dat pic x(18).


procedure division.


*> Connect to an IBM DB2 Sample database
display "Connect statement tests"
display " "
display "Enter database alias to connect to (Eg Sample) "
with no advancing
accept ws-db
display "Enter username "
with no advancing
accept ws-usr
display "Enter password "
with no advancing
accept ws-pass


*> test 1 - basic type 1 CONNECT without id or password
display "Test 1:"

EXEC SQL
CONNECT TO :ws-db
END-EXEC
if sqlcode not = 0
display "Error: cannot connect "
display sqlcode
display sqlerrmc
stop run
else
display "Test 1: OK"
EXEC SQL
DISCONNECT CURRENT
END-EXEC
if sqlcode not = 0
display "Error: cannot disconnect "
display sqlcode
display sqlerrmc
stop run
end-if
end-if

*>test2
*>type 1 connect with id / password passed as char fields
display "Test 2:"
EXEC SQL
CONNECT TO :ws-db USER :ws-usr USING :ws-pass
END-EXEC
if sqlcode not = 0
display "Error: cannot connect Test 2 "
display sqlcode
display sqlerrmc
stop run
end-if
display "Test 2: OK"

EXEC SQL
DISCONNECT CURRENT
END-EXEC
if sqlcode not = 0
display "Error: cannot disconnect "
display sqlcode
display sqlerrmc
stop run
end-if

*>test3
*>type 1 connect with id / password passed as varchar field
display "Test 3:"
move 0 to ws-var-pass-len
move ws-pass to ws-var-pass-dat
inspect ws-pass tallying ws-var-pass-len for characters
before initial " "

EXEC SQL
CONNECT TO :ws-db USER :ws-usr USING :ws-var-pass
END-EXEC
if sqlcode not = 0
display "Error: cannot connect Test 3 "
display sqlcode
display sqlerrmc
stop run
end-if
display "Test 3: OK"

EXEC SQL
CONNECT RESET
END-EXEC
if sqlcode not = 0
display "Error: cannot disconnect "
display sqlcode
display sqlerrmc
stop run
end-if
stop run.
===============================================================
and get this error :


os.init:

os.init.windows:

os.init.unix:

init:

init.New_Configuration:

build:

os.init:

os.init.windows:

os.init.unix:

init:

pre.build.cfg.New_Configuration:

os.init:

os.init.windows:

os.init.unix:

init:

cfg.New_Configuration:
[cobol]
[cobol] Compiling CONNECT.CBL...
[cobol] Compilation complete with no errors.
[cobollink] Linking sqlproj1.exe...
[cobollink] C:\PROGRA~2\MICROF~1\VISUAL~1\bin\cbllink.exe -FM -Osqlproj1.exe CONNECT.obj
[cobollink] Micro Focus COBOL - CBLLINK utility
[cobollink] Version 1.2.0.156 Copyright (C) 1984-2010 Micro Focus (IP) Limited.
[cobollink]
[cobollink] Microsoft (R) Incremental Linker Version 10.00.30319.01
[cobollink] Copyright (C) Microsoft Corporation. All rights reserved.
[cobollink]
[cobollink] CONNECT.obj
[cobollink] cbllds00001AB8.obj
[cobollink] mfsqlsmf.lib
[cobollink] Creating library sqlproj1.lib and object sqlproj1.exp
[cobollink] CONNECT.obj : error LNK2001: unresolved external symbol _SQLGSTRT@12
[cobollink] CONNECT.obj : error LNK2001: unresolved external symbol _SQLGALOC@16
[cobollink] CONNECT.obj : error LNK2001: unresolved external symbol _SQLGSTLV@28
[cobollink] CONNECT.obj : error LNK2001: unresolved external symbol _SQLGCALL@20
[cobollink] CONNECT.obj : error LNK2001: unresolved external symbol _SQLGSTOP@4
[cobollink] sqlproj1.exe : fatal error LNK1120: 5 unresolved externals
[cobollink] Link complete with errors
[cobollink]


BUILD FAILED
Build finished with 1 errors, 0 warnings, 0 notices and a maximum exit code of 1,120

D:\SHLOMOCOBOL\workspace\sqlproj1\.cobolBuild:141: Build errors have occurred

Total time: 4 seconds

=============================================
it appears in any program with sql.

can anybody help ?

thanks


shlomo
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: link problem in cobol with sql

Jump to solution
Are you using a 64-bit version of DB2 on your system?

I am running on Windows 7 64-bit also and 64-bit products are installed to c:\program files\ whereas 32-bit products are installed to c:\program files (x86)\

This leads me to believe that you have a 64-bit version of DB2 installed but you are trying to compile the COBOL application as 32-bit.

This will not work.

You can change the bitism on the property page entitled Target Platform Settings to 64-bit if this is what you wish to use.

I compiled and linked your program successfully in Eclipse Visual COBOL in a native project with chipset set to 32-bit and linking to 32-bit DB2 library.

If you wish to link to 32-bit then you need to use the 32-bit DB2 library.

View solution in original post

0 Likes
7 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: link problem in cobol with sql

Jump to solution
From memory I think the routines are in db2api.lib which should come with your db2 support.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: link problem in cobol with sql

Jump to solution
You need to add the db2 library db2api.lib to your link libraries.

Right click on the Project name and select Properties.
Under the Micro Focus COBOL option select Build Configurations.
Highlight the Build Configuration in the list and click on the Edit button.
Click on the Next button 4 times until you are at the Additional Libraries and Resource Files page.
Click the New button and navigate to the location of db2api.lib on your system and select it.

On my system this is:
C:\Program Files (x86)\IBM\SQLLIB\lib\db2api.lib

Build again.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: link problem in cobol with sql

Jump to solution
i have done so and get the same error:
============================================================

os.init:

os.init.windows:

os.init.unix:

init:

init.New_Configuration:

build:

os.init:

os.init.windows:

os.init.unix:

init:

pre.build.cfg.New_Configuration:

os.init:

os.init.windows:

os.init.unix:

init:

cfg.New_Configuration:
[cobol]
[cobol] Compiling CONNECT.CBL...
[cobol] Compilation complete with no errors.
[cobollink] Linking contact.exe...
[cobollink] Micro Focus COBOL - CBLLINK utility
[cobollink] Version 1.2.0.156 Copyright (C) 1984-2010 Micro Focus (IP) Limited.
[cobollink]
[cobollink] Microsoft (R) Incremental Linker Version 10.00.30319.01
[cobollink] Copyright (C) Microsoft Corporation. All rights reserved.
[cobollink]
[cobollink] CONNECT.obj
[cobollink] cbllds00001064.obj
[cobollink] mfsqlsmf.lib
[cobollink] Creating library contact.lib and object contact.exp
[cobollink] CONNECT.obj : error LNK2001: unresolved external symbol _SQLGSTRT@12
[cobollink] CONNECT.obj : error LNK2001: unresolved external symbol _SQLGALOC@16
[cobollink] CONNECT.obj : error LNK2001: unresolved external symbol _SQLGSTLV@28
[cobollink] CONNECT.obj : error LNK2001: unresolved external symbol _SQLGCALL@20
[cobollink] CONNECT.obj : error LNK2001: unresolved external symbol _SQLGSTOP@4
[cobollink] contact.exe : fatal error LNK1120: 5 unresolved externals
[cobollink] Link complete with errors
[cobollink]


BUILD FAILED
Build finished with 1 errors, 0 warnings, 0 notices and a maximum exit code of 1,120

D:\SHLOMOCOBOL\workspace\contact\.cobolBuild:151: Build errors have occurred

Total time: 2 seconds
===============================================

i am working i windows 7 64 bit
the file is in :
C:\Program Files\IBM\SQLLIB\lib\db2api.lib

shlomo
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: link problem in cobol with sql

Jump to solution
Are you using a 64-bit version of DB2 on your system?

I am running on Windows 7 64-bit also and 64-bit products are installed to c:\program files\ whereas 32-bit products are installed to c:\program files (x86)\

This leads me to believe that you have a 64-bit version of DB2 installed but you are trying to compile the COBOL application as 32-bit.

This will not work.

You can change the bitism on the property page entitled Target Platform Settings to 64-bit if this is what you wish to use.

I compiled and linked your program successfully in Eclipse Visual COBOL in a native project with chipset set to 32-bit and linking to 32-bit DB2 library.

If you wish to link to 32-bit then you need to use the 32-bit DB2 library.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: link problem in cobol with sql

Jump to solution
THANKS

I REMOVE THE DB2 64 BIT FROM MY WINDOWS 7 64 BIT SYSTEM
AND INSTALL DB2 32 BIT
NOW IT WORKS

SHLOMO
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: link problem in cobol with sql

Jump to solution
I'm trying to run the same sample program and have run into this as well.
In Visual Studio 2015 these options appear to have been renamed and or moved.
The properties window under COBOL does not appear to have a Build configurations section or button. There is General, Errors and Warnings, Output, Additional directives and Build settings.

Build settings can not be edited directly but I tried to add the db2api.lib in the "Additional copybook paths both as just the path to the lib dir and with the full path to the db2api.lib.

There is also a COBOL link section under properties so I tried adding the db2api lib in the "Link with libs".

Adding the db2api lib in either of these resolves the "LNK2001: unresolved external symbol" error.

Can anyone explain what the difference is between these two options?

Just in case anyone else runs into this: you need to restart Visual Studio after installing the 32bit DB2 driver to pick up changes to %PATH%.
Before restarting I ran into another error: "Required DB software: 'db2agapi' could not be found."
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: link problem in cobol with sql

Jump to solution
I think you are confusing two products here. The original post was referencing the Visual COBOL for Eclipse product which uses Build Configurations in its properties. You are using the Visual COBOL for Visual Studio product which has a different set of properties. In Visual Studio you set up import libraries and additional object files on the Link tab as you have found. The .lib files are not copybooks but import libraries and need to be added to the Link with these libs section.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.