C Backend Creating static libs (Windows)

Everything else that doesn't fall into one of the other PB categories.
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: C Backend Creating static libs (Windows)

Post by ChrisR »

Did you change the path to libfoo.lib, it must exist currently

Code: Select all

!//precompile E:\PureBasic\Portable\PureBasic_Windows_beta10_X64_6.00\FakeCompilers\libfoo.lib;

I also tried with your method, Justin

Code: Select all

ar.exe rcs c:\pb\PureBasic.a c:\pb\PureBasic.obj
It works well too.
Are there any advantages or drawbacks to either method?
Last edited by ChrisR on Fri Jun 10, 2022 9:12 pm, edited 1 time in total.
Justin
Addict
Addict
Posts: 832
Joined: Sat Apr 26, 2003 2:49 pm

Re: C Backend Creating static libs (Windows)

Post by Justin »

Yes i changed to an existing path but no lib is created, maybe a permission issue?, but the folder does not need write permissions.
Justin
Addict
Addict
Posts: 832
Joined: Sat Apr 26, 2003 2:49 pm

Re: C Backend Creating static libs (Windows)

Post by Justin »

Are there any advantages or drawbacks to either method?
I think idle's method includes the required pb libs automatically but i can't test it because it's not working here.
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: C Backend Creating static libs (Windows)

Post by ChrisR »

In polink.pb, maybe you can add SetClipboardText(cmd)

Code: Select all

RunProgram("polib.exe",cmd,GetCurrentDirectory())    
SetClipboardText(cmd)  ; to Add
MessageRequester("polib",cmd)
and run it manually to see possible messages.
Justin
Addict
Addict
Posts: 832
Joined: Sat Apr 26, 2003 2:49 pm

Re: C Backend Creating static libs (Windows)

Post by Justin »

The cmd was
/OUT:C:\Users\me\Documents\purebasic\static_libs\libfoo.lib libfoo.o

And the error
POLIB: fatal error: File not found: 'libfoo.o'.
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: C Backend Creating static libs (Windows)

Post by ChrisR »

Here libfoo.o is created in %Temp%\PureBasicxxxxxxxxx
Just before MessageRequester("precomp","ok " + tCommand) in gcc.pb (with tCommand = -O2 -o libfoo.o purebasic1.c -c)
Perhaps in cmd, you should add Path=%Path%;%Temp%\PureBasicxxxxxxxxx

If it is not the case, when the message "precomp" appears, try manually in cmd:

Code: Select all

Path=%Path%;%Temp%\PureBasicxxxxxxxxx
gcc_real.exe -O2 -o libfoo.o purebasic1.c -c
My Polib.exe ... SetClipboardText(cmd):

Code: Select all

/OUT:E:\PureBasic\Portable\PureBasic_Windows_beta10_X64_6.00\FakeCompilers\libfoo.lib libfoo.o  C:\Users\ChrisR\AppData\Local\Temp\PureBasic1429593828\Array.lib C:\Users\ChrisR\AppData\Local\Temp\PureBasic1429593828\Cipher.lib C:\Users\ChrisR\AppData\Local\Temp\PureBasic1429593828\CipherMD5.lib C:\Users\ChrisR\AppData\Local\Temp\PureBasic1429593828\Date.lib C:\Users\ChrisR\AppData\Local\Temp\PureBasic1429593828\Map.lib C:\Users\ChrisR\AppData\Local\Temp\PureBasic1429593828\Memory.lib C:\Users\ChrisR\AppData\Local\Temp\PureBasic1429593828\Network.lib C:\Users\ChrisR\AppData\Local\Temp\PureBasic1429593828\SimpleList.lib C:\Users\ChrisR\AppData\Local\Temp\PureBasic1429593828\String.lib C:\Users\ChrisR\AppData\Local\Temp\PureBasic1429593828\System.lib 
Justin
Addict
Addict
Posts: 832
Joined: Sat Apr 26, 2003 2:49 pm

Re: C Backend Creating static libs (Windows)

Post by Justin »

I was using an older beta, updating to beta 10 works, sorry!
User avatar
idle
Always Here
Always Here
Posts: 5093
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: C Backend Creating static libs (Windows)

Post by idle »

That looks like the debugger is on chrisR.
Thanks for the edits, my codes a mess but it's really a case of discovery at the moment.
I need to change the command line for compiling the object and also copy some system files for thread safety.

I'm still on beta 8
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: C Backend Creating static libs (Windows)

Post by ChrisR »

idle wrote: Fri Jun 10, 2022 11:36 pm That looks like the debugger is on chrisR.
Yes, I understood that it was in discovery mode for now, just my 2cts when I can.
I'm just trying to learn how to create a static lib through your knowledge, code. polib, polink... all this is new for me.
User avatar
idle
Always Here
Always Here
Posts: 5093
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: C Backend Creating static libs (Windows)

Post by idle »

Thanks for the help, It's almost there. :D
Justin
Addict
Addict
Posts: 832
Joined: Sat Apr 26, 2003 2:49 pm

Re: C Backend Creating static libs (Windows)

Post by Justin »

I did a quick test with a simple lib and it can be linked into a Visual Studio 2022 project too, for example:

Code: Select all

!//precompile C:\pb\my_math.lib;

  ProcedureCDLL.l Foo_Rnd()
	  ProcedureReturn Random(100)
  EndProcedure
In VS project properties -> linker -> general -> additional library directories, add C:\pb

In VS project properties -> linker -> input -> additional dependencies, add my_math.lib

In the project declare the function like:

Code: Select all

extern "C" long f_foo_rnd(void);
And it works. Using strings need more work, will take a look later.
User avatar
idle
Always Here
Always Here
Posts: 5093
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: C Backend Creating static libs (Windows)

Post by idle »

no you will have to include initialization functions in your lib if its using PB objects and also add the additional libs.

I did tests with producing an a static lib, dll and import lib and the result is more or less the same. I will write it up tomorrow and post it.
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: C Backend Creating static libs (Windows)

Post by jack »

idle wrote: Wed Jun 08, 2022 1:38 am Check your PM's, I've sent you a modification of the compiler flag tool to automate the object creation.
you just need to set the precompile flag as the last flag and specify the location to save it.
hello idle, I am interested in your modified tool, would you post it or send me a pm ?
User avatar
ChrisR
Addict
Addict
Posts: 1150
Joined: Sun Jan 08, 2017 10:27 pm
Location: France

Re: C Backend Creating static libs (Windows)

Post by ChrisR »

jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: C Backend Creating static libs (Windows)

Post by jack »

thank you ChrisR :)
Post Reply