LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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-08-2004, 07:30 PM   #1
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Rep: Reputation: 34
strange header problem


Hi,


I've got a strange header file problem, because of which i can not compile my program.

Look the concerned files looks like this:

the xkeylock..cpp file

Code:
#include "xkeylock.h"

extern "C"
{
  #include <X11/Xlib.h>
  #include <X11/keysym.h>
  #include <X11/extensions/XTest.h>       //PROBLEM IS HERE
}
      

XKeyLock::XKeyLock(Display *a_display, QObject *parent, const char *name) 
  : QObject(parent, name), numlock_mask(0), capslock_mask(0), scrolllock_mask(0)
{
  display = a_display;

  KeyCode keycode;

  keycode = XKeysymToKeycode(display, XK_Num_Lock);
  if (keycode != NoSymbol)
  {
    numlock_mask = getModifierMapping(keycode);
    if (numlock_mask == 0) numlock_mask = setModifierMapping(keycode);
  }
    
  keycode = XKeysymToKeycode(display, XK_Caps_Lock);
  if (keycode != NoSymbol)
  {
    capslock_mask = getModifierMapping(keycode);
    if (capslock_mask == 0) capslock_mask = setModifierMapping(keycode);
  }
   
  keycode = XKeysymToKeycode(display, XK_Scroll_Lock);
  if (keycode != NoSymbol)
  {
    scrolllock_mask = getModifierMapping(keycode);
    if (scrolllock_mask == 0) scrolllock_mask = setModifierMapping(keycode);
  }
}

XKeyLock::~XKeyLock()
{
}

unsigned int XKeyLock::getModifierMapping(KeyCode keycode)
{
  unsigned int mask = 0;
  
  XModifierKeymap* map = XGetModifierMapping(display);
  
  for(int i = 0 ; i < 8; ++i)
    if (map->modifiermap[map->max_keypermod * i] == keycode) 
      mask = 1 << i;
  
  XFreeModifiermap(map);
  return mask;
}

unsigned int XKeyLock::setModifierMapping(KeyCode keycode)
{
  unsigned int mask = 0;
  XModifierKeymap* map = XGetModifierMapping(display);
  
  for(int i = 0 ; i < 8; ++i)
    if (map->modifiermap[map->max_keypermod * i] == 0) 
    {
      map->modifiermap[map->max_keypermod * i] = keycode;
      XSetModifierMapping(display, map);
      mask = 1 << i;
      break;
    }      

  XFreeModifiermap(map);
  return mask;
}


bool XKeyLock::isNumLockReadable()
{
  return (numlock_mask != 0);
}

bool XKeyLock::isCapsLockReadable()
{
  return (capslock_mask != 0);
}

bool XKeyLock::isScrollLockReadable()
{
  return (scrolllock_mask != 0);
}


bool XKeyLock::getNumLock()
{
  if (!XKeyLock::isNumLockReadable()) 
    return false;
  else 
    return (bool) (getIndicatorStates() & numlock_mask);
}

bool XKeyLock::getCapsLock()
{
  if (!XKeyLock::isCapsLockReadable()) 
    return false;
  else
    return (bool) (getIndicatorStates() & capslock_mask);
}

bool XKeyLock::getScrollLock()
{
  if (!XKeyLock::isScrollLockReadable()) 
    return false;
  else
    return (bool) (getIndicatorStates() & scrolllock_mask);
}


void XKeyLock::toggleNumLock()
{
  XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Num_Lock), true, CurrentTime);
  XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Num_Lock), false, CurrentTime);
}

void XKeyLock::toggleCapsLock()
{
  XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Caps_Lock), true, CurrentTime);
  XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Caps_Lock), false, CurrentTime);
}

void XKeyLock::toggleScrollLock()
{
  XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Scroll_Lock), true, CurrentTime);
  XTestFakeKeyEvent(display, XKeysymToKeycode(display, XK_Scroll_Lock), false, CurrentTime);
}


void XKeyLock::setNumLock(bool state)
{
  if (numlock_mask !=0 && getNumLock() != state)
    toggleNumLock();
}

void XKeyLock::setCapsLock(bool state)
{
  if (capslock_mask !=0 && getCapsLock() != state)
    toggleCapsLock();
}

void XKeyLock::setScrollLock(bool state)
{
  if (scrolllock_mask !=0 && getScrollLock() != state)
    toggleScrollLock();
}

unsigned int XKeyLock::getIndicatorStates()
{
  Window dummy1, dummy2;
  int dummy3, dummy4, dummy5, dummy6;
  unsigned int indicatorStates;

  XQueryPointer(display, DefaultRootWindow(display), &dummy1, &dummy2,&dummy3, &dummy4, &dummy5, &dummy6, &indicatorStates);
	  
  return indicatorStates;
}

The problem is that when I compile I get this error:

Code:
g++ -Wl,-rpath,/usr/lib/qt/lib -o connectMonitor main.o xkeylock.o mainw.o moc_xkeylock.o moc_mainw.o   -L/usr/lib/qt/lib -L/usr/X11R6/lib -lqt-mt -lXext -lX11-lm
xkeylock.o(.text+0x547): In function `XKeyLock::toggleNumLock()':
: undefined reference to `XTestFakeKeyEvent'
xkeylock.o(.text+0x56a): In function `XKeyLock::toggleNumLock()':
: undefined reference to `XTestFakeKeyEvent'
xkeylock.o(.text+0x5a7): In function `XKeyLock::toggleCapsLock()':
: undefined reference to `XTestFakeKeyEvent'
xkeylock.o(.text+0x5ca): In function `XKeyLock::toggleCapsLock()':
: undefined reference to `XTestFakeKeyEvent'
xkeylock.o(.text+0x607): In function `XKeyLock::toggleScrollLock()':
: undefined reference to `XTestFakeKeyEvent'
xkeylock.o(.text+0x62a): more undefined references to `XTestFakeKeyEvent' follow
collect2: ld returned 1 exit status
make: *** [connectMonitor] Error 1
But as it turns out that `XTestFakeKeyEvent' is defined in X11/extensions/XTest.h, and this file is includede and the path is correct. So why is it acting as if I did not add the concerned header file?

Last edited by irfanhab; 09-08-2004 at 07:36 PM.
 
Old 09-08-2004, 08:01 PM   #2
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
ld is the linker; when it gives you "undefined reference" it means you forgot to link something, not that you forgot a header. Some grepping suggests the missing culprit is libXtst, whatever that is.
 
Old 09-08-2004, 08:01 PM   #3
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Can you post the lines that define XTestFakeKeyEvent in the header file? It's not inside an #ifdef that might evaluate false?
 
Old 09-08-2004, 08:03 PM   #4
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
oops, aluser is right, silly me - don't paste that definition
 
Old 09-09-2004, 12:22 AM   #5
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Original Poster
Rep: Reputation: 34
Quote:
ld is the linker; when it gives you "undefined reference" it means you forgot to link something, not that you forgot a header
I 'copied' this file from KeybLED program, to control Keyboard LEDS, well, I checked for any external references but found that it was totally self-contained, so I copied it to my project and started using it until this happened.

Now the linker thing is a bit curious, because I compiled KeybLED too, and that compiled without any problems
the xkeylock.moc.lo file, which is for the linker is the exact same KeybLED has, but only in mine it gives an error?
 
Old 09-09-2004, 09:05 AM   #6
Marius2
Member
 
Registered: Jan 2004
Location: Munich
Distribution: SuSE 9.2, 10.2, 10.3, knoppix
Posts: 276

Rep: Reputation: 31
Quote:
Originally posted by irfanhab
I 'copied' this file from KeybLED program, to control Keyboard LEDS, well, I checked for any external references but found that it was totally self-contained, so I copied it to my project and started using it until this happened.

Now the linker thing is a bit curious, because I compiled KeybLED too, and that compiled without any problems
the xkeylock.moc.lo file, which is for the linker is the exact same KeybLED has, but only in mine it gives an error?
I think aluser is right, error message meaning that you missed to link a library. You have a binary of KeybLED? You can
get it's dependencies with ldd (ldd <KeybLED binary>), it's one of the files dumped then that you should add to the list of
object files in your makefile.

HTH
 
Old 09-09-2004, 12:57 PM   #7
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
ooor you can just throw -lXtst at the end of your command line and see if that fixes it. lol
 
Old 09-09-2004, 10:11 PM   #8
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Original Poster
Rep: Reputation: 34
Quote:
ooor you can just throw -lXtst at the end of your command line and see if that fixes it. lol
What do you mean?
make -lXtst
 
Old 09-09-2004, 10:57 PM   #9
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Add it to your Makefile (there's usually a variable called LIBS or something similar - yours will have qt-mt, Xext, and X11-lm already in it)
 
Old 09-10-2004, 12:29 AM   #10
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Original Poster
Rep: Reputation: 34
Quote:
Add it to your Makefile (there's usually a variable called LIBS or something similar - yours will have qt-mt, Xext, and X11-lm already in it)
IT COMPILED IT!!!!!
The trick was that I had to add
-lXtst to the MakeFile under the LIBS tag

Thanx Everyone

Just one question to aluser:
How did you know I had to add -lXtst?
 
Old 09-10-2004, 01:02 AM   #11
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
I did a

grep -r XTestFakeKeyEvent /usr/X11R6/lib

Normally you'd check /usr/lib, but this looked like an X11 function.
 
Old 09-10-2004, 01:10 AM   #12
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Original Poster
Rep: Reputation: 34
Quote:
grep -r XTestFakeKeyEvent /usr/X11R6/lib
nice...
 
  


Reply



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
problem compiling c++ header in slack 10.1 tommyj27 Slackware 2 10-28-2005 05:10 PM
Problem with c header file alaios Programming 4 09-03-2005 09:06 PM
Problem with Delivered-To Header waremock Linux - Enterprise 1 11-08-2004 08:48 AM
strange, strange alsa problem: sound is grainy/pixellated? fenderman11111 Linux - Software 1 11-01-2004 05:16 PM
Problem with C++ include/header files! Pisces107 Programming 12 12-23-2003 11:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:47 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration