Page 1 of 1

PureLibrary created with C backend fails when using /THREAD option

Posted: Fri Jun 20, 2025 10:19 pm
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>

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

Posted: Sat Jun 21, 2025 10:07 am
by Fred
Yes, you shouldn't use the /THREAD option explicitely, it's done automatically. I will fix this

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

Posted: Sat Jun 21, 2025 11:02 am
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!

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

Posted: Sat Jun 21, 2025 12:18 pm
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.

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

Posted: Sat Jun 21, 2025 12:44 pm
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.