各位C++链接报错,帮忙看下问题在那里,谢谢

lichujing 2017-06-15 03:16:32
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'

...全文
75 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ztenv 版主 2017-06-15
  • 打赏
  • 举报
回复
.cpp文件中要初始化静态成员变量; .h或.cpp文件中要有函数的实现;

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧