Static Linking of Library (Mac)

Mac OSX specific forum
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Static Linking of Library (Mac)

Post by coder14 »

After successfully static-linking a library with my Windows program I am trying to do the same with Mac OS X.

I used Code::Blocks to create a static library on Mac but get this error:

Code: Select all

Id: warning: ignoring file /Users/jamescordon/dev/statlib/bin/Release/libstatlib.a, file was built for archive which is not the architecture being linked (i386): /Users/jamescordon/dev/statlib/bin/Release/libstatlib.a
Undefined symbols for architecture i386: "_go", referenced from: PStub_go in purebasic.o
Id: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1
Please see my post about Windows static library here: http://www.purebasic.fr/english/viewtop ... 13&t=63370

What is causing this error?
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Static Linking of Library (Mac)

Post by Fred »

coder14 wrote:After successfully static-linking a library with my Windows program I am trying to do the same with Mac OS X.

I used Code::Blocks to create a static library on Mac but get this error:

Code: Select all

Id: warning: ignoring file /Users/jamescordon/dev/statlib/bin/Release/libstatlib.a, file was built for archive which is not the architecture being linked (i386): /Users/jamescordon/dev/statlib/bin/Release/libstatlib.a
Undefined symbols for architecture i386: "_go", referenced from: PStub_go in purebasic.o
Id: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1
Please see my post about Windows static library here: http://www.purebasic.fr/english/viewtop ... 13&t=63370

What is causing this error?
seems like your lib doesn't have a go() function, which is needed by the import.

edit: just read the warning: Id: warning: ignoring file /Users/jamescordon/dev/statlib/bin/Release/libstatlib.a, file was built for archive which is not the architecture being linked (i386): /Users/jamescordon/dev/statlib/bin/Release/libstatlib.a
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Static Linking of Library (Mac)

Post by coder14 »

Fred wrote:edit: just read the warning: Id: warning: ignoring file /Users/jamescordon/dev/statlib/bin/Release/libstatlib.a, file was built for archive which is not the architecture being linked (i386): /Users/jamescordon/dev/statlib/bin/Release/libstatlib.a
Hello Fred. How are you?

I am so sorry that I do not know what it means. My library has the "go" function but what does it mean:
file was built for archive which is not the architecture being linked (i386)?

Thank you so much for reading my post. :D
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Static Linking of Library (Mac)

Post by wilbert »

coder14 wrote:what does it mean:
file was built for archive which is not the architecture being linked (i386)?
It probably means the lib was build for 64 bits and you are using the 32 bits version of PureBasic.
Windows (x64)
Raspberry Pi OS (Arm64)
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Static Linking of Library (Mac)

Post by coder14 »

wilbert wrote:It probably means the lib was build for 64 bits and you are using the 32 bits version of PureBasic.
WOW! It means exactly that! How did (could) you know that?

I downloaded the 32bit version of PureBasic for the Mac just to try this but Code::Blocks for the Mac must be compiling in 64bit (but nothing indicated in the IDE). I tried linking the library with 64bit PureBasic and it works!

I guess experience makes a world of difference. I gave up last night from exhaustion but today is a new day.

Thank you wilbert. Thanks a whole lot. :D
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Static Linking of Library (Mac)

Post by wilbert »

coder14 wrote:WOW! It means exactly that! How did (could) you know that?
I created a few libs myself in the past :wink:

64 bit output is the default setting for XCode which makes sense.
Windows 10 still has both a 32 and 64 bit version but OSX is 64 bit only since OSX 10.7 (although you can still run 32 bit applications).
Only the early Intel based Macs (before 2007) have a processor incapable of running 64 bit and therefore don't support OSX 10.7+ .
If you don't worry about supporting those early Intel Macs, I recommend using the 64 bit version of PureBasic on OSX.
If you use PB code only, 32 bits is not a problem but if you want to use OSX frameworks, a lot of the newer frameworks are only available in 64 bit mode.
Windows (x64)
Raspberry Pi OS (Arm64)
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: Static Linking of Library (Mac)

Post by coder14 »

wilbert wrote:I created a few libs myself in the past :wink:

64 bit output is the default setting for XCode which makes sense.
Windows 10 still has both a 32 and 64 bit version but OSX is 64 bit only since OSX 10.7 (although you can still run 32 bit applications).
Only the early Intel based Macs (before 2007) have a processor incapable of running 64 bit and therefore don't support OSX 10.7+ .
If you don't worry about supporting those early Intel Macs, I recommend using the 64 bit version of PureBasic on OSX.
If you use PB code only, 32 bits is not a problem but if you want to use OSX frameworks, a lot of the newer frameworks are only available in 64 bit mode.
Thank you for the explanation - I did not know that. I thought that PureBasic x86 will generate 32bit programs.

The library is working well with the my PureBasic program but it is acting a little weird. Some of the file data that it reads from disk is incorrect - like file size, writing offset, etc. The library is actually an EXE which I converted to static library and it is 32bit originally.

Is this the reason for the strange results? When converting to 64bit is there any rules about the variables like uint8_t and uint32_t etc?
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Static Linking of Library (Mac)

Post by Fred »

PureBasic x86 does generate only 32-bit programs.
Post Reply