Just starting out? Need help? Post your questions and find answers here.
-
al2791
- User

- Posts: 20
- Joined: Mon Oct 23, 2017 7:28 am
Post
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()
-
juergenkulow
- Enthusiast

- Posts: 581
- Joined: Wed Sep 25, 2019 10:18 am
Post
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?
-
al2791
- User

- Posts: 20
- Joined: Mon Oct 23, 2017 7:28 am
Post
by al2791 »
Windows 11 22H2 - X64
-
Fred
- Administrator

- Posts: 18162
- Joined: Fri May 17, 2002 4:39 pm
- Location: France
-
Contact:
Post
by Fred »
Did you try to declare scanf() in C before using it ? Using without declaring can lead to issues
-
al2791
- User

- Posts: 20
- Joined: Mon Oct 23, 2017 7:28 am
Post
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)
-
juergenkulow
- Enthusiast

- Posts: 581
- Joined: Wed Sep 25, 2019 10:18 am
Post
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
-
Fred
- Administrator

- Posts: 18162
- Joined: Fri May 17, 2002 4:39 pm
- Location: France
-
Contact:
Post
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()