News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Error - Function is already defined

Started by matty47, September 06, 2024, 04:25:14 AM

Previous topic - Next topic

matty47

I tried to create an include file for an external dll. I am sure that I followed the help file with LinkDLL, then functions with parameters and alias, then EndLinkDLL.
When I include the file I get a Function is already defined error.
I also added some constants at the top of the include file before the LinkDLL and these triggered a Constant already defined error.
; PROJECT : irrlicht
; EDITED  : 6/09/2024
; ---------------------------------------------------------------------
 //Constants
 //gui interface
Constant IRR_GUI_NO_BORDER = 0
Constant IRR_GUI_BORDER = 1
Constant IRR_GUI_NO_WRAP = 0
Constant IRR_GUI_WRAP = 1
 //keyboard
Constant KEY_ESCAPE = 27
//open the irrlicht interface
LinkDll "bIrrlicht.dll"
//global
iIrr3D(width,height,depth,fullscreen) Alias "iIrr3D" As Integer
iAppTitle(title$) Alias "iAppTitle"
iCameraCLSColor(r,g,b) Alias "iCameraCLSColor"
iRun() Alias "iRun" As Integer
iBeginScene() Alias "iBeginScene"
iEndScene() Alias "iEndScene"
iDrawGUI() Alias "iDrawGUI"
iEndIrr3D() Alias "iEndIrr3D"


//events
iKeyHit(key) Alias "iKeyHit" As Integer


//gui
iStaticText(txt$,topX,topY,botX,botY,border,wordwrap,parent) Alias "iStaticText" As Integer


EndLinkDll
What have I done wrong??

kevin


 Hi Matty47,


   I don't get any compile errors pasting your code into PlayBASIC.  What's the project your using this within ?  as I suspect either the file is included more than once.


    So effectively constants and function names need to be unique.   

PlayBASIC Code: [Select]
      constant myConstant = 123456
constant myConstant = 123456


Function Stuff()
EndFunction


Function Stuff()
EndFunction






PlayBASIC Code: [Select]



matty47

#2
Thanks for the reply.
Here is the code from main.pba
; PROJECT : irrlicht
; AUTHOR  :
; CREATED : 6/09/2024
; EDITED  : 6/09/2024
; ---------------------------------------------------------------------

#Include "irrInc.pba"

//start irrlicht
iIrr3D(640,480,32,0)
//set the app title
iAppTitle("Hello World Example")
//add a static text
iStaticText("Hello World",4,0,200,16,IRR_GUI_NO_BORDER,IRR_GUI_NO_WRAP,0)
//erase the canvas color to white before rendering
iCameraCLSColor(255,255,255)
//now the main loop
While iRun() And Not iKeyHit(KEY_ESCAPE))
//begin the scene
iBeginScene()
//draw the GUI
iDrawGUI()
//end the scene
iEndScene()
EndWhile
//stop the irrlicht engine
iEndIrr3D()
End

The code in the first post was the include file. I think the constant and function names were unique.
I am using version 1.65C3 Beta09.

kevin


  if i remove this line and endwhile it compiles fine

PlayBASIC Code: [Select]
   While iRun() And Not iKeyHit(KEY_ESCAPE))




    There's an extra bracket at the end,

    It doesn't run here as i don't have the dll, but compiles ok once removing the bracket   





matty47

Thanks for getting back to me.
Still could not get this to compile with the include file, (I did fix the error in the while statement). If I moved the definitions into the main.pba and did not try to use the include it worked!!
This code compiled and ran OK.
; PROJECT : irrlicht
; AUTHOR  : mingle47@gmail.com
; CREATED : 6/09/2024
; EDITED  : 7/09/2024
; ---------------------------------------------------------------------
Constant IRR_GUI_NO_BORDER = 0
Constant IRR_GUI_BORDER = 1
Constant IRR_GUI_NO_WRAP = 0
Constant IRR_GUI_WRAP = 1
Constant KEY_ESCAPE = 27

LinkDll "bIrrlicht.dll"
//global
iIrr3D(width,height,depth,fullscreen) Alias "iIrr3D" As Integer
iAppTitle(title$) Alias "iAppTitle"
iCameraCLSColor(r,g,b) Alias "iCameraCLSColor"
iRun() Alias "iRun" As Integer
iBeginScene() Alias "iBeginScene"
iEndScene() Alias "iEndScene"
iDrawGUI() Alias "iDrawGUI"
iEndIrr3D() Alias "iEndIrr3D"


//events
iKeyHit(key) Alias "iKeyHit" As Integer


//gui
iStaticText(txt$,topX,topY,botX,botY,border,wordwrap,parent) Alias "iStaticText" As Integer


EndLinkDll

//start irrlicht
iIrr3D(640,480,32,0)
//set the app title
iAppTitle("Hello World Example")
//add a static text
iStaticText("Hello World",4,0,200,16,IRR_GUI_NO_BORDER,IRR_GUI_NO_WRAP,0)
//erase the canvas color to white before rendering
iCameraCLSColor(255,255,255)
//now the main loop
While iRun() And Not iKeyHit(KEY_ESCAPE)
//begin the scene
iBeginScene()
//draw the GUI
iDrawGUI()
//end the scene
iEndScene()
EndWhile
//stop the irrlicht engine
iEndIrr3D()
End
So it looks like I am doing something wrong with the include. I did add the include file in the project list. Should I not have done that?
What version are you using?

matty47

Since the above worked I removed the include file from the project manager list. Unfortunately the IDE crashed and wiped out the main.pba in the process.
I reconstructed the main.pba and this is the only file now shown in the project list.
The file compiled and ran OK, so the original error was in adding the include file to the project manager list.
I could not find a way to open just a file (the include file) in the ide without adding it to the project list which means that I had to edit the include file in an external editor.
I guess this sort of solves the problem.

kevin

QuoteI did add the include file in the project list. Should I not have done that?

  Naah..  kind assumed this is what you'd done.  If the file is part project and then you #include that same file directly at some other point.  You'll get collisions. 


QuoteWhat version are you using?

  Whatever the current built is, which I think is 1.65C3 beta 10 from memory.  Tested some older revisions and all works as expected.   1.65 was missing a runtime error when the linked dll wasn't present.   

    You can open any #include by right clicking the file from the IDE,  there's option to open the include.