读书人

cups 编程出现 undefined reference解

发布时间: 2013-10-01 12:15:56 作者: rapoo

cups 编程出现 undefined reference
//函数测试小程序 test.cpp

#include<iostream>
#include<cups/cups.h>
using namespace std;
int main()
{
cups_dest_t *dests;
int num_dests =cupsGetDests(&dests);
cups_dest_t *dest = cupsGetDest("name",NULL,num_dests,dests);
cout<<"the name is :"<<dest->name<<endl;
cout<<"the options is"<<dest->num_options<<endl;
cupsFreeDests(num_dests,dests);
return 0;
}
编译平台:ubutnu10.04 g++
编译命令: g++ test.cpp

cups版本:1.4

//编译结果:
/tmp/ccrur3CY.o: In function `main':
1.cpp:(.text+0x12): undefined reference to `cupsGetDests'
1.cpp:(.text+0x3a): undefined reference to `cupsGetDest'
1.cpp:(.text+0xbf): undefined reference to `cupsFreeDests'
collect2: ld returned 1 exit status
orchard@ubuntu:~/cups$

问题:
出现上述的几个函数 undefined ,已经包含正确的头文件,而且可以确定这几个函数是正确的。但是仍然出错,ps这个小程序是从cups官网copy下来的,请指教为何出现这种错误 ,是真的没有写对头文件还是编译命令不行,谢谢。 cups?? undefined?reference
[解决办法]
需要链接cups库文件,参考http://www.cups.org/documentation.php/doc-1.4/api-overview.html

引用:
//函数测试小程序 test.cpp

#include<iostream>
#include<cups/cups.h>
using namespace std;
int main()
{
cups_dest_t *dests;
int num_dests =cupsGetDests(&dests);
cups_dest_t *dest = cupsGetDest("name",NULL,num_dests,dests);
cout<<"the name is :"<<dest->name<<endl;
cout<<"the options is"<<dest->num_options<<endl;
cupsFreeDests(num_dests,dests);
return 0;
}
编译平台:ubutnu10.04 g++
编译命令: g++ test.cpp

cups版本:1.4

//编译结果:
/tmp/ccrur3CY.o: In function `main':
1.cpp:(.text+0x12): undefined reference to `cupsGetDests'
1.cpp:(.text+0x3a): undefined reference to `cupsGetDest'
1.cpp:(.text+0xbf): undefined reference to `cupsFreeDests'
collect2: ld returned 1 exit status
orchard@ubuntu:~/cups$

问题:
出现上述的几个函数 undefined ,已经包含正确的头文件,而且可以确定这几个函数是正确的。但是仍然出错,ps这个小程序是从cups官网copy下来的,请指教为何出现这种错误 ,是真的没有写对头文件还是编译命令不行,谢谢。

读书人网 >C++

热点推荐