Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class
1236 views

Eclipse precompile cobol-source with gcc not working

the precompile-step   "P(gcc) -E -P -x c  -I/home/max/workMax/include ENDP"

gets always the error "COBCH0018S Preprocessor error on initialization"

Any idea, what went wrong?

0 Likes
10 Replies
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

system ist redhat-linux, visual-cobol 4
0 Likes
Micro Focus Expert
Micro Focus Expert

Hello lennart.wegner,

Can you give us some background about what you are trying to accomplish? Are you trying to use compiler options that you have previously used at the command line, or in a build script? Are you trying to use Visual COBOL to compile a mixture of COBOL and C routines?

The Micro Focus COBOL preprocessor directive, P, can be used to specify a preprocessor that will operate on COBOL source code before it is processed by the COBOL compiler. This preprocessor must be written specifically to cooperate with the Micro Focus COBOL compiler. I am only familiar with "gcc" as a C compiler, not as a Micro Focus conforming COBOL preprocessor.

Blair McDonald

0 Likes
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

Hello Blair,
i have a lot of cobol-code, running on a mainframe bevore. the cobol-code has a lot of c-includes with cobol-code inside, such as

INPUT-OUTPUT SECTION.
FILE-CONTROL.
#include "I1VOR01"


therefore i have to use a c-precompile to get proper cobol-code. i like to use gcc with -E option (precompile only). this works fine on the command line:

#!/bin/bash
#set -x
P=TTMRK
rm -f $P.cob
gcc -E -P -x c -D _VERSION="'6040'" -I/home/max/workMax/marmInclude -o $P.cob $P.in

do you have suggestions for this problem?

regards

lennart
0 Likes
Micro Focus Expert
Micro Focus Expert

Thank you for the additional info. So, it sounds like you are used to invoking gcc as a first "step" to bring in portions of the COBOL source file. Then in a second step, you separately submit the resulting source file to the COBOL compiler.

I have a couple of ideas, but first, a few more questions. When your "include" files are brought in, is gcc doing any additional processing to the included files? Perhaps replacing strings of text in the files? Are there "nested" #include statements, where one of these included files might also contain #include statements? Or, is gcc just bringing in the #include files as-is?

Blair McDonald

0 Likes
Micro Focus Expert
Micro Focus Expert

Sorry, one more question. Is this a one-time conversion, where you would be able to modify the source files if necessary? Or, do you need to leave them as-is, so that they could also continue to work in the old environment where using gcc is required?

Blair McDonald

0 Likes
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

yes, there ist string replacing like
[tag:define] _VERSION '6040'
..
move _VERSION to picXXXX

furthermore then ist code like

[tag:ifdef] _zos
...
[tag:else]
..
#endif

where [tag:define] _zos ist only set at the mainframe-compile and not at unix



no nested includes
Tags (3)
0 Likes
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

no, not a one-time conversion. the code has to run at different target-machines (mainframe,linux)
0 Likes
Micro Focus Expert
Micro Focus Expert

Thanks for your updates. I would suggest trying the option in the Visual COBOL for Eclipse IDE for a pre-build event, to get the COBOL source generated by gcc using a script.

You can do this by right-clicking on the Project, and selecting Properties. Then, navigate to Micro Focus->Build Configurations-> Events. On the Events pane, you can enter commands that are to be executed before (or after) the actual Build (COBOL compile) takes place. You might try entering a command in the "Pre-build event command line" field to invoke a script, which would run the gcc preprocessor against each program in the project.

Blair McDonald

0 Likes
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

Thanks for the hint. I tried this already.
Can you tell me where to find the actual build-variables-names, such as program name, to pass it on to the script ?
The "event"-gcc-script has to start the precompile and write the output in a temp-file.
The temp-file has to be the new input file for the following compile-step.

0 Likes
Micro Focus Expert
Micro Focus Expert

The command or script that you enter into the pre-build event is executed before the build of the programs actually begins. I don't believe that there is any variable that would allow you pick up program names for your script. I was thinking you might be able to write a script that would loop through the .in files, and where they were newer than the equivalent .cob files, invoke gcc to generate a new .cob from the .in. This idea assumes that you would be editing the .in files, and never manually touch the .cob files. Because the COBOL builder automatically builds files with the .cob extension, the resulting files should get picked up and compiled by the normal build process. Please note that I have not tested this idea - you would need to test to confirm that it works for you.

Another option (aside from writing a script) would be to write your own Integrated Preprocessor, sometimes called a "stacked" preprocessor. This could probably be written to do what gcc is doing for you now. Once written and compiled, an Integrated Preprocessor can be specified within your Build Configuration on the "Additional Preprocessors" pane. Integrated Preprocessors have the ability to make changes to each line of source before the compiler "sees" it, as well as insert lines, remove lines, etc. Here is a link to information in the documentation about Integrated Preprocessors:

www.microfocus.com/.../GUID-006D4634-7E8B-4D85-A3BC-15B4965E33C0.html

Blair McDonald

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.