Page 1 of 1

[Solved] Compiling C to PB compatible static lib on Mint x64

Posted: Tue Oct 11, 2016 6:40 pm
by Crusiatus Black
Hi there all,

I'm trying to compile the ISAAC algorithm (standard.h, rand.h, rand.c) into a static library on Linux.
Specifically, Iḿ using gcc to compile rand.c to rand.o, after which I use ar to create a static library.

Code: Select all

gcc -c rand.c
ar rvs rand.a rand.o
However, the problem is that upon linking with a PureBasic project (5.42 LTS x64) everything seems fine,
until I try calling randinit on a CTX. This shouldn't be a problem, the exact same code compiled on Windows
functions as expected on both x64 and x86 systems. I'm having this problem on Linux Mint 17 x64 with Cinnamon.

The simplest PB test file I use which causes the compiler to report an unexpected exit after a second or two:

Code: Select all

#RANDSIZL = 8
#RANDSIZ  = (1 << #RANDSIZL)

Structure randctx Align #PB_Structure_AlignC
  randcnt.l
  randrsl.l[#RANDSIZ]
  randmem.l[#RANDSIZ]
  randa.l
  randb.l
  randc.l
EndStructure

ImportC "rand.a"
  isaac.i    (*ctx.randctx)
  randinit.i (*ctx.randctx, flag.i = 0)
EndImport

Define test.randctx
randinit(@test, #False)
Can anybode point me in the right direction?

Re: Compiling C to PB compatible static lib on Linux Mint x6

Posted: Tue Oct 11, 2016 8:21 pm
by wilbert
I'm not sure if it is related to the problem you are having.
When using the zlib library, the Windows version (x86 and x64) needs .l inside a structure the library requires while both Linux and OSX need .i
So it is very well possible, that your randctx structure is fine this way for Windows but that some or all of the fields need to be declared as .i on Linux.

Re: Compiling C to PB compatible static lib on Linux Mint x6

Posted: Tue Oct 11, 2016 9:18 pm
by Crusiatus Black
wilbert wrote:I'm not sure if it is related to the problem you are having.
When using the zlib library, the Windows version (x86 and x64) needs .l inside a structure the library requires while both Linux and OSX need .i
So it is very well possible, that your randctx structure is fine this way for Windows but that some or all of the fields need to be declared as .i on Linux.
Thanks for your reply,

Ah yes, an unsigned long int is 64-bits wide to gcc. (I tried with a simple printf("%d", sizeof(unsigned long int));)
That's funny, because the VC++ compiler keeps it at 32-bits. Thanks for the tip Wilbert!

Edit - That did the trick, thanks Wilbert!

Re: Compiling C to PB compatible static lib on Linux Mint x6

Posted: Wed Oct 12, 2016 6:01 am
by wilbert
Crusiatus Black wrote:Ah yes, an unsigned long int is 64-bits wide to gcc. (I tried with a simple printf("%d", sizeof(unsigned long int));)
That's funny, because the VC++ compiler keeps it at 32-bits. Thanks for the tip Wilbert!
Good to hear it worked :)
I sometimes wish those C types would be better documented and more uniform across different compilers.
Things like this make it more complicated to define the right structures.

Re: Compiling C to PB compatible static lib on Linux Mint x6

Posted: Wed Oct 12, 2016 6:27 am
by Crusiatus Black
wilbert wrote:
Crusiatus Black wrote:Ah yes, an unsigned long int is 64-bits wide to gcc. (I tried with a simple printf("%d", sizeof(unsigned long int));)
That's funny, because the VC++ compiler keeps it at 32-bits. Thanks for the tip Wilbert!
Good to hear it worked :)
I sometimes wish those C types would be better documented and more uniform across different compilers.
Things like this make it more complicated to define the right structures.
I agree, it's rather peculiar that C types differ from compiler to compiler.
It's logical that they are different between architectures, but for example
on 64-bit Linux and 64-bit Windows a type should be of the same size.

I now wonder if there is a difference between MinGW and VC++ on Windows.