Aji*_*HTA 22 programming software-installation
谁能解释一下如何在 Ubuntu 中编译和运行 COBOL 程序?我从未在 Ubuntu 中编写过任何程序。请给我一个简单的程序来编译和运行。
War*_*ill 40
COBOL在 Linux 上并不是特别流行,但有可用的编译器。其中之一是开放式cobol。
第一步是检查它是否安装在您的系统上:它可能没有。
whereis cobc; which cobc
cobc:
Run Code Online (Sandbox Code Playgroud)
如果像我的系统一样没有安装它,你可以安装它
sudo apt-get install open-cobol
Run Code Online (Sandbox Code Playgroud)
并检查其安装 whereis cobc; which cobc
cobc: /usr/bin/cobc /usr/bin/X11/cobc /usr/share/man/man1/cobc.1.gz
/usr/bin/cobc
Run Code Online (Sandbox Code Playgroud)
现在让我们用任何文本编辑器编写我们的第一个程序。
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
*> simple hello world program
PROCEDURE DIVISION.
DISPLAY 'Hello world!'.
STOP RUN.
Run Code Online (Sandbox Code Playgroud)
将其保存为“helloworld.cbl”
我们现在可以编译它 cobc -free -x -o helloworld helloworld.cbl
在我的系统上,我看到了这个
$ cobc -free -x -o helloworld helloworld.cbl
/tmp/cob3837_0.c: In function ‘HELLO_2DWORLD_’:
/tmp/cob3837_0.c:75:7: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob3837_0.c:76:7: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob3837_0.c:77:7: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob3837_0.c:88:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob3837_0.c:107:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
/tmp/cob3837_0.c:111:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
Run Code Online (Sandbox Code Playgroud)
一些警告 - 但没有错误测试 ./helloworld
Hello World!
Run Code Online (Sandbox Code Playgroud)
有用。
替代(固定格式):
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
* simple hello world program
PROCEDURE DIVISION.
DISPLAY 'Hello world!'.
STOP RUN.
Run Code Online (Sandbox Code Playgroud)
将其另存为“helloworld.cob”并使用cobc helloworld.cob(使用cobcrun helloworld.
如果您想从 C 编译器中删除警告:下载当前的 GnuCOBOL 2.x 快照(尚未更新包)并自行构建(需要额外的apt-get bison flex libdb-dev curses-dev)。
取自:
Cobol Hello World 示例:如何在thegeekstuff.com上的 Linux 操作系统上编写、编译和执行 Cobol 程序
在 Ubuntu 12.04.2 上测试
您可以使用 open-cobol 编译器。只需按键盘上的Ctrl+ Alt+T打开终端。打开后,运行以下命令:
sudo apt-get install open-cobol
cobc your_program_here.cbl
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
43340 次 |
| 最近记录: |