I have multiple questions here. Sorry for long description.
I have 2 programs. Program1.cob and Program2.cob.
As program2.cob has linkage section, I have written Program1.cob to call Program2.cob.
Identification Division.
Program-id. Program1.
Data division.
working-storage section.
01 parm-data.
05 parm-value pic x(256).
procedure division.
accept parm-data from command-line.
call "Program2" using parm-value.
stop run.
Then I create Porgram1.exe by below command. I have build GnuCobol using VS 2019.
cobc -x Program1.cob Program2.cob
When I run Program1.exe I get below error message.
c:\OCVS\Programs>Program1.exe
libcob: error: module 'S_GetCurrentDir' not found
I see in Program2, there is a call to S_GetCurrentDir function.
In my existing build environment, the link command is as follows. In this environment Realia compiler is used to create Program2.obj
link.exe /NOLOGO /INCREMENTAL:NO /SUBSYSTEM:WINDOWS /machine:X86 "/DEBUG:FULL" /ENTRY:_RealiaCOBOLexeentry /OUT:Program2.EXE Program2.OBJ msvcrt.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib oldnames.lib oldnames.lib
So I suppose S_GetCurrentDir function is part of library/dll files mentioned above (one of the file from msvcrt.lib to oldnames.lib). Probably there are other calls in Program2.cob which requires all of these files.
when I try COBC command I get below error message. I hope this command is euivalent to link command given above.
cobc -x Program1.cob Program2.cob msvcrt.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib oldnames.lib oldnames.lib
Program2.cob: cobc: msvcrt.lib: No such file or directory
I see that, in the same cmd prompt, link.exe command works fine but for cobc it gives error as msvcrt.lib not found. Somehow these files are avaialble to link.exe but not to cobc.
I tried setting up the VS environment by calling below batch files.
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\VsDevCmd.bat"
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars32.bat"
Is it possible to use link.exe after creating obj files using COBC compiler?
When I use below link command, I get many link errors.
c:\OCVS\Programs\Program2>link.exe /NOLOGO /INCREMENTAL:NO /SUBSYSTEM:WINDOWS /machine:X86 "/DEBUG:FULL" /OUT:Program2.EXE Program2.OBJ msvcrt.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib oldnames.lib carclw62.lib oldnames.lib
Creating library Program2.lib and object Program2.exp
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_get_global_ptr referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_module_global_enter referenced in function _Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_module_leave referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_module_free referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_stop_run referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_fatal_error referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_check_version referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_inspect_init referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_inspect_start referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_inspect_before referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_inspect_characters referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_inspect_all referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_inspect_finish referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_string_init referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_string_delimited referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_string_append referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_string_finish referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_unstring_init referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_unstring_delimited referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_unstring_into referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_unstring_finish referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_move referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_set_int referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_set_cancel referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_resolve_cobol referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_display referenced in function Program2
msvcrt.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ)
Hence I added libcob.lib file in the list and I get one link error.
c:\OCVS\Programs>link.exe /NOLOGO /INCREMENTAL:NO /SUBSYSTEM:WINDOWS /machine:X86 "/DEBUG:FULL" /OUT:Program2.EXE Program2.OBJ msvcrt.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib oldnames.lib carclw62.lib oldnames.lib libcob.lib
Creating library Program2.lib and object Program2.exp
msvcrt.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ)
Program2.EXE : fatal error LNK1120: 1 unresolved externals
Please note that in the link command (for object craeated by Realia compiler), we use /ENTRY:_RealiaCOBOLexeentry statment.
Is there any such /ENTRY parameter for the object files creted by cobc compiler?
For any COBC command(either to create obj,exe, or dll file) is there a way to find euivalent cl.exe and link.exe commands ran by cobc in the background?
Regards,
Abhijeet
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
yes that are multiple questions, I start with the last one:
For any COBC command(either to create obj,exe, or dll file) is there a way to find euivalent cl.exe and link.exe commands ran by cobc in the background?
According to the manual and cobc --help there's the following option:
-v, -verbose display compiler version and the commands invoked by the compiler
So addition of --verbose (or the short form -v, which is a bit more common) seems what you're looking for.
when I try COBC command I get below error message. I hope this command is euivalent to link command given above.
cobc -x Program1.cob Program2.cob msvcrt.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib oldnames.lib oldnames.lib
Program2.cob: cobc: msvcrt.lib: No such file or directory
That isn't equivalent. As you want to directly pass a parameter to the linker, you likely want to tell cobc to do so.
As you're on windows: cobc --help | findstr link prompts you with
-Q <options> add <options> to the C link phase
So -Q "msvcrt.lib" seems to be what you look for here.
As an alternative you can also tell cobc to include the library, cobc --help | findstr lib shows:
-L <directory> add <directory> to library search path
-l <lib> link the library <lib>
So -lmsvcrt should have a chance to work, too.
So I suppose S_GetCurrentDir function is part of library/dll files mentioned above.
Not sure, at least a quick online search did not show anything for "S_GetCurrentDir", could be a realia library call - CBL_GET_CURRENT_DIR may be a good substitute then.
Last - in general: if you want to statically link an entry point then you either have to use a call-convention specifying this or the internal CALL STATIC "someEntry" or -K someEntry or the "all literal calls as static" -static.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
Anonymous
-
2020-07-07
Thank you for your answer.
I found the source of function GetCurrentDir (in Program3.c) and I added that in the cobc command. I also added all the system libs mentioned below as without these I was getting many "unresolved external symbol" errors
Then using option -l and -static worked fine.
Q1.
If it is possible to create a static library Program3.lib and add -l Program3.lib, what would be the cobc command option to create .lib file? Please note that Program3.c just have GetCurrentDir function and do not have main function.
Q2.
If I create obj files for all of the above programs and combine them all together then I get error entry point must be defined
c:\OCVS\Programs>cobc -c Program1.cob
Program1.cob(10): warning: line not terminated by a newline
c:\OCVS\Programs>cobc -c Program2.cob
c:\OCVS\Programs>cobc -c Program3.cob
c:\OCVS\Programs\TN3DPUSR>cobc -x Program1.obj Program2.obj Program3.obj -l msvcrt.lib -l kernel32.lib -l user32.lib -l gdi32.lib -l winspool.lib -l comdlg32.lib -l advapi32.lib -l shell32.lib -l ole32.lib -l oleaut32.lib -l uuid.lib -l odbc32.lib -l odbccp32.lib -l oldnames.lib -l oldnames.lib -static
LINK : fatal error LNK1561: entry point must be defined
Program1.cob is a simple COBOL program (I have given the program code in my first post). The c program conversion of Program1.cob is as below. How do I give entry point in cobc command?
Hi,
I have multiple questions here. Sorry for long description.
I have 2 programs. Program1.cob and Program2.cob.
As program2.cob has linkage section, I have written Program1.cob to call Program2.cob.
Then I create Porgram1.exe by below command. I have build GnuCobol using VS 2019.
cobc -x Program1.cob Program2.cob
When I run Program1.exe I get below error message.
c:\OCVS\Programs>Program1.exe
libcob: error: module 'S_GetCurrentDir' not found
I see in Program2, there is a call to S_GetCurrentDir function.
In my existing build environment, the link command is as follows. In this environment Realia compiler is used to create Program2.obj
link.exe /NOLOGO /INCREMENTAL:NO /SUBSYSTEM:WINDOWS /machine:X86 "/DEBUG:FULL" /ENTRY:_RealiaCOBOLexeentry /OUT:Program2.EXE Program2.OBJ msvcrt.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib oldnames.lib oldnames.lib
So I suppose S_GetCurrentDir function is part of library/dll files mentioned above (one of the file from msvcrt.lib to oldnames.lib). Probably there are other calls in Program2.cob which requires all of these files.
when I try COBC command I get below error message. I hope this command is euivalent to link command given above.
cobc -x Program1.cob Program2.cob msvcrt.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib oldnames.lib oldnames.lib
Program2.cob: cobc: msvcrt.lib: No such file or directory
I see that, in the same cmd prompt, link.exe command works fine but for cobc it gives error as msvcrt.lib not found. Somehow these files are avaialble to link.exe but not to cobc.
I tried setting up the VS environment by calling below batch files.
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\VsDevCmd.bat"
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars32.bat"
Is it possible to use link.exe after creating obj files using COBC compiler?
When I use below link command, I get many link errors.
c:\OCVS\Programs\Program2>link.exe /NOLOGO /INCREMENTAL:NO /SUBSYSTEM:WINDOWS /machine:X86 "/DEBUG:FULL" /OUT:Program2.EXE Program2.OBJ msvcrt.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib oldnames.lib carclw62.lib oldnames.lib
Creating library Program2.lib and object Program2.exp
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_get_global_ptr referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_module_global_enter referenced in function _Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_module_leave referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_module_free referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_stop_run referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_fatal_error referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_check_version referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_inspect_init referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_inspect_start referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_inspect_before referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_inspect_characters referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_inspect_all referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_inspect_finish referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_string_init referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_string_delimited referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_string_append referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_string_finish referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_unstring_init referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_unstring_delimited referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_unstring_into referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_unstring_finish referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_move referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_set_int referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_set_cancel referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_resolve_cobol referenced in function Program2
Program2.OBJ : error LNK2019: unresolved external symbol __imp__cob_display referenced in function Program2
msvcrt.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ)
Hence I added libcob.lib file in the list and I get one link error.
c:\OCVS\Programs>link.exe /NOLOGO /INCREMENTAL:NO /SUBSYSTEM:WINDOWS /machine:X86 "/DEBUG:FULL" /OUT:Program2.EXE Program2.OBJ msvcrt.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib oldnames.lib carclw62.lib oldnames.lib libcob.lib
Creating library Program2.lib and object Program2.exp
msvcrt.lib(exe_winmain.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function "int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ)
Program2.EXE : fatal error LNK1120: 1 unresolved externals
Please note that in the link command (for object craeated by Realia compiler), we use /ENTRY:_RealiaCOBOLexeentry statment.
Is there any such /ENTRY parameter for the object files creted by cobc compiler?
For any COBC command(either to create obj,exe, or dll file) is there a way to find euivalent cl.exe and link.exe commands ran by cobc in the background?
Regards,
Abhijeet
Hi Abhijeet,
yes that are multiple questions, I start with the last one:
According to the manual and
cobc --helpthere's the following option:So addition of
--verbose(or the short form-v, which is a bit more common) seems what you're looking for.That isn't equivalent. As you want to directly pass a parameter to the linker, you likely want to tell cobc to do so.
As you're on windows:
cobc --help | findstr linkprompts you withSo
-Q "msvcrt.lib"seems to be what you look for here.As an alternative you can also tell cobc to include the library,
cobc --help | findstr libshows:So
-lmsvcrtshould have a chance to work, too.Not sure, at least a quick online search did not show anything for "S_GetCurrentDir", could be a realia library call -
CBL_GET_CURRENT_DIRmay be a good substitute then.Last - in general: if you want to statically link an entry point then you either have to use a call-convention specifying this or the internal
CALL STATIC "someEntry"or-K someEntryor the "all literal calls as static"-static.Thank you for your answer.
I found the source of function GetCurrentDir (in Program3.c) and I added that in the cobc command. I also added all the system libs mentioned below as without these I was getting many "unresolved external symbol" errors
Then using option -l and -static worked fine.
cobc -x Program1.cob Program2.cob Program3.c -l msvcrt.lib -l kernel32.lib -l user32.lib -l gdi32.lib -l winspool.lib -l comdlg32.lib -l advapi32.lib -l shell32.lib -l ole32.lib -l oleaut32.lib -l uuid.lib -l odbc32.lib -l odbccp32.lib -l oldnames.lib -l oldnames.lib -static
Q1.
If it is possible to create a static library Program3.lib and add -l Program3.lib, what would be the cobc command option to create .lib file? Please note that Program3.c just have GetCurrentDir function and do not have main function.
Q2.
If I create obj files for all of the above programs and combine them all together then I get error entry point must be defined
c:\OCVS\Programs>cobc -c Program1.cob
Program1.cob(10): warning: line not terminated by a newline
c:\OCVS\Programs>cobc -c Program2.cob
c:\OCVS\Programs>cobc -c Program3.cob
c:\OCVS\Programs\TN3DPUSR>cobc -x Program1.obj Program2.obj Program3.obj -l msvcrt.lib -l kernel32.lib -l user32.lib -l gdi32.lib -l winspool.lib -l comdlg32.lib -l advapi32.lib -l shell32.lib -l ole32.lib -l oleaut32.lib -l uuid.lib -l odbc32.lib -l odbccp32.lib -l oldnames.lib -l oldnames.lib -static
LINK : fatal error LNK1561: entry point must be defined
Program1.cob is a simple COBOL program (I have given the program code in my first post). The c program conversion of Program1.cob is as below. How do I give entry point in cobc command?
/ Functions /
/ PROGRAM-ID 'Program1' /
/ ENTRY 'Program1' /
int
Program1 ()
{
return Program1_ (0);
}
Regards,
Abhijeet