PureLibrary created with C backend fails when using /THREAD option

Post bugreports for the Windows version here
Taz
User
User
Posts: 75
Joined: Sat Jan 20, 2018 5:28 pm
Location: Germany

PureLibrary created with C backend fails when using /THREAD option

Post by Taz »

Hi, I believe I’ve found a bug related to the use of custom PureLibraries with the C backend and the /THREAD option.

Environment:
  • PureBasic 6.21 x64
  • Windows 10 x64
  • C Backend (issue only occurs here)
  • ASM Backend works fine
Description:
I created a simple PureLibrary using pbcompilerc.exe with the /PURELIBRARY and /THREAD options. The library compiles successfully.
However, when I try to use this library in another file compiled with /THREAD, I get a linker error.
This issue only appears when:
  • The C backend is used AND The /THREAD flag is set
  • The ASM backend does not have this issue (threaded or not)
Steps to reproduce:

File: libTest.pb

Code: Select all

EnableExplicit
DisablePureLibrary Test

ProcedureDLL$ Test(Str$)
	ProcedureReturn Trim(Str$)
EndProcedure
File: test.pb

Code: Select all

EnableExplicit
Test(" Ups ")
Library creation command:

Code: Select all

pbcompilerc.exe "T:\libTest.pb" /THREAD /OPTIMIZER /PURELIBRARY /OUTPUT "Test"
App compilation command:

Code: Select all

pbcompilerc.exe "T:\test.pb" /THREAD /OPTIMIZER /OUTPUT "T:\test.exe"
Error:

Code: Select all

Error: Linker
error: undefined symbol: PB_StringBasePosition
>>> referenced by Test.lib(purebasicnothread.obj):(.refptr.PB_StringBasePosition)
Additional Notes:
  • If I remove the /THREAD option from either compilation, it works fine.
  • This seems to indicate an inconsistency between threaded libraries and the C backend.
  • The presence or absence of the /OPTIMIZER flag does not change the outcome.
Could someone from the team take a look? Or perhaps confirm if there's a workaround?

Thanks!

Console output:
Image

Code: Select all

T:\PB_6.21_x64>pbcompilerc.exe "T:\libTest.pb" /THREAD /PURELIBRARY /OUTPUT "Test"
PureBasic 6.21 - C Backend (Windows - x64)
Compiling T:\libTest.pb
Loading external libraries...
Starting compilation...
6 lines processed.
Creating threaded version of the PureLibrary...
Starting compilation...
6 lines processed.
PureLibrary successfully created: "T:\PB_6.21_x64\purelibraries/userlibraries/Test".

- Feel the ..PuRe.. Power -

T:\PB_6.21_x64>pbcompilerc.exe "T:\test.pb" /THREAD /OUTPUT "T:\test.exe
PureBasic 6.21 - C Backend (Windows - x64)
Compiling T:\test.pb
Loading external libraries...
Starting compilation...
2 lines processed.
Creating executable "T:\test.exe".
Error: Linker
error: undefined symbol: PB_StringBasePosition
>>> referenced by Test.lib(purebasicnothread.obj):(.refptr.PB_StringBasePosition)

T:\PB_6.21_x64>
Fred
Administrator
Administrator
Posts: 18153
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PureLibrary created with C backend fails when using /THREAD option

Post by Fred »

Yes, you shouldn't use the /THREAD option explicitely, it's done automatically. I will fix this
Taz
User
User
Posts: 75
Joined: Sat Jan 20, 2018 5:28 pm
Location: Germany

Re: PureLibrary created with C backend fails when using /THREAD option

Post by Taz »

Thanks for the clarification, Fred!

Just to confirm: I removed the /THREAD flag when building the PureLibrary, and it still generates the threaded version automatically, as expected.

However, when I then try to compile and run the program that uses this library with the /THREAD option, I still get the same linker error:

Code: Select all

Error: Linker
error: undefined symbol: PB_StringBasePosition
>>> referenced by Test.lib(purebasicnothread.obj):(.refptr.PB_StringBasePosition)
So while the /THREAD flag is no longer used manually when building the PureLibrary, the resulting library still causes the same issue when used in a threaded program (C backend).
This issue only appears when I then try to compile and run the program that uses this library and:
  • The C backend is used AND The /THREAD flag is set
  • The ASM backend does not have this issue (threaded or not)
Let me know if I misunderstood something. Otherwise, I guess this is still part of the same underlying issue.

Thanks again!
User avatar
mk-soft
Always Here
Always Here
Posts: 6201
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PureLibrary created with C backend fails when using /THREAD option

Post by mk-soft »

Same problem with Linux :cry:

Don't two different libraries have to be created automatically?
One with and one without thread safe. Or does one library support both?
You don't want to recompile for the required library every time.
Last edited by mk-soft on Sat Jun 21, 2025 12:58 pm, edited 1 time in total.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 6201
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PureLibrary created with C backend fails when using /THREAD option

Post by mk-soft »

I also pack errors in macOS here, because it fits!

With macOS and using the library with Enable ThreadSafe this error occurs
error: call to undeclared function 'PB_FreeFormatStrings'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
438 | PB_FreeFormatStrings();
| ^
1 error generated.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply