Install mingw, the official installer is broken, go to:
https://winlibs.com/#download-release
Download the UCRT runtime MinGW-w64 version.
Unzip it, in my case i have it in c:\mingw64
Add c:\mingw64\bin to your environment path variable.
Check that it's working, open a command prompt and type gcc --version
Now the pb lib code:
Code: Select all
EnableExplicit
ProcedureDLL add(a.l, b.l)
ProcedureReturn a + b
EndProcedure
https://www.purebasic.fr/german/viewtop ... 93#p361093
The generated purebasic.c is:
Code: Select all
#pragma warning(disable: 4024)
typedef long long quad;
typedef quad integer;
#define PB_INFINITY (1.0 / 0.0)
#define PB_NEG_INFINITY (-1.0 / 0.0)
typedef struct pb_array { void *a; } pb_array;
typedef struct pb_array2 { void *a; integer b[2]; } pb_array2;
typedef struct pb_array3 { void *a; integer b[3]; } pb_array3;
typedef struct pb_array4 { void *a; integer b[4]; } pb_array4;
typedef struct pb_array5 { void *a; integer b[5]; } pb_array5;
typedef struct pb_array6 { void *a; integer b[6]; } pb_array6;
typedef struct pb_array7 { void *a; integer b[7]; } pb_array7;
typedef struct pb_array8 { void *a; integer b[8]; } pb_array8;
typedef struct pb_array9 { void *a; integer b[9]; } pb_array9;
typedef struct pb_listitem { void *a; void *b; void *c;} pb_listitem;
typedef struct pb_list { void *a; pb_listitem *b; } pb_list;
typedef struct pb_mapitem { void *a; void *b; void *c;} pb_mapitem;
typedef struct pb_pbmap { pb_mapitem *a; } pb_pbmap;
typedef struct pb_map { pb_pbmap *a; } pb_map;
static integer s_s[]={0, -1};
#define M_SYSFUNCTION(a) a
#define M_PBFUNCTION(a) a
#define M_CDECL
typedef void TCHAR;
static integer SYS_BankerRound (double i) { return i >= 0 ? i+0.5 : i-0.5; }
static quad SYS_BankerRoundQuad(double i) { return i >= 0 ? i+0.5 : i-0.5; }
integer f_exitprocess_(integer) asm("ExitProcess");
integer f_heapcreate_(integer,integer,integer) asm("HeapCreate");
integer f_heapdestroy_(integer) asm("HeapDestroy");
integer f_getmodulehandle_(integer) asm("GetModuleHandleW");
static char *tls;
int PB_ExitCode=0;
integer PB_MemoryBase=0;
integer PB_Instance=0;
unsigned char *pb_datapointer;
void SYS_Quit();
M_SYSFUNCTION(void) SYS_InitPureBasic();
int PB_DEBUGGER_LineNumber=-1;
int PB_DEBUGGER_IncludedFiles=0;
char *PB_DEBUGGER_FileName=0;
integer f_add(int v_a,int v_b);
static integer ms_s[]={0,-1};
integer f_add(int v_a,int v_b) {
integer r=0;
r=(v_a+v_b);
goto end;
r=0;
end:
return r;
}
int PB_Compiler_Unicode=1;
int PB_Compiler_Thread=0;
int PB_Compiler_Purifier=0;
int PB_Compiler_Debugger=0;
int PB_Compiler_DPIAware=1;
int PB_Compiler_XPSkins=1;
int PB_ExecutableType=0;
void PB_EndFunctions() {
}
int WinMain(void *instance, void *prevInstance, void *cmdLine, int cmdShow) {
PB_Instance = f_getmodulehandle_(0);
PB_MemoryBase = f_heapcreate_(0,4096,0);
//
SYS_Quit();
}
void SYS_Quit() {
PB_EndFunctions();
f_heapdestroy_(PB_MemoryBase);
f_exitprocess_(PB_ExitCode);
}
We need the obj file from this c file, open a command prompt and go to the pb compilers folder, and use its gcc compiler, adapt the paths to the files, command line thanks to tool from idle.
gcc -O0 -fsigned-char -Wno-incompatible-pointer-types -Wno-overflow -Wno-int-conversion -c -o c:\pb\PureBasic.obj c:\pb\purebasic.c
This will create c:\pb\PureBasic.obj
Now use the ar.exe tool from the mingw installation to create a static lib:
ar rcs c:\pb\PureBasic.a c:\pb\PureBasic.obj
This will create the static lib c:\pb\PureBasic.a
Now use it from pb:
Code: Select all
Import "purebasic.a"
add(a.l, b.l) As "f_add"
EndImport
MessageRequester("", Str(add(2,3)))