Compile OO from command line ?

[Migrated content. Thread originally posted on 31 January 2011]

Can source code with OO, methods, etc, be compiled from the command line, or does it have to be done in Visual Studio ?
  • Verified Answer

    Sure, you can use the command line as normal, you just need to use the right directives, for example ilgen for .Net and jvmgen for the JVM, for example:


    >cobol Program1.cbl ilgen;
    Micro Focus COBOL
    Version 1.2.00054 Copyright (C) 1984-2010 Micro Focus (IP) Limited.
    * Checking complete with no errors

    >program1
    Hello World

    >cobol Program2.cbl jvmgen;
    Micro Focus COBOL
    Version 1.2.00054 Copyright (C) 1984-2010 Micro Focus (IP) Limited.
    * Checking complete with no errors

    >java Program2
    Hello World

    >type Program1.cbl
           invoke type System.Console::WriteLine("Hello World")

    >type Program2.cbl
           invoke type java.lang.System::out::println("Hello World")


    You can also use the project's created in visual studio from the command line too via the 'msbuild' command..

    Do you have any reason why you need to use the command line?
  • spgennard originally wrote:
    Do you have any reason why you need to use the command line?


    Old habits die hard :-)
    As I am still getting used to VS, and learning OO concepts,
    I tend to use vim to type up something short, and then compile
    from the command line.

    As it happens, the code I was compiling was code I think you wrote
    (same user name) and posted (on StackOverflow) !

  • One of the main advantages in using Visual Studio is the independent and extensible build system AKA msbuild.

    If you create your project using Visual Studio, you can also build it on the command line using msbuild because the project file we create is in fact an msbuild makefile.

    msbuild mycobolproject.cblproj

    Keeping your build configuration in one place whether you're working in the IDE or from the command line makes life a lot simpler.
  • One other thing worth mentioning...

    One of the COBOL settings on the COBOL property page is "generate directives file".

    With this set, the IDE will create a .dir file in the project root directory which you can also use to compile your application.

    cobol source.cbl use(project_name.dir) ;
  • colemanj originally wrote:
    As I am still getting used to VS, and learning OO concepts,
    I tend to use vim to type up something short, and then compile
    from the command line.


    Good to know I'm not the only person in the world using Vim to edit Visual COBOL.

    For quick&dirty programs - typically just to test out some obscure corner of VisCOB .NET syntax - I often just compile with "cobol ... ilgen" (sometimes wrapped in a simple Makefile). For real projects, I use Visual Studio to create the project file, but I typically edit in Vim and build using msbuild on the command line.

    For when I do have to work in Visual Studio, I've installed Jared Parsons' VsVim extension for Visual Studio, which provides a pretty good Vim emulation mode in the VS editor.

    I've also customized my Vim installation with a COBOL syntax file that recognizes more of the .NET syntax, and a hack I made to the Vim sources to better handle the COBOL A-margin for fixed/variable formatted source. (My normal inclination would be to use free format, but a lot of the source I work with is variable-format and shared with other developers.) If you're interested in those, drop me an email at michael.wojcik@microfocus.com.