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 10-06-2006, 06:35 PM   #1
samel_tvom
Member
 
Registered: Aug 2004
Posts: 133

Rep: Reputation: 15
‘js_event’ undeclared, linux/joystick.h


Hi!

I have a small program that doesn't do much:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <linux/joystick.h>

int main() {
	int len;
	js_event msg;
	
	while(1) {
		read(f, &msg, sizeof(js_event));
		if (len == (int) sizeof(js_event)) {
			printf("wii\n");
		}
	}
	
	return 0;

}
I try compile with gcc test.c but I get
‘js_event’ undeclared (first use in this function)

What args should I have for gcc?

Thanks!
 
Old 10-09-2006, 12:11 PM   #2
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
You need to include the library on the compile line for gcc

heres an example that uses the math lib
Code:
 

#include<stdio.h> 
#include<stdlib.h> 
#include<math.h> 

int main() 
{ 
  .....some code that uses math.h 
}

to compile use

Code:
 
user@linux# gcc -o test test.c -lm
Hope this helps
 
Old 10-09-2006, 03:08 PM   #3
samel_tvom
Member
 
Registered: Aug 2004
Posts: 133

Original Poster
Rep: Reputation: 15
Thanks for the reply!

Actually, I just missed to type "struct" before "js_event", that solved it all.
I didn't have to pass anything to gcc since linux/joystick.h lives at
/usr/include, and gcc always looks there,
so
Code:
gcc testjoystick.c
Now the code looks like

Code:
// for printf
#include <stdio.h>
// for usleep
#include <unistd.h>
// for open()
#include <fcntl.h>   
// for js_event
#include <linux/joystick.h>

int main() {
	struct js_event msg;
	char* device = "/dev/input/js0";
	
	int fd = open(device, O_RDONLY);
	
	while(1) {
		if(read(fd, &msg, sizeof(struct js_event)) != sizeof(struct js_event)) {
			printf("Error when reading from joystick\n");
			exit(1);
		} else {
			printf("wee\n");
			if(msg.type == JS_EVENT_BUTTON) 
				printf("button press\n");
			if(msg.type == JS_EVENT_AXIS)
				printf("axis pressed\n");	
			usleep(10000);
		}
	}
	
	return 0;
}
As you can see when you run the program, "wee" is printed many times even though
you don't press any keys, that's probably some info stuff or something.

Well, now I know what I need to. Thanks!
 
  


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
undeclared here (not in a function) ashlesha Linux - Software 2 08-23-2006 11:29 PM
Joystick Driver and API under kernel 2.6.12.3 using an USB joystick dispatcher Linux - Newbie 1 08-06-2005 09:43 AM
Linux-friendly joystick? BroX Linux - Games 4 07-01-2005 05:28 PM
The Linux/Joystick myth storyteller Linux - Hardware 7 01-03-2004 06:20 PM
joystick in linux? lpriyamb Linux - Software 2 10-09-2003 03:27 AM

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

All times are GMT -5. The time now is 10:45 AM.

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