Jump to content



Photo
- - - - -

Include Guards


  • Please log in to reply
14 replies to this topic

#1 paul_brassington

paul_brassington

    Newbie

  • Members
  • Pip
  • 25 posts

  • Calculators:
    fx-9860g II SD

Posted 08 March 2013 - 06:17 PM

Hi Guys,

I'm having problems with the classic problem of include guards, when I use Visual Studio 8 I use:

#pragma once

at the top of each C header file and for classes I use

#ifndef MATHSBASE_H
#define MATHSBASE_H
class MathsBase: public Object {
//code here
};
#endif

To get over the compiler errors that something has been included twice.

It doesn't seem to work in Casio 9860G Software Developer Kit IDE using the Hitachi compiler.

But without this how can I develop a large program. I'm sure you guys have solved this issue.

Warm Regards and if anyone needs any help with Java then just ask as I've spent years using this language.

Paul Brassington

#2 Casimo

Casimo

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 641 posts
  • Gender:Not Telling

Posted 08 March 2013 - 06:19 PM

Have you used the cpp-compiler?
Do you use win7-64bit?

#3 paul_brassington

paul_brassington

    Newbie

  • Members
  • Pip
  • 25 posts

  • Calculators:
    fx-9860g II SD

Posted 08 March 2013 - 09:00 PM

Hi,

Yes I use Win7 and 64 bit computer.

Paul

#4 hayzel

hayzel

    Newbie

  • Members
  • Pip
  • 10 posts

Posted 08 March 2013 - 09:48 PM

Hi Guys,
....

#ifndef MATHSBASE_H
#define MATHSBASE_H
class MathsBase: public Object {
//code here
};
#endif

To get over the compiler errors that something has been included twice.

It doesn't seem to work in Casio 9860G Software Developer Kit IDE using the Hitachi compiler.

I use the #ifndef #define #endif notation in the header files (.h) both in c and c++ code, without any problems in casio 9860 sdk ide.
I don't use #pragma though.

#5 Casimo

Casimo

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 641 posts
  • Gender:Not Telling

Posted 09 March 2013 - 10:19 AM

You are running Win7 64bit, so be sure that you installed the SDK in a folder with administrative privileges, for example on 'D' instead of 'C' or on a stick.
Otherwise try to compile just the sample.

#6 paul_brassington

paul_brassington

    Newbie

  • Members
  • Pip
  • 25 posts

  • Calculators:
    fx-9860g II SD

Posted 09 March 2013 - 11:21 AM

Hi Guys,

I'm really stuck here and in desperate need of help. I've taken just about all my code out to make the problem as clear as possible. This compiles in Visual Studio but not in the sdk. I've installed the sdk on an old XP machine without any difference and the sdk is installed on a ram disk with admin rights.

globals.h
#ifndef GLOBALS_H
#define GLOBALS_H
typedef struct menu {
unsigned char type;
int * noitems;
unsigned char * lines[5];
int * tomenus;
int exitmenu;
};
struct menu * menus[6];
#endif

functions.h
#include "fxlib.h"
#include "dispbios.h"
#include "keybios.h"
#include "globals.h"

functions.c
#include "functions.h"
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
int pos[21] = {30,30,10,25,20,5,45,30,15,0,0,10,20,30,40,54,36,27,18,9,0};
int at[6] = {0,1,3,6,10,15};
#endif

mathsanswers.h
#include "functions.h"

mathsanswers.c
#include "mathsanswers.h"

int AddIn_main(int isAppli, unsigned short OptionNum) {

}

#pragma section _BR_Size
unsigned long BR_Size;
#pragma section


#pragma section _TOP

int InitializeSystem(int isAppli, unsigned short OptionNum)
{
return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}

#pragma section

The compiler complaint is:

** L2300 (E) Duplicate symbol "_menus" in "C:\Users\Paul Brassington\Documents\CASIO\fx-9860G SDK\learn\mathsanswers\Debug\functions.obj"

Please help as I'm totally stuck with this.

Paul

#7 Casimo

Casimo

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 641 posts
  • Gender:Not Telling

Posted 09 March 2013 - 12:03 PM

Does it work when you put everything in a single file (mathanswers.c)?

#8 paul_brassington

paul_brassington

    Newbie

  • Members
  • Pip
  • 25 posts

  • Calculators:
    fx-9860g II SD

Posted 09 March 2013 - 05:30 PM

Hi Casimo,

Yes it does work in a single file however it is planned to be a big project and the array of structs (called menus) will contain all the menus and needs to be available to many functions. As such I need to split the project into possibly 50 or so files.

Have you achieved global variables in C for Casio SDK?

Is there a different way to achieve the same objective?

Warm Regards

Paul

#9 Casimo

Casimo

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 641 posts
  • Gender:Not Telling

Posted 09 March 2013 - 05:57 PM

I don't often use multiple files :-|
It could work when you completely remove the #ifdef.
I'll try to find a solution.

#10 3298

3298

    Casio Addict

  • Members
  • PipPipPip
  • 77 posts
  • Gender:Male
  • Location:Germany

  • Calculators:
    fx-9750G Plus
    Algebra FX 2.0 (ROM 1.03,broken)
    HP 50G

Posted 09 March 2013 - 06:21 PM

Visual Studio likes that code? I'm pretty sure GCC would complain as well.
First: Why is the include guard for functions.h not in functions.h, but in functions.c? That doesn't cause the error, but it makes no sense to me.
Second: The "struct menu * menus6" is not a weak symbol, so it will fail while linking because it is present multiple times. My workaround: move this definition into a *.c file (for example, a new globals.c) and put an "extern" before it in the globals.h to make a symbol with an undefined value that will be resolved during linking.

#11 paul_brassington

paul_brassington

    Newbie

  • Members
  • Pip
  • 25 posts

  • Calculators:
    fx-9860g II SD

Posted 09 March 2013 - 06:59 PM

Thanks for your attention and effort guys I really to appreciate this.

Code amended as follows:

globals.h
#ifndef GLOBALS_H
#define GLOBALS_H
typedef struct menu {
unsigned char type;
int * noitems;
unsigned char * lines[5];
int * tomenus;
int exitmenu;
};
extern struct menu * menus[];
#endif

globals.c
#include "globals.h"

struct menu * menus[6];

functions.h
#ifndef FUNCTIONS_H
#define FUNCTIONS_H

#include "fxlib.h"
#include "dispbios.h"
#include "keybios.h"
#include "globals.h"

#endif

functions.c
#include "functions.h"

int pos[21] = {30,30,10,25,20,5,45,30,15,0,0,10,20,30,40,54,36,27,18,9,0};
int at[6] = {0,1,3,6,10,15};

Same error message as before:
** L2300 (E) Duplicate symbol "_menus" in "C:\Users\Paul Brassington\Documents\CASIO\fx-9860G SDK\learn\mathsanswers\Debug\functions.obj"

Any further advice so very welcome

Paul

#12 Casimo

Casimo

    Casio Overlord

  • Members
  • PipPipPipPipPipPipPip
  • 641 posts
  • Gender:Not Telling

Posted 09 March 2013 - 07:08 PM

And when you remove the "extern ..." line completely in globals.h?

#13 paul_brassington

paul_brassington

    Newbie

  • Members
  • Pip
  • 25 posts

  • Calculators:
    fx-9860g II SD

Posted 09 March 2013 - 07:21 PM

Same result I'm afraid. Any further suggestions very welcome as this has been me for the last 24 hours :banghead:

#14 3298

3298

    Casio Addict

  • Members
  • PipPipPip
  • 77 posts
  • Gender:Male
  • Location:Germany

  • Calculators:
    fx-9750G Plus
    Algebra FX 2.0 (ROM 1.03,broken)
    HP 50G

Posted 09 March 2013 - 08:00 PM

There could be something called "menus" in the libraries you include (I don't use the 9860 SDK, I don't even have a 9860). In that case, simply renaming the variable would help. But other than that, I have no clue. Also, when you remove the "extern" line completely, it isn't possible to use the variable in the other parts of your project.

#15 paul_brassington

paul_brassington

    Newbie

  • Members
  • Pip
  • 25 posts

  • Calculators:
    fx-9860g II SD

Posted 09 March 2013 - 08:32 PM

Thanks for all your help guys, now it does work as I used the rebuild all and it now does compile.

A million thanks to you all.

extern did solve the problem so thanks to 3298, :rolleyes:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users