I have the following code AI is helping me with, but it seems that libc is for cygwin more so than mingw. It keeps saying "licob not finding module memcpy". I tried fooling with pointers, and I was so spacy that i thought about using the perl code example brian left, after he even said, 'for display only' ... lol. I rallied and said, I need to get out C book but am having a little trouble with this compile and link scenario.
Here is the offending code...
Please assist - jim
*> Call the C functionCALL "create_integer_string"USINGBYREFERENCEnum-arrayBYVALUEarray-sizeRETURNINGc-result-pointer.*> Check if the returned pointer is not NULLIFc-result-pointerNOT =NULL*> Call memcpy to copy the C string into the COBOL stringCALL "memcpy"USINGBYREFERENCEc-result-stringBYREFERENCEc-result-pointerBYVALUE256*> Null-terminate the COBOL string just in caseMOVEX"00"TOc-result-string(256:1)DISPLAY "Result from C: "c-result-string*> Free the memory allocated by CCALL "free"USINGBYREFERENCEc-result-pointerELSEDISPLAY "C function returned NULL."END-IF.
#include<stdio.h>#include<stdlib.h>#include<string.h>// Function to create and return a string of integerschar*create_integer_string(int*numbers,intsize){intestimated_size=size*16;// Each integer can take up to 16 characters (including space)char*buffer=(char*)malloc(estimated_size*sizeof(char));if(buffer==NULL){printf("Memory allocation failed\n");returnNULL;}char*current=buffer;for(inti=0;i<size;i++){chartemp[16];sprintf(temp,"%d",numbers[i]);if(i>0){*current=' ';current++;}// Ensure that memcpy is correctly copying the string and its null terminatormemcpy(current,temp,strlen(temp)+1);// Copy string including null terminatorcurrent+=strlen(temp);}returnbuffer;// Returns the dynamically allocated string}/*int main() { int numbers[] = {1, 23, 456, 7890}; int size = sizeof(numbers) / sizeof(numbers[0]); char *result = create_integer_string(numbers, size); if (result != NULL) { printf("Created string: %s\n", result); free(result); // Free the memory when done } return 0;}*/
Last edit: Simon Sobisch 2024-12-31
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This whole winmain thing is killing me with mingw.
I'm certainly a beginner and this one has me STUCK!
thanks
g++-mwindowscobjapi.ojapilib.otestabc.oimageio.ofileselect.o-L"c:\msys64\opt\gixsql\lib"-L"c:\msys64\mingw64\bin"-L.-L/mingw64/lib-lcob-lws2_32-ljapi-lgixsql
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:C:/msys64/mingw64/lib/libmingw32.a(lib64_libmingw32_a-crtexewin.o):infunction`main':C:/M/B/src/mingw-w64/mingw-w64-crt/crt/crtexewin.c:67:(.text.startup+0xc5): undefined reference to `WinMain'
collect2.exe:error:ldreturned1exitstatus
#include<stdio.h>#include<iostream>#include<sstream>#include<string>#include<cstring>// Function to create and return a dynamically allocated string of integerschar*create_integer_string(int*numbers,intsize){std::ostringstreamoss;// Append integers to the string streamfor(inti=0;i<size;++i){if(i>0)oss<<" ";// Add space between numbersoss<<numbers[i];}// Convert the string stream to a std::stringstd::stringresult=oss.str();// Dynamically allocate memory for the string and copy itchar*cstr=newchar[result.size()+1];std::strcpy(cstr,result.c_str());// Copy the string contentreturncstr;// Return the pointer to the allocated string}// Function to free the memory allocated for the stringvoidfree_string(char*str){delete[]str;}intwmain(intargc,wchar_t**argv)return0;}
Last edit: Simon Sobisch 2024-12-31
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You seem to want to create something that is callable from COBOL; in this case you want to add an extern C declaration as well.
The WinMain comes from your command line options - change wMain to WinMain - but again, if you want this to be called by GnuCOBOL you don't want that at all but use -shared (and likely drop -mwindows) to create a shared loadable object. And if you don't want that to be named a.out , then add -o create_integer_string.dll (or -o myhelper.dll which you then place into COB_PRE_LOAD.
... and you likely want to tell the linker to keep all elements (the default is to drop all unused functions and references, which are nearly all of your -l options).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I found a guide to learn about calling c from cobol from ron normal.
I will give that a read.
I could have got this earlier today but I am not that good with all the C and mingw stuff so this is a huge help and I am sure with the guide I got mentioned below I will get there now.
thank you so much. I better save these notes in my notetaking app and back them up.
Hi all-
I want to use pointers in cobol.
I tried thus so far...
I have the following code AI is helping me with, but it seems that libc is for cygwin more so than mingw. It keeps saying "licob not finding module memcpy". I tried fooling with pointers, and I was so spacy that i thought about using the perl code example brian left, after he even said, 'for display only' ... lol. I rallied and said, I need to get out C book but am having a little trouble with this compile and link scenario.
Here is the offending code...
Please assist - jim
Last edit: Simon Sobisch 2024-12-31
i was reviewing and found out that numbers needed fixing to pointer or array. I guess the ai fell asleep a little.
sorry,
thanks
Last edit: Simon Sobisch 2024-12-31
Hi all-
I tried this but I am running out of tries.
This whole winmain thing is killing me with mingw.
I'm certainly a beginner and this one has me STUCK!
thanks
Last edit: Simon Sobisch 2024-12-31
You seem to want to create something that is callable from COBOL; in this case you want to add an
extern Cdeclaration as well.The WinMain comes from your command line options - change
wMaintoWinMain- but again, if you want this to be called by GnuCOBOL you don't want that at all but use-shared(and likely drop-mwindows) to create a shared loadable object. And if you don't want that to be nameda.out, then add-o create_integer_string.dll(or-o myhelper.dllwhich you then place intoCOB_PRE_LOAD.... and you likely want to tell the linker to keep all elements (the default is to drop all unused functions and references, which are nearly all of your
-loptions).Hey Simon,
that was awesome..
I found a guide to learn about calling c from cobol from ron normal.
I will give that a read.
I could have got this earlier today but I am not that good with all the C and mingw stuff so this is a huge help and I am sure with the guide I got mentioned below I will get there now.
thank you so much. I better save these notes in my notetaking app and back them up.
BTW an excellent Happy New Year to you Simon!
thanks,
jim
Sent with Proton Mail secure email.