CUPS打印文件分割错误

CUPS打印文件分割错误,c,segmentation-fault,cups,C,Segmentation Fault,Cups,我正在尝试制作一个CUPS打印系统。我想获得打印机状态、目前打印的页面数等信息 为此,我正在执行CUPS示例中给出的示例程序 #include <cups/cups.h> #include <stdio.h> int main(){ int num_options; cups_option_t *options; cups_dest_t *dests; int num_dests = cupsGetDests(&dests); cups_dest_t *d

我正在尝试制作一个CUPS打印系统。我想获得打印机状态、目前打印的页面数等信息

为此,我正在执行CUPS示例中给出的示例程序

#include <cups/cups.h>
#include <stdio.h>


int main(){

int num_options;
cups_option_t *options;

cups_dest_t *dests;
int num_dests = cupsGetDests(&dests);
cups_dest_t *dest = cupsGetDest("name", NULL, num_dests, dests);
int job_id;

/* Print a single file */
job_id = cupsPrintFile(dest->name, "testfile.txt", "Test Print", num_options, options);

cupsFreeDests(num_dests, dests);

return 0;
}
#包括
#包括
int main(){
int num_选项;
cups_选项_t*选项;
杯子的目的地;
int num_dests=杯形集合(&dests);
cups\u dest\u t*dest=cupsGetDest(“名称”,NULL,num\u dests,dests);
int job_id;
/*打印单个文件*/
作业id=cupsPrintFile(dest->name,“testfile.txt”,“测试打印”,num\u选项,选项);
杯底(杯底、杯底);
返回0;
}
我使用gcc myfile.c-o myout-lcups编译它

当我尝试执行
/myout

我越来越

分段故障

我使用树莓皮3板作为我的CUPS服务器


提前感谢。

dest
指向无效地址

cups_dest_t *dest; // declared but not initialized or assigned afterwards 
因此,取消对它的引用(
cupsPrintFile(dest->name
…)是UB,可能会导致SegFault


这是您应该如何使用它(摘自):


dest
指向无效地址

cups_dest_t *dest; // declared but not initialized or assigned afterwards 
因此,取消对它的引用(
cupsPrintFile(dest->name
…)是UB,可能会导致SegFault


这是您应该如何使用它(摘自):


gdb是否存在于您的开发环境中?@lockcmpxchg8b是。如果您知道如何运行它,它将在SIGSEGV处中断,
where
命令将给出一个堆栈跟踪,说明它在segv时执行的位置。如果您在调试模式下编译,效果会更好。gdb是否存在于您的开发环境中?@lockcmpxchg8b是。如果您知道如何运行it、 它将在SIGSEGV处中断,
where
命令将提供一个堆栈跟踪,以跟踪它在segv时执行的位置。如果在调试模式下编译,效果会更好。确实如此。但它们不会从提供的代码段OP中删除(仅[可能]在函数内部).我提到的UB发生在函数启动之前invoked@CIsForCookies问题已用最新代码更新。@CIsForCookies那么如何解决这个
cups\u option\u t*options;
初始化问题呢?请仔细阅读我提供的链接。它以精细的方式展示了整个APIexamples@CIsForCookies这就是我过去两天一直在做的。这仍然是
分段错误
错误问题。确实如此。但它们与提供的代码段OP无关(仅[可能]在函数内部).我提到的UB发生在函数启动之前invoked@CIsForCookies问题已用最新代码更新。@CIsForCookies那么如何解决这个
cups\u option\u t*options;
初始化问题呢?请仔细阅读我提供的链接。它以精细的方式展示了整个APIexamples@CIsForCookies这就是我过去两天一直在做的。仍然存在此
分段错误
错误问题。
int main(){

int num_options;
cups_option_t *options; // add a call to "cupsAddOption("first", "value", num_options, &options);"

cups_dest_t *dests;
int num_dests = cupsGetDests(&dests);
cups_dest_t *dest = cupsGetDest("name", NULL, num_dests, dests);
int job_id;

/* Print a single file */
job_id = cupsPrintFile(dest->name, "testfile.txt", "Test Print", num_options, options); // options is used here but is uninitialized

cupsFreeDests(num_dests, dests);

return 0;
}