Page 1 of 1
PB 6.10B1 Polink fatal error : 1 unresolved external (C_Backend)
Posted: Mon Dec 25, 2023 11:33 am
by al2791
Error Unresolved external symbol 'scanf' - reference from 'Purebasic.obj'
It-s OK with Pb6.04 LTS
Code: Select all
; printf under PB_C
CompilerIf #PB_Compiler_ExecutableFormat<>#PB_Compiler_Console
CompilerError "Exec-Format must be Console in Compiler-Option"
CompilerEndIf
;! int fact(int);
! int fact(int n) {
! if(n>=1)
! return n*fact(n-1);
! else return 1;
! }
OpenConsole()
! int number;
! printf("Enter a positive integer: ");
! scanf("%d",&number);
! printf("Factorial of %d = %d", number, fact(number));
Input()
CloseConsole()
Re: PB 6.10B1 Polink fatal error : 1 unresolved external (C_Backend)
Posted: Mon Dec 25, 2023 3:24 pm
by juergenkulow
Code: Select all
/media/ramdisk/pb610B1/purebasic/compilers/pbcompilerc /media/kulow/BCE4-8C0F/PB/fact.pb --commented
Enter a positive integer: Factorial of 0 = 1PureBasic 6.10 beta 1 - C Backend (Linux - x64)
Loading external modules...
Loading 'c' subsystem
Starting compilation...
20 lines processed.
Creating the executable.
- Feel the ..PuRe.. Power -
/media/ramdisk/pb610B1/purebasic/compilers/pbcompilerc Runtime:137 ms
Under which operating system and which compiler_processor did the problem occur?
Re: PB 6.10B1 Polink fatal error : 1 unresolved external (C_Backend)
Posted: Tue Dec 26, 2023 8:35 am
by al2791
Windows 11 22H2 - X64
Re: PB 6.10B1 Polink fatal error : 1 unresolved external (C_Backend)
Posted: Tue Dec 26, 2023 1:44 pm
by Fred
Did you try to declare scanf() in C before using it ? Using without declaring can lead to issues
Re: PB 6.10B1 Polink fatal error : 1 unresolved external (C_Backend)
Posted: Wed Dec 27, 2023 9:51 am
by al2791
No I don't 'declare scanf() in C before using it
For you information, the program is ok when I used PB 6.04 LTS (x64)
Re: PB 6.10B1 Polink fatal error : 1 unresolved external (C_Backend)
Posted: Wed Dec 27, 2023 11:55 am
by juergenkulow
Code: Select all
; gcc scanf - where is it?
CompilerIf #PB_Compiler_ExecutableFormat<>#PB_Compiler_Console
; CompilerError "Exec-Format must be Console in Compiler-Option"
CompilerEndIf
! int __cdecl scanf(const char * __restrict__ _Format, ...); // { printf("My scanf, where is gcc scanf?\n"); }
Define number.l
OpenConsole()
! scanf("%d",&v_number);
Print(Str(number))
Input()
; PB 6.10 Beta 1 Windows x64
; C Backend F:\PB610B1x64\Compilers\pbcompilerc.exe D:\scanf.pb /CONSOLE
; PureBasic 6.10 beta 1 - C Backend (Windows - x64)
; Loading 'C' subsystem
; Compiling D:\scanf.pb
; Loading external libraries...
; Starting compilation...
; 16 lines processed.
; Creating And launching executable.
; Error: Linker
; error: Unresolved external symbol 'scanf' - referenced from 'PureBasic.obj'.
; POLINK: fatal error: 1 unresolved external(s).
; PB 6.03 LTS Windows x64
; 42
; 42
Re: PB 6.10B1 Polink fatal error : 1 unresolved external (C_Backend)
Posted: Sat Jan 27, 2024 10:37 am
by Fred
You will need to link with legacy libs if you want to use scanf without including stdio.h as told here
https://stackoverflow.com/questions/324 ... tudio-2015.
You can find these 2 libs in VS2022 package
Code: Select all
; printf under PB_C
CompilerIf #PB_Compiler_ExecutableFormat<>#PB_Compiler_Console
CompilerError "Exec-Format must be Console in Compiler-Option"
CompilerEndIf
Import "legacy_stdio_definitions.lib"
EndImport
Import "legacy_stdio_wide_specifiers.lib"
EndImport
;! int fact(int);
! int fact(int n) {
! if(n>=1)
! return n*fact(n-1);
! else return 1;
! }
OpenConsole()
! int number;
! printf("Enter a positive integer: ");
! scanf("%d",&number);
! printf("Factorial of %d = %d", number, fact(number));
Input()
CloseConsole()