我需要在一个项目中使用LibHaru,我已经下载并安装了它,配置和调试正常。但是现在,当我尝试在代码中使用它时,无法识别功能。
我正在尝试在Linux Mint发行版中。可以识别HPDF_Doc,Page和Font。
# 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:有趣的`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:Referencia a`
等等。
collect2:错误:ld返回1个退出状态
Makefile.vuelos:39:目标'vuelos_client'的配方失败
make:*** [vuelos_client]错误1
答案 0 :(得分:2)
我对rpcgen
不熟悉,我不能说我完全理解这里发生的事情。但我建议您尝试将-lhpdf
添加到该行
LDLIBS += -lnsl
,使其显示为
LDLIBS += -lnsl -lhpdf
以-llibrary
形式的命令行选项提供给编译器(至少适用于gcc
和clang
),它告诉链接器在某些目录集中搜索诸如{ {1}}或liblibrary.a
(如果这是一个共享库),并使用它实际链接程序。 AFAICT,liblibrary.so
的库名类似于libharu
,因此建议将该选项添加到变量libhpdf.so
中。