各位C++链接报错,帮忙看下问题在那里,谢谢
g++ -c screen.cpp没有报错。
screen.h文件
class screen{
public:
static int xres;
static int yres;
static int xres_virtual;
static int yres_virtual;
static unsigned int *mem;
static int fd;
static int init();
}
#include "screen.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include <sys/ioctl.h>
screen.cpp文件
int screen::init()
{
int ret = 0;
struct fb_var_screeninfo vinfo;
fd = open(DEVICE,O_RDWR);
if(screen::fd < 0)
{
printf("Open %s failed\n",DEVICE);
return -1;
}
if (ioctl(screen::fd,FBIOGET_VSCREENINFO,&vinfo)){
printf("Get device info failed\n");
return -2;
}
screen::xres = vinfo.xres;
screen::yres = vinfo.yres;
screen::xres_virtual = vinfo.xres_virtual;
screen::yres_virtual = vinfo.yres_virtual;
mem = (unsigned int *)mmap(NULL,xres*yres*4,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);;
return ret;
}
main.cpp文件
int main()
{
screen::init();
return 0;
}
g++ screen.cpp main.cpp报错如下:
/tmp/ccQxpgES.o: In function `screen::init()':
screen.cpp:(.text+0x28): undefined reference to `screen::fd'
screen.cpp:(.text+0x2e): undefined reference to `screen::fd'
screen.cpp:(.text+0x56): undefined reference to `screen::fd'
screen.cpp:(.text+0x94): undefined reference to `screen::xres'
screen.cpp:(.text+0xa0): undefined reference to `screen::yres'
screen.cpp:(.text+0xac): undefined reference to `screen::xres_virtual'
screen.cpp:(.text+0xb8): undefined reference to `screen::yres_virtual'
screen.cpp:(.text+0xbe): undefined reference to `screen::fd'
screen.cpp:(.text+0xc4): undefined reference to `screen::xres'
screen.cpp:(.text+0xca): undefined reference to `screen::yres'
screen.cpp:(.text+0xf9): undefined reference to `screen::mem'