0

I have a program and a subprogram. I compile my program with the following statement:

cobc -x -free -Wall program.cob

My issue is with my subprogram. I use the following statement to compile it:

cobc -c -free -Wall mysubprogram.cob

When i use the -c flag it compiles but the code doesn't get updated. When i change a value for example in the code, it will compile but that change wont be reflected when I run the program.

But if i change the flag from -c to -m like the following:

cobc -m -free -Wall mysubprogram.cob

This will fix the issue and the changes I made to the code will also appear when I run the code

Can someone please help me understand why this is happening?

Bill Woodger
  • 12,968
  • 4
  • 38
  • 47
Benjer
  • 153
  • 2
  • 10
  • Because, as in the answer to your other question on this subject, the -x will produce an executable, which must be executed from the OS, and the -m will produce a callable-module, which is dynamically loaded to satisfy a CALL in another COBOL program. – Bill Woodger Mar 16 '15 at 20:00
  • possible duplicate of [Executable program requested but PROCEDURE/ENTRY has USING clause](http://stackoverflow.com/questions/29053234/executable-program-requested-but-procedure-entry-has-using-clause) – Bill Woodger Mar 16 '15 at 20:01
  • 1
    But what does the -c do? Which is the right way to compile the subprogram? With -c or -m? – Benjer Mar 16 '15 at 20:04
  • What do you mean when you say, *but the code doesn't get updated*? I know you gave an example (partial), so what exactly are your commands for compiling and linking? The `-m` flag creates a `.so` file which can be linked to your main program (with `cobc -x`), or the `-c` creates a `.o` file which could also be linked (at least it works for me). – lurker Mar 16 '15 at 20:38
  • So does it matter wether I compile with -m or -c? What I do is, first I do -m when I compile the subprogram. Then I use -x when I compile the main program and it works. – Benjer Mar 16 '15 at 20:40
  • `-c` is `Compile and assemble, but do not link`. All the switch values can be found if you do 'cobc -h'. – Bill Woodger Mar 16 '15 at 21:28
  • @Benjer if all you're doing is writing a simple app that runs on your PC, whether you do it with `-m` or `-c` and then directly link the `.so` or `.o`, respectively, you probably won't notice the difference. Sort of like DLL's in Windows, a shared dynamic object enables Linux to share the library dynamically with various programs that link with it, and they can link with them at run time. In dynamic linking, you can compile your main program separately and link later at run time if you desire. See [this description](http://www.opencobol.org/modules/bwiki/index.php?UserManual%2F2_2). – lurker Mar 17 '15 at 01:11
  • Just to note. .so is dynamic linkage, .o static. Entry points in DSO files can be found at run-time. Entry points in .o files are only found during the link phase of a compile pass. `cobc` is fairly powerful Benjer. You can say `cobc -x mainprog.cob subprog.cob` or `cobc -x mainprog.cob subprog.o` and cobc will 'do the right thing'. *Edit: reading more, this is a duplicate comment from what lurker posted.* – Brian Tiffin Mar 18 '15 at 00:29

1 Answers1

1

As per the man page, the -c flag means:

Compile and assemble, but do not link. (pretty much the same way it works when compiling C or C++).

That means the executable is not built (you'll simply get an object file) so either there won't be an executable at all (if this is the first time), or it will be the one from the previous successful non -c build (hence your "but the code doesn't get updated" comment).

The -m option builds a dynamically-loadable module, suitable for linking against. The fact that the linking is dynamic means that an update to the module is reflected immediately in the executable (assuming it's been built of course). See here for details on how this works.

The -x option builds a proper executable and therefore contains your updates automatically.

Community
  • 1
  • 1
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953