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

Linux specific forum
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

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

Post 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?
Last edited by Crusiatus Black on Tue Oct 11, 2016 9:34 pm, edited 1 time in total.
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

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

Post 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.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

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

Post 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!
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

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

Post 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.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Crusiatus Black
Enthusiast
Enthusiast
Posts: 389
Joined: Mon May 12, 2008 1:25 pm
Location: The Netherlands
Contact:

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

Post 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.
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!
Post Reply