cpdflibharu

C LibHaru reference to <functions> not defined


I need to use LibHaru in a project and I've downloaded and installed it, the configure and make worked fine. But now, when I try to use it in the code doesn't recognize the functions.

I'm trying in a Linux Mint distribution. The HPDF_Doc, Page and Font are recognized.

# 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);

The output is the error of reference to function not defined

Output :

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: referencia a `HPDF_New' sin definir

/home/opresor/Descargas/PracticaFinal/vuelos_client.c:514: referencia a `HPDF_Free' sin definir

/home/opresor/Descargas/PracticaFinal/vuelos_client.c:517: referencia a `HPDF_SetCompressionMode' sin definir

/home/opresor/Descargas/PracticaFinal/vuelos_client.c:518: referencia a `

etc..

collect2: error: ld returned 1 exit status

Makefile.vuelos:39: recipe for target 'vuelos_client' failed

make: *** [vuelos_client] Error 1


Solution

  • I'm not familiar with rpcgen, and I can't really say I understand completely what is going on here. But I would suggest you try adding -lhpdf to the line LDLIBS += -lnsl, so that it reads

    LDLIBS += -lnsl -lhpdf
    

    Giving a command line option of the form -llibrary to the compiler (at least for gcc and clang), tells the linker to search a certain set of directories for something like liblibrary.a or liblibrary.so (if this is a shared library) and to actually link your program with that. AFAICT, the library name for libharu is something like libhpdf.so, hence the suggestion to add that option to the variable LDLIBS.