LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-18-2005, 07:19 PM   #1
copolii
LQ Newbie
 
Registered: Feb 2005
Location: Richmond BC
Posts: 19

Rep: Reputation: 0
g++ complains about global variables


Hi Everybody,

I'm trying to write an OpenGL application in X Windows, but am having problems with g++. Currently the source tree is very simple, there are 2 files: a1.cpp and a1.h and as you have probably guessed already, a1.cpp starts with #include "a1.h"
I have declared a set of global variables at the beginning of a1.h that are SUPPOSED to be accessible from anywhere in the code .... but they arent!
any ideas on WHAT is causing this?
Output is the same from within KDevelop or just plain command line g++
I'd include the code, but it is about 250 lines and didnt wanna take up too much room unless it was necessary, so I've shortened it.
I appreciate any help with this as im a noob in both GL and X Programming :P

Cheers.

src/a1.cpp: In function 'bool initGLX(int&, __GLXcontextRec*&, XVisualInfo*)':
src/a1.cpp:52: error: 'glxQueryExtension' was not declared in this scope
src/a1.cpp:80: error: 'singleBufferVisual' was not declared in this scope
src/a1.cpp:88: error: 'g_bDoubleBufferred' was not declared in this scope
src/a1.cpp: In function 'void createGLWindow(Colormap&, XVisualInfo*, __GLXcontextRec*&, char**, int)':
src/a1.cpp:136: error: 'g_window' was not declared in this scope

FILES:
Code:
// a1.h
#ifndef _A1_H_
#define _A1_H_
#define MAX_WINDOW_WIDTH        800
#define MAX_WINDOW_HEIGHT       600
const char * APPTITLE = "GL1";
const char *  WINDOWTITLE = "GL TEST 1";
    // Error return values
#define AOK             0
#define NODISPLAY       -10
#define NOGLX           -11
#define NOVISUAL        -12
#define NORENDERCONTEXT -13
short BufferDepth = 24;
Display * g_pDisplay = NULL;            // global pointer to display object
Window g_Window;                        // global variable for window being used
bool g_bDoubleBuffered = true;          // application uses double buffering
int g_LastMousePosX = 0;                // Last mouse X and Y coordinates
int g_LastMousePosY = 0;
void initGL ();
void updateWorld ();
void showError (int code);
inline void showError (char * err);
bool initGLX(int & result, GLXContext & glxContext, XVisualInfo * visualInfo);
void createGLWindow (Colormap & colorMap, XVisualInfo * visualInfo, GLXContext & glxContext, char ** argv, int argc);
void ProcessEvent (XEvent & event);
#endif
// end a1.h
Code:
//a1.cpp
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "a1.h"
// line 52 inside function initGLX
if (!glxQueryExtension (g_pDisplay, &errorBase, &eventBase))
    {
        result = NOGLX;
        return false;
    }

// line 80 inside function initGLX
visualInfo = glXChooseVisual (g_pDisplay, DefaultScreen(g_pDisplay), singleBufferVisual);

// line 88 inside function initGLX
g_bDoubleBufferred = false;

// line 136inside function createGLWindow
g_window = XCreateWindow (  g_pDisplay, 
        RootWindow (g_pDisplay, visualInfo->screen),
        0, 0,                                       // top left of window
        MAX_WINDOW_WIDTH, MAX_WINDOW_HEIGHT,        // window dimensions
        0,                                          // border
        visualInfo->depth,                          // pixel depth
        InputOutput,
        visualInfo->visual,
        CWBorderPixel | CWColormap | CWEventMask,
        &windowAttributes);
//end a1.cpp
 
Old 09-18-2005, 07:32 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 116Reputation: 116
Well, in one case, you use g_window when you've declared g_Window. One instance of g_bDoubleBufferred has two rs, the other is g_bDoubleBuffered. Is glxQueryExtension from some other included header file? Ditto on singleBufferVisual. From your posted code, g++ is perfectly sane.
 
Old 09-18-2005, 07:40 PM   #3
copolii
LQ Newbie
 
Registered: Feb 2005
Location: Richmond BC
Posts: 19

Original Poster
Rep: Reputation: 0
problem solved :p

Oh for god's sake! You'd think after all these years of case-sensitive programming I've learnt to check my spelling before i start whining
Thanks alot
 
Old 09-18-2005, 08:43 PM   #4
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 116Reputation: 116
No problem. Sometimes it helps to have a second person take a look at the code.

Always happy to help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Local vs Global variables wujee Programming 1 03-11-2005 11:43 PM
Setting global system variables AzidStar Linux - Newbie 5 03-11-2005 09:03 AM
global variables in php champ Programming 2 10-13-2002 01:31 PM
exporting global variables neo77777 Programming 6 09-18-2002 01:46 PM
global environmental variables antadam Linux - General 2 10-11-2001 06:36 AM


All times are GMT -5. The time now is 05:40 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration