我目前在这个 4 人团队中遇到问题。
使用我在 kiska 下载的二进制文件的网站。我能够将 cobol 编译为 C 并使用 cobcrun 运行它或将其编译为可执行文件。但是我无法让 opencobol 找到 postgres 命令。
这是我的 cobol 脚本的策略:
identification division.
program-id. pgcob.
data division.
working-storage section.
01 pgconn usage pointer.
01 pgres usage pointer.
01 resptr usage pointer.
01 resstr pic x(80) based.
01 result usage binary-long.
01 answer pic x(80).
procedure division.
display "Before connect:" pgconn end-display
call "PQconnectdb" using
by reference "dbname = postgres" & x"00"
by reference "host = 10.37.180.146" & "00"
returning pgconn
end-call
...
调用PQconnectdb
失败,找到模块:PQconnectdb
我注意到,如果我重命名 libpq.dll,错误消息将更改为找不到入口点
。所以至少我确信它可以获取我的 dll。
深入研究libcob
库的调用方法的代码后。我发现可以使用环境变量COB_PRE_LOAD预加载一些dll,但没有结果。
以下是编译 cobol 的脚本:
call "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat"
set COB_CONFIG_DIR=C:\OpenCobol\config
set COB_COPY_DIR=C:\OpenCobol\Copy
set COB_LIBS=%COB_LIBS% c:\OpenCobol\libpq.lib
set COB_LIBRARY_PATH=C:\OpenCobol\bin
set COB_PRE_LOAD=C:\OpenCobol\libpq.dll
@echo on
cobc -info
cobc -free -o pgcob -L:"C:\OpenCobol" -llibpq.lib test_cobol\postgres.cob
call cobcrun pgcob
我没有看到任何丢失的东西,我使用的是 kiska 网站上的 64 位二进制文件,并使用 Visual Studio 中的 64 位 cl.exe,Postgres 也是 64 位版本(使用 dependencyChecker 检查)。
我什至尝试从 Visual Studio 编译生成的 C,结果相同,但我可能会错过一些东西,我对 C 很烂,从来没有真正需要管理 DLL 或使用 Visual Studio。
我错过了什么?
最佳答案
COB_PRE_LOAD 不采用任何路径或扩展名,请参阅 short documentation for the available runtime configurations 。我猜
set COB_LIBRARY_PATH=C:\OpenCobol\bin;C:\OpenCobol
set COB_PRE_LOAD=libpq
会起作用的。如果您没有在其中放置任何其他可执行文件,则可以省略 C:\OpenCobol\bin。
如果它不起作用(即使它起作用),我会尝试在编译时解决 C 函数。要么使用
CALL STATIC "PQconnectdb" using ...
或适当的CALL-CONVENTION
或按原样保留程序并使用
cobc -free -o pgcob -L"C:\OpenCobol" -llibpq -K PQconnectdb test_cobol\postgres.cob
来自 cobc --help:
-K generate CALL to <entry> as static
总的来说:kiska.net 的二进制文件已经过时了。我强烈建议从 official download site 获取更新的或者最好从源代码自己构建它们,请参阅 documentation for building GnuCOBOL with VisualStudio .
关于postgresql - Windows 上使用 Visual Studio 的 OpenCobol 和 PostgreSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40402200/