November 02, 2025, 02:36:49 PM

News:

IWBasic runs in Windows 11!


duplicate declaration

Started by fasecero, July 21, 2008, 02:47:45 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

fasecero

July 21, 2008, 02:47:45 AM Last Edit: July 21, 2008, 03:54:22 AM by fasecero
Im working on a project and i need to use the functions of a dll. So i put all the declarations of the functions in the dll in a include file (.inc).
I need to use that functions in various sources (.eba) of the project, so in theory i need to include the .inc in every source. But then when i try to compile i get a "duplicate declaration" of every declared function.
In C, to avoid this, exists the commands:
            #ifndef souce_h
            #define source_h
means include the source only is not was included before.
In EB is a way to do this?
Thank you and sorry for my english :)

fasecero

ok, i play with the code to see wath's wrong...

suppose:
           myinclude.inc
      source1.eba
      source2.eba
      source3.eba
if i include "myinclude.inc" in the sources no problem and compiles ok.


But if i have:
           myinclude.inc
      source1.eba
      source1.inc
      source2.eba
      source2.inc
      source3.eba
      source3.inc

and i include "myinclude.inc" in the others inc appears "duplicate declaration".

So, in definitive, we can repeat an include in various sources, but we can't repeat an include in others includes.

pistol350

You can use these preprocessor commands in Ebasic :

$ifndef ....
$define ...



For more info, see the "Conditional Compiling" chapter in user guide.

By the way, if you create a project using the IDE options, I think the proper thing to do is to include the headers as part of the project only once
then the compiler and linker will do the rest of the job.


Regards,

Peter B.