0

我需要在一个项目中使用 LibHaru,我已经下载并安装了它,配置和制作工作正常。但是现在,当我尝试在代码中使用它时无法识别这些功能。

我正在尝试使用 Linux Mint 发行版。HPDF_Doc、页面和字体被识别。

# This is a template Makefile generated by rpcgen

# Parameters

CLIENT = vuelos_client
SERVER = vuelos_server

SOURCES_CLNT.c = 
SOURCES_CLNT.h = 
SOURCES_SVC.c = 
SOURCES_SVC.h = 
SOURCES.x = vuelos.x

TARGETS_SVC.c = vuelos_svc.c vuelos_server.c vuelos_xdr.c 
TARGETS_CLNT.c = vuelos_clnt.c vuelos_client.c vuelos_xdr.c 
TARGETS = vuelos.h vuelos_xdr.c vuelos_clnt.c vuelos_svc.c vuelos_client.c vuelos_server.c

OBJECTS_CLNT = $(SOURCES_CLNT.c:%.c=%.o) $(TARGETS_CLNT.c:%.c=%.o)
OBJECTS_SVC = $(SOURCES_SVC.c:%.c=%.o) $(TARGETS_SVC.c:%.c=%.o)
# Compiler flags 

CFLAGS += -g 
LDLIBS += -lnsl
RPCGENFLAGS = 

# Targets 

all : $(CLIENT) $(SERVER)

$(TARGETS) : $(SOURCES.x) 
    rpcgen $(RPCGENFLAGS) $(SOURCES.x)

$(OBJECTS_CLNT) : $(SOURCES_CLNT.c) $(SOURCES_CLNT.h) $(TARGETS_CLNT.c) 

$(OBJECTS_SVC) : $(SOURCES_SVC.c) $(SOURCES_SVC.h) $(TARGETS_SVC.c) 

$(CLIENT) : $(OBJECTS_CLNT) 
    $(LINK.c) -o $(CLIENT) $(OBJECTS_CLNT) $(LDLIBS) 

$(SERVER) : $(OBJECTS_SVC) 
    $(LINK.c) -o $(SERVER) $(OBJECTS_SVC) $(LDLIBS)

 clean:
     $(RM) core $(TARGETS) $(OBJECTS_CLNT) $(OBJECTS_SVC) $(CLIENT) $(SERVER)
#include "hpdf.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <setjmp.h>
#include <math.h>
 
jmp_buf env;
 
#ifdef HPDF_DELL
void __stdcall
#else
void
#endif
 
error_handler (HPDF_STATUS error_no, HPDF_STATUS detail_no, void *user_data) {
    printf("ERROR: error_no=%04X, detail_no=%u\n", (HPDF_UINT)error_no, (HPDF_UINT)detail_no);
    longjmp(env, 1);
}
 
//tons of code
 
//Handle PDF
HPDF_Doc pdf;
HPDF_Page page;
HPDF_Font font;
float tw;
const char * titulo = "FACTURACION VUELO";
 
//tons of code
 
pdf = HPDF_New (error_handler, NULL);
if(!pdf){
    printf("Lo sentimos, ha habido un error, contacte con un administrador\n");
    break;
}
if(setjmp(env)){
        HPDF_Free (pdf);
        break;
}
HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL);
font = HPDF_GetFont (pdf, "Helvetica", NULL);
HPDF_SetPageMode (pdf, HPDF_PAGE_MODE_USE_OUTLINE);
page = HPDF_AddPage (pdf);
HPDF_Page_SetSize (page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);
HPDF_Page_SetFontAndSize (page, font, 24);
tw = HPDF_Page_TextWidth (page, titulo);
HPDF_Page_BeginText (page);
HPDF_Page_TextOut (page, (HPDF_Page_GetWidth(page) -tw) / 2, HPDF_Page_GetHeight(page) - 50, titulo);
HPDF_Page_EndText (page);
HPDF_Page_BeginText (page);
HPDF_Page_MoveTextPos (page, 60, HPDF_Page_GetHeight(page) -60);
HPDF_Free (pdf);

输出是对未定义函数的引用错误

输出 :

opresor@opresor:~/Descargas/PracticaFinal$ make -f Makefile.vuelos

vuelos_client.o: En la función `vuelos_1':

/home/opresor/Descargas/PracticaFinal/vuelos_client.c:508:参考“HPDF_New”罪定义

/home/opresor/Descargas/PracticaFinal/vuelos_client.c:514:参考“HPDF_Free”罪定义

/home/opresor/Descargas/PracticaFinal/vuelos_client.c:517:参考“HPDF_SetCompressionMode”罪定义

/home/opresor/Descargas/PracticaFinal/vuelos_client.c:518:参考一个`

ETC..

collect2:错误:ld 返回 1 个退出状态

Makefile.vuelos:39:目标“vuelos_client”的配方失败

make: *** [vuelos_client] 错误 1

4

1 回答 1

2

我不熟悉rpcgen,我不能说我完全理解这里发生了什么。但我建议您尝试添加-lhpdf到该行 LDLIBS += -lnsl,使其显示为

LDLIBS += -lnsl -lhpdf

为编译器提供形式的命令行选项-llibrary(至少对于gccand clang),告诉链接器在一组特定的目录中搜索类似liblibrary.aor liblibrary.so(如果这是一个共享库)并将您的程序与它实际链接。AFAICT,库名称libharu类似于libhpdf.so,因此建议将该选项添加到变量LDLIBS

于 2019-06-21T17:34:40.633 回答