Page 1 of 1
Static Linking of Library (Mac)
Posted: Fri Sep 25, 2015 4:18 pm
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?
Re: Static Linking of Library (Mac)
Posted: Fri Sep 25, 2015 4:21 pm
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
Re: Static Linking of Library (Mac)
Posted: Fri Sep 25, 2015 4:26 pm
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.

Re: Static Linking of Library (Mac)
Posted: Fri Sep 25, 2015 5:26 pm
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.
Re: Static Linking of Library (Mac)
Posted: Sat Sep 26, 2015 3:27 am
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.

Re: Static Linking of Library (Mac)
Posted: Sat Sep 26, 2015 4:59 am
by wilbert
coder14 wrote:WOW! It means exactly that! How did (could) you know that?
I created a few libs myself in the past
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.
Re: Static Linking of Library (Mac)
Posted: Sun Sep 27, 2015 11:48 am
by coder14
wilbert wrote:I created a few libs myself in the past
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?
Re: Static Linking of Library (Mac)
Posted: Sun Sep 27, 2015 12:02 pm
by Fred
PureBasic x86 does generate only 32-bit programs.