我目前面临这个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
失败,module ont found : PQconnectdb
我注意到如果我重命名libpq.dll,错误消息将更改为can't find entry point
。所以至少我确定它可以得到我的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。
我错过了什么?
答案 0 :(得分:3)
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。