运行C/C时出错++;使用gcc或g++;关于DebianLinux

运行C/C时出错++;使用gcc或g++;关于DebianLinux,c,linux,gcc,C,Linux,Gcc,我两天前开始使用DebianLinux。 安装gcc、g++编译器后, 我想使用命令(gcc file.C)运行C代码,但在终端中发现了一个奇怪的错误 /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: error: ld returned 1 exit stat

我两天前开始使用DebianLinux。 安装gcc、g++编译器后, 我想使用命令(gcc file.C)运行C代码,但在终端中发现了一个奇怪的错误

/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
操纵杆
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括“操纵杆.h”
静态int_fd=-1;
/*这些在罗技双动隆隆和xbox360控制器上都是合理的*/
静态int操纵杆_x_轴=0;
静态int操纵杆_y_轴=1;
int打开操纵杆(字符*操纵杆装置)
{
如果(操纵杆装置==NULL)
操纵杆设备=操纵杆设备名称;
操纵杆fd=打开(操纵杆装置,O|RDONLY | O|UNBLOCK);/*读写力反馈*/
如果(操纵杆摩擦系数<0)
返回操纵杆(fd);
/*也许可以在这里询问特征*/
返回操纵杆(fd);
}
int读取事件(结构js事件*jse)
{
整数字节;
字节=读取(操纵杆fd、jse、sizeof(*jse));
如果(字节==-1)
返回0;
if(字节==sizeof(*jse))
返回1;
printf(“来自操纵杆的意外字节:%d\n”,字节);
返回-1;
}
无效关闭操作手柄()
{
关闭(操纵杆_fd);
}
int get_操纵杆_状态(结构wwvi_js_事件*wjse)
{
int rc;
结构js_事件jse;
如果(操纵杆摩擦系数<0)
返回-1;
/*memset(wjse,0,sizeof(*wjse))*/
while((rc=读取操纵杆事件(&jse)==1)){
jse.type&=~JS_EVENT_INIT;/*忽略合成事件*/
if(jse.type==JS_事件_轴){
如果(jse.number==操纵杆x轴)
wjse->stick_x=jse.value;
if(jse.number==操纵杆y轴)
wjse->stick_y=jse.value;
}else if(jse.type==JS_事件_按钮){
如果(jse编号<11){
开关(jse.value){
案例0:
案例一:wjse->按钮[jse.number]=jse.value;
打破
违约:
打破
}
}
}
}
/*printf(“%d\n”,wjse->stick1_y)*/
返回0;
}
无效集\操纵杆\ y \轴(int轴)
{
操纵杆y轴=轴;
}
无效设置\u操纵杆\u x\u轴(int轴)
{
操纵杆x轴=轴;
}
#如果0
/*一个小测试程序*/
int main(int argc,char*argv[])
{
int-fd,rc;
int done=0;
结构js_事件jse;
fd=打开操纵杆();
如果(fd<0){
printf(“打开失败。\n”);
出口(1);
}
而(!完成){
rc=读取操纵杆事件(&jse);
usleep(1000);
如果(rc==1){
printf(“事件:时间%8u,值%8hd,类型:%3u,轴/按钮:%u\n”,
jse.time、jse.value、jse.type、jse.number);
}
}
}
操纵杆
#包括
#如果没有__
#定义操纵杆__
#定义操纵杆名称“/dev/input/js0”
#定义JS_事件_按钮0x01/*按钮按下/释放*/
#定义JS_事件_轴0x02/*操纵杆已移动*/
#定义设备的JS_事件_INIT 0x80/*初始状态*/
结构js_事件{
未签名的int-time;/*事件时间戳(毫秒)*/
短值;/*值*/
无符号字符类型;/*事件类型*/
无符号字符号;/*轴/按钮号*/
};
结构wwvi_js_事件{
int按钮[11];
int stick_x;
内部粘滞;
};
外部内部开启操纵杆(字符*操纵杆装置);
外部内部读取事件(结构js事件*jse);
外部无效设置轴(内部轴);
外部无效设置x轴(内部轴);
外部无效关闭_操纵杆();
外部获取操纵杆状态(结构wwvi_js_事件*wjse);
#恩迪夫
#恩迪夫

存在
#if 0
main
排除在编译之外。如果为1,则将其更改为
。由于您没有相应的
#endif
,因此可以将该行全部删除。

非常感谢。。。。。。这真是一个严重的错误:D
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

#include "joystick.h"

static int joystick_fd = -1;

/* These are sensible on Logitech Dual Action Rumble and xbox360 controller. */
static int joystick_x_axis = 0;
static int joystick_y_axis = 1;

int open_joystick(char *joystick_device)
{
    if (joystick_device == NULL)
        joystick_device = JOYSTICK_DEVNAME;
    joystick_fd = open(joystick_device, O_RDONLY | O_NONBLOCK); /* read write for force feedback? */
    if (joystick_fd < 0)
        return joystick_fd;

    /* maybe ioctls to interrogate features here? */

    return joystick_fd;
}

int read_joystick_event(struct js_event *jse)
{
    int bytes;

    bytes = read(joystick_fd, jse, sizeof(*jse));

    if (bytes == -1)
        return 0;

    if (bytes == sizeof(*jse))
        return 1;

    printf("Unexpected bytes from joystick:%d\n", bytes);

    return -1;
}

void close_joystick()
{
    close(joystick_fd);
}

int get_joystick_status(struct wwvi_js_event *wjse)
{
    int rc;
    struct js_event jse;
    if (joystick_fd < 0)
        return -1;

    /* memset(wjse, 0, sizeof(*wjse)); */
    while ((rc = read_joystick_event(&jse) == 1)) {
        jse.type &= ~JS_EVENT_INIT; /* ignore synthetic events */
        if (jse.type == JS_EVENT_AXIS) {
            if (jse.number == joystick_x_axis)
                wjse->stick_x = jse.value;
            if (jse.number == joystick_y_axis)
                wjse->stick_y = jse.value;
        } else if (jse.type == JS_EVENT_BUTTON) {
            if (jse.number < 11) {
                switch (jse.value) {
                case 0:
                case 1: wjse->button[jse.number] = jse.value;
                    break;
                default:
                    break;
                }
            }
        }
    }
    /* printf("%d\n", wjse->stick1_y); */
    return 0;
}

void set_joystick_y_axis(int axis)
{
    joystick_y_axis = axis;
}

void set_joystick_x_axis(int axis)
{
    joystick_x_axis = axis;
}


#if 0
/* a little test program */
int main(int argc, char *argv[])
{
    int fd, rc;
    int done = 0;

    struct js_event jse;

    fd = open_joystick();
    if (fd < 0) {
        printf("open failed.\n");
        exit(1);
    }

    while (!done) {
        rc = read_joystick_event(&jse);
        usleep(1000);
        if (rc == 1) {
            printf("Event: time %8u, value %8hd, type: %3u, axis/button: %u\n",
                jse.time, jse.value, jse.type, jse.number);
        }
    }
}
#include <stdio.h>
#ifndef __JOYSTICK_H__
#define __JOYSTICK_H__

#define JOYSTICK_DEVNAME "/dev/input/js0"

#define JS_EVENT_BUTTON         0x01    /* button pressed/released */
#define JS_EVENT_AXIS           0x02    /* joystick moved */
#define JS_EVENT_INIT           0x80    /* initial state of device */


struct js_event {
    unsigned int time;  /* event timestamp in milliseconds */
    short value;   /* value */
    unsigned char type;     /* event type */
    unsigned char number;   /* axis/button number */
};

struct wwvi_js_event {
    int button[11];
    int stick_x;
    int stick_y;
};

extern int open_joystick(char *joystick_device);
extern int read_joystick_event(struct js_event *jse);
extern void set_joystick_y_axis(int axis);
extern void set_joystick_x_axis(int axis);
extern void close_joystick();
extern int get_joystick_status(struct wwvi_js_event *wjse);

#endif

#endif