Project suddenly won't compile

New to FreeBASIC? Post your questions here.
Post Reply
xX_Pokeman2003_Xx
Posts: 25
Joined: Mar 11, 2022 21:10

Project suddenly won't compile

Post by xX_Pokeman2003_Xx »

I recently decided that I would move a bunch of my file handling functions off to a DLL to more easily share it later. Somewhere in the process of doing so, my code has stopped compiling. The error goes something like this.

Code: Select all

C:\Users\Pokeman2003\Desktop\Project>"compfb\fbc64.exe" -v -exx -x ProjMan.exe -eassert -O 0 -R -edebuginfo Project\main.bas
FreeBASIC Compiler - Version 1.09.0 (2021-12-31), built for win64 (64bit)
Copyright (C) 2004-2021 The FreeBASIC development team.
standalone
target:       win64, x86-64, 64bit
backend:      gcc
compiling:    Project\main.bas -o Project\main.c (main module)
Now compiling main.bas
Now compiling shared\cmacros.bas
WARNING SERIES NOT DEFINED!
WARNING COMPILE TIME NOT DEFINED!
Now compiling shared\errhand.bas
Including \filehandling\...
Now compiling /shared/fdf.bi
Now compiling shared\filehandling\setup.bas
Settings Loader(2) error 61: Illegal inside functions in 'sub loadsetup()'
Now compiling shared\prompt.bas
Prompt Handling(1) error 61: Illegal inside functions in 'function promptchoice(choicelist as zstring) as ubyte'
Project\main.bas(10) error 42: Variable not declared, loadsetup in 'loadsetup()'
Project\main.bas(11) error 61: Illegal inside functions, found 'shared' in 'dim shared state as ubyte = 0'
State Handler(8) error 42: Variable not declared, promptchoice in 'chosen = promptchoice("lpre")'
State Handler(22) error 126: Expected 'END FUNCTION' in 'errhandle'
This WILL compile if you remove loadsetup() and the include for filehandling\include.bas, so I don't understand what's gone wrong here.
Here's the source code, and a copy of the DLL.
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Project suddenly won't compile

Post by badidea »

First error message that is see in your post is:

Code: Select all

Now compiling shared\filehandling\setup.bas
Settings Loader(2) error 61: Illegal inside functions in 'sub loadsetup()'
The code in setup.bas:

Code: Select all

dim file as ubyte
sub loadsetup()
print "Loading..."
file = openfdf("settings")
end sub
The variable 'file' does not exist in loadsetup()
But I do not understand your error message.
xX_Pokeman2003_Xx
Posts: 25
Joined: Mar 11, 2022 21:10

Re: Project suddenly won't compile

Post by xX_Pokeman2003_Xx »

badidea wrote: Mar 31, 2022 19:20 The variable 'file' does not exist in loadsetup()
Semi intentional, it was an attempted fix to the problem I forgot to revert. I, while sleep deprived, remembered the goto command having this issue in the past and to fix it, you just DIM'd everything outside of the goto command.
Of course, it fixed nothing, as most of my sleep deprived escapades happen to not do.
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Project suddenly won't compile

Post by dodicat »

Put your fdf.dll in the same folder as main.bas
Your fdf.bi should be

#print Now compiling /shared/fdf.bi
#inclib "fdf"
declare function openfdf(filename as zstring) as ubyte 'Open a file.

Your setup.bas should be

#PRINT Now compiling shared\filehandling\setup.bas
#line 0 "Settings Loader"
'dim file as ubyte
sub loadsetup()
print "Loading..."
var file = openfdf("settings")
end sub
xX_Pokeman2003_Xx
Posts: 25
Joined: Mar 11, 2022 21:10

Re: Project suddenly won't compile

Post by xX_Pokeman2003_Xx »

Dodicat, with all due respect, how would that change anything? I decided to try it anyways, and as I expected, it changed literally nothing, so unless I've missed something, this isn't a fix at all.
3oheicrw
Posts: 25
Joined: Mar 21, 2022 6:41

Re: Project suddenly won't compile

Post by 3oheicrw »

A lot of errors indeed.

Now compiling main.bas
Now compiling shared\cmacros.bas
WARNING SERIES NOT DEFINED!
WARNING COMPILE TIME NOT DEFINED!
Now compiling shared\errhand.bas
Including \filehandling\...
Now compiling /shared/fdf.bi
Now compiling shared\filehandling\setup.bas
Settings Loader(2) error 61: Illegal inside functions in 'sub loadsetup()'
Now compiling shared\prompt.bas
Prompt Handling(1) error 61: Illegal inside functions in 'function promptchoice(choicelist as zstring) as ubyte'
main.bas(10) error 42: Variable not declared, loadsetup in 'loadsetup()'
main.bas(11) error 61: Illegal inside functions, found 'shared' in 'dim shared state as ubyte = 0'
State Handler(8) error 42: Variable not declared, promptchoice in 'chosen = promptchoice("lpre")'
State Handler(22) error 126: Expected 'END FUNCTION' in 'errhandle'
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Project suddenly won't compile

Post by dodicat »

after my suggested changes:

Compiler output:
Now compiling main.bas
Now compiling shared\cmacros.bas
WARNING SERIES NOT DEFINED!
WARNING COMPILE TIME NOT DEFINED!
Now compiling shared\errhand.bas
Including \filehandling\...
Now compiling /shared/fdf.bi
Now compiling shared\filehandling\setup.bas
Now compiling shared\prompt.bas

Results:
Compilation successful
Generated executable: C:\Users\Computer\Downloads\New folder\Entire Code\Project\FBIDETEMP.exe

System:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 1.09.0 (2021-12-31), built for win64 (64bit)
OS: Windows NT 6.2 (build 9200)

...

so it is working here.

Suggestion
Compile your main with the -pp option to see exactly where your errors are coming from.
#cmdline "-pp"

(Note I wouldn't post a solution if it didn't work here).
Look at your main.pp.bas, you should have your code fixed yourself in about 10 minutes.
xX_Pokeman2003_Xx
Posts: 25
Joined: Mar 11, 2022 21:10

Re: Project suddenly won't compile

Post by xX_Pokeman2003_Xx »

I want to apologize dodicat, you were right. The fixes did work. I applied the two code fixes to the wrong source code copy on my hard drive, so I was really only applying the copying the dll into my source code fix. I'll soon update the thread with the fix information, but I'm exhausted right now.
Again, really, I'm sorry.
Post Reply