Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-18-2005, 08:19 PM   #1
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


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

// 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
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);
// end a1.h
#include <config.h>
#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
        CWBorderPixel | CWColormap | CWEventMask,
//end a1.cpp
Old 09-18-2005, 08:32 PM   #2
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 124Reputation: 124
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, 08:40 PM   #3
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, 09:43 PM   #4
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

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

Always happy to help.


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-12-2005 12:43 AM
Setting global system variables AzidStar Linux - Newbie 5 03-11-2005 10:03 AM
global variables in php champ Programming 2 10-13-2002 02:31 PM
exporting global variables neo77777 Programming 6 09-18-2002 02:46 PM
global environmental variables antadam Linux - General 2 10-11-2001 07:36 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:14 PM.

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