jung-kurt / luahpdf

LuaHPDF is a module that lets you programmatically create PDF files using Lua.
23 stars 10 forks source link

MacOSX install #8

Open arnodick opened 6 years ago

arnodick commented 6 years ago

Hi Kurt,

This is a bit of a longshot, but is there any chance you have some advice for building luahpdf on MacOSX?

I'm getting this error: hpdf.c:257:4 error: use of undeclared identifier 'HPDF_ARRAY_COUNT_ERR' Plus a bunch more errors that follow the same pattern, saying there are undeclared identifiers.

I've tried changing the Makefile in a variety of ways, but nothing is working. I've managed to get luahpdf installed on a linux machine, but for some reason can't get it working on OSX at all.

Thanks for your time

jung-kurt commented 6 years ago

I'll look into this when I have access to a Mac, possibly tomorrow.

How did you install your version of the HPDF library? Direct from source, homebrew, or some other means? What version os OSX are you running?

arnodick commented 6 years ago

Thanks for the response, Kurt.

I tried installing HPDF from source but had issues, so I ended up using homebrew. Running OSX 10.12.6

This was my best stab at modifying the Makefile:

PREFIX ?= /usr/local MODDIR ?= $(PREFIX)/bin/lua-5.3.4 LUALIB ?= -liblua HPDFLIB ?= -libhpdf LUA ?= lua LUAC ?= luac PLATFORM=macosx

arnodick commented 6 years ago

Oh and I forgot to mention it's libharu version 2.3.0

jung-kurt commented 6 years ago

I tried installing HPDF from source but had issues, so I ended up using homebrew.

Whew! These fussy build scripts make me realize why I like go so much. lua builds easily as do libpng and zlib, but the libharu build is one frustration after another. And I'm having trouble getting the antiquated homebrew installation on the Mac I borrowed to update properly. I'll chip away a bit more on this and will report back.

jung-kurt commented 6 years ago

I am unable to install homebrew on the Mac (version 10.7.5 from 2012) to which I have access, and I can't get past the configuration step when trying to build libharu from source.

hpdf.c:257:4 error: use of undeclared identifier 'HPDF_ARRAY_COUNT_ERR'

This looks to me like the compiler is unable to find the libhpdf header files. You can use the HPDFINC setting in the luahpdf Makefile to set the location. I think homebrew puts its file into the /usr/local tree. Try something like find /usr/local -name "*hpdf*h" to pinpoint the directory to specify.

arnodick commented 6 years ago

Thanks for the response, Kurt!

I'll try these suggestions out as soon as I get a chance and let you now how it goes.

arnodick commented 6 years ago

Hi Kurt,

I ended up not having to use luahpdf on my mac, but I'm now very close to having it working on my web host. It's a freeBSD system, and with some messing around with the Makefile I was able to get luahpdf to make and install.

Unfortunately, when I runt the test command lua52 -l hpdf -e "print(hpdf.VERSION_TEXT)"

I get this error

lua52: error loading module 'hpdf' from file './hpdf.so': Undefined symbol "luaopen_hpdf" stack traceback: [C]: in ? [C]: in function '_G.require' [C]: in ?

I think this may have something to do with luahpdf requiring haru to be a shared library, but I'm not sure. Thought I'd ask and see if you had any insight.

Thanks!

jung-kurt commented 6 years ago

Hi @arnodick,

I ended up not having to use luahpdf on my mac

I'd still like to get it working on Macs, but I'll definitely need to get access to a newer one before I can proceed. libhpdf seems to build a lot more easily on Linux and BSD.

I think this may have something to do with luahpdf requiring haru to be a shared library, but I'm not sure.

Yes, the ".so" indicates a shared object. After make completes, do you have a file called hpdf.so in the same directory as the Makefile? If so, what do you get when you run ldd ./hpdf.so? If not, does make report errors during the build?

arnodick commented 6 years ago

Yup, hpdf.so is in the directory after make and install. No errors, but I do get a warning:

cc: warning: argument unused during compilation: '-shared' [-Wunused-command-line-argument]

The output of ldd ./hpdf.so is:

./hpdf.so: libhpdf.so => /usr/local/lib/libhpdf.so (0x21201000) libz.so.6 => /lib/libz.so.6 (0x214bf000) libpng16.so.16 => /usr/local/lib/libpng16.so.16 (0x216d8000) libm.so.5 => /lib/libm.so.5 (0x21910000) libc.so.7 => /lib/libc.so.7 (0x20824000)

jung-kurt commented 6 years ago

Good. Instead of

lua52 -l hpdf -e "print(hpdf.VERSION_TEXT)"

try

lua52 -e "package.path=[[]] package.cpath=[[./?.so]] local hpdf = require [[hpdf]] print(hpdf.VERSION_TEXT)"

This will make sure that Lua looks for your hpdf.so in the current directory.

If that works, then the problem with the first command is likely something to do with Lua finding the module where it was installed.

arnodick commented 6 years ago

Hi Kurt,

I tried the modified command but it resulted in the same error.

I did find this which seems to mention a very similar problem: https://github.com/jung-kurt/luahpdf/issues/4

It mentions a pull request but I'm not which one they're referring to. https://github.com/jung-kurt/luahpdf/issues/4#issuecomment-113042140

jung-kurt commented 6 years ago

That pull request was already merged into the repository, so you're making use of it.

Let's take a look at what the exports in the module you compiled. On Linux, the command is

nm -g ./hpdf.so

If that doesn't work on FreeBSD, try man nm to read up on what switches apply. On my system (Debian Linux) the output includes

                 U luaL_error
                 U luaL_optlstring
                 U luaL_setfuncs
000000000000ec90 T luaopen_hpdf
                 U lua_pushboolean
                 U lua_pushfstring
                 U lua_pushinteger

We're specifically looking for that luaopen_hpdf.

arnodick commented 6 years ago

Ah, I'm getting very different results.

                  w _Jv_RegisterClasses
00000000002006f9 A __bss_start
                  w __cxa_finalize@@FBSD_1.0
00000000002006f9 A _edata
0000000000200700 A _end
00000000000004a8 T _fini
00000000000003a0 T _init

The nm command for freeBSD seems to be the same as Debian. -g writes only global symbols.

jung-kurt commented 6 years ago

Do you get the same results with nm -g hpdf.o?

I just looked at the FreeBSD target in the Lua makefile as well as the makefiles in some other Lua modules on GitHub that build on FreeBSD. I have not found any flags that look out of place in luahpdf's makefile.

I suggest starting as simply as possible and adding flags as needed, checking the generated object file (hpdf.o) each time with nm -g ./hpdf.o. For example,

cc -I/usr/include/lua5.2 -c -o hpdf.o hpdf.c
nm -g ./hpdf.o

Incrementally add the compiler flags -shared, -fPIC, etc from Makefile.

arnodick commented 6 years ago

Ah, I used a much simplified compile command cc -I/usr/local/include/lua52 -I/usr/local/include -c -o hpdf.o hpdf.c

The results were promising!

00000000000001b0 D CnAnnotHighlightMode
00000000000001e0 D CnAnnotIcon
0000000000000320 D CnBlendMode
0000000000000160 D CnByteType
0000000000000230 D CnColorSpace
0000000000000130 D CnEncoderType
00000000000002f0 D CnEncryptMode
0000000000000000 R CnErrorMessages
00000000000002a0 D CnInfoType
0000000000000390 D CnLineCap
00000000000003c0 D CnLineJoin
00000000000000d0 D CnPageDirection
0000000000000000 D CnPageLayout
0000000000000030 D CnPageMode
00000000000000f0 D CnPageNumStyle
0000000000000060 D CnPageSizes
0000000000000440 D CnTextAlignment
00000000000003f0 D CnTextRenderingMode
0000000000000470 D CnTransitionStyle
0000000000000190 D CnWritingMode
                 U HPDF_AddPage
                 U HPDF_AddPageLabel
                 U HPDF_CreateExtGState
                 U HPDF_CreateOutline
                 U HPDF_Destination_SetFit
                 U HPDF_Destination_SetFitB
                 U HPDF_Destination_SetFitBH
                 U HPDF_Destination_SetFitBV
                 U HPDF_Destination_SetFitH
                 U HPDF_Destination_SetFitR
                 U HPDF_Destination_SetFitV
                 U HPDF_Destination_SetXYZ
                 U HPDF_Encoder_GetByteType
                 U HPDF_Encoder_GetType
                 U HPDF_Encoder_GetUnicode
                 U HPDF_Encoder_GetWritingMode
                 U HPDF_ExtGState_SetAlphaFill
                 U HPDF_ExtGState_SetAlphaStroke
                 U HPDF_ExtGState_SetBlendMode
                 U HPDF_Font_GetAscent
                 U HPDF_Font_GetBBox
                 U HPDF_Font_GetCapHeight
                 U HPDF_Font_GetDescent
                 U HPDF_Font_GetEncodingName
                 U HPDF_Font_GetFontName
                 U HPDF_Font_GetUnicodeWidth
                 U HPDF_Font_GetXHeight
                 U HPDF_Font_MeasureText
                 U HPDF_Font_TextWidth
                 U HPDF_Free
                 U HPDF_FreeDoc
                 U HPDF_FreeDocAll
                 U HPDF_GetCurrentEncoder
                 U HPDF_GetCurrentPage
                 U HPDF_GetEncoder
                 U HPDF_GetError
                 U HPDF_GetErrorDetail
                 U HPDF_GetFont
                 U HPDF_GetInfoAttr
                 U HPDF_GetPageByIndex
                 U HPDF_GetPageLayout
                 U HPDF_GetPageMode
                 U HPDF_GetStreamSize
                 U HPDF_GetVersion
                 U HPDF_GetViewerPreference
                 U HPDF_HasDoc
                 U HPDF_Image_GetBitsPerComponent
                 U HPDF_Image_GetColorSpace
                 U HPDF_Image_GetHeight
                 U HPDF_Image_GetSize
                 U HPDF_Image_GetSize2
                 U HPDF_Image_GetWidth
                 U HPDF_Image_SetColorMask
                 U HPDF_Image_SetMaskImage
                 U HPDF_InsertPage
                 U HPDF_LinkAnnot_SetBorderStyle
                 U HPDF_LinkAnnot_SetHighlightMode
                 U HPDF_LoadJpegImageFromFile
                 U HPDF_LoadPngImageFromFile
                 U HPDF_LoadPngImageFromFile2
                 U HPDF_LoadRawImageFromFile
                 U HPDF_LoadRawImageFromMem
                 U HPDF_LoadTTFontFromFile
                 U HPDF_LoadTTFontFromFile2
                 U HPDF_LoadType1FontFromFile
                 U HPDF_New
                 U HPDF_NewDoc
                 U HPDF_Outline_SetDestination
                 U HPDF_Outline_SetOpened
                 U HPDF_Page_Arc
                 U HPDF_Page_BeginText
                 U HPDF_Page_Circle
                 U HPDF_Page_Clip
                 U HPDF_Page_ClosePath
                 U HPDF_Page_ClosePathEofillStroke
                 U HPDF_Page_ClosePathFillStroke
                 U HPDF_Page_ClosePathStroke
                 U HPDF_Page_Concat
                 U HPDF_Page_CreateDestination
                 U HPDF_Page_CreateLinkAnnot
                 U HPDF_Page_CreateTextAnnot
                 U HPDF_Page_CreateURILinkAnnot
                 U HPDF_Page_CurveTo
                 U HPDF_Page_CurveTo2
                 U HPDF_Page_CurveTo3
                 U HPDF_Page_DrawImage
                 U HPDF_Page_Ellipse
                 U HPDF_Page_EndPath
                 U HPDF_Page_EndText
                 U HPDF_Page_Eoclip
                 U HPDF_Page_Eofill
                 U HPDF_Page_EofillStroke
                 U HPDF_Page_ExecuteXObject
                 U HPDF_Page_Fill
                 U HPDF_Page_FillStroke
                 U HPDF_Page_GRestore
                 U HPDF_Page_GSave
                 U HPDF_Page_GetCMYKFill
                 U HPDF_Page_GetCMYKStroke
                 U HPDF_Page_GetCharSpace
                 U HPDF_Page_GetCurrentFont
                 U HPDF_Page_GetCurrentFontSize
                 U HPDF_Page_GetCurrentPos
                 U HPDF_Page_GetCurrentPos2
                 U HPDF_Page_GetCurrentTextPos
                 U HPDF_Page_GetCurrentTextPos2
                 U HPDF_Page_GetDash
                 U HPDF_Page_GetFillingColorSpace
                 U HPDF_Page_GetFlat
                 U HPDF_Page_GetGMode
                 U HPDF_Page_GetGStateDepth
                 U HPDF_Page_GetGrayFill
                 U HPDF_Page_GetGrayStroke
                 U HPDF_Page_GetHeight
                 U HPDF_Page_GetHorizontalScalling
                 U HPDF_Page_GetLineCap
                 U HPDF_Page_GetLineJoin
                 U HPDF_Page_GetLineWidth
                 U HPDF_Page_GetMiterLimit
                 U HPDF_Page_GetRGBFill
                 U HPDF_Page_GetRGBStroke
                 U HPDF_Page_GetStrokingColorSpace
                 U HPDF_Page_GetTextLeading
                 U HPDF_Page_GetTextMatrix
                 U HPDF_Page_GetTextRaise
                 U HPDF_Page_GetTextRenderingMode
                 U HPDF_Page_GetTextRise
                 U HPDF_Page_GetTransMatrix
                 U HPDF_Page_GetWidth
                 U HPDF_Page_GetWordSpace
                 U HPDF_Page_LineTo
                 U HPDF_Page_MeasureText
                 U HPDF_Page_MoveTextPos
                 U HPDF_Page_MoveTextPos2
                 U HPDF_Page_MoveTo
                 U HPDF_Page_MoveToNextLine
                 U HPDF_Page_Rectangle
                 U HPDF_Page_SetCMYKFill
                 U HPDF_Page_SetCMYKStroke
                 U HPDF_Page_SetCharSpace
                 U HPDF_Page_SetDash
                 U HPDF_Page_SetExtGState
                 U HPDF_Page_SetFlat
                 U HPDF_Page_SetFontAndSize
                 U HPDF_Page_SetGrayFill
                 U HPDF_Page_SetGrayStroke
                 U HPDF_Page_SetHeight
                 U HPDF_Page_SetHorizontalScalling
                 U HPDF_Page_SetLineCap
                 U HPDF_Page_SetLineJoin
                 U HPDF_Page_SetLineWidth
                 U HPDF_Page_SetMiterLimit
                 U HPDF_Page_SetRGBFill
                 U HPDF_Page_SetRGBStroke
                 U HPDF_Page_SetRotate
                 U HPDF_Page_SetSize
                 U HPDF_Page_SetSlideShow
                 U HPDF_Page_SetTextLeading
                 U HPDF_Page_SetTextMatrix
                 U HPDF_Page_SetTextRaise
                 U HPDF_Page_SetTextRenderingMode
                 U HPDF_Page_SetTextRise
                 U HPDF_Page_SetWidth
                 U HPDF_Page_SetWordSpace
                 U HPDF_Page_ShowText
                 U HPDF_Page_ShowTextNextLine
                 U HPDF_Page_ShowTextNextLineEx
                 U HPDF_Page_Stroke
                 U HPDF_Page_TextOut
                 U HPDF_Page_TextRect
                 U HPDF_Page_TextWidth
                 U HPDF_ResetError
                 U HPDF_ResetStream
                 U HPDF_SaveToFile
                 U HPDF_SaveToStream
                 U HPDF_SetCompressionMode
                 U HPDF_SetCurrentEncoder
                 U HPDF_SetEncryptionMode
                 U HPDF_SetInfoAttr
                 U HPDF_SetInfoDateAttr
                 U HPDF_SetOpenAction
                 U HPDF_SetPageLayout
                 U HPDF_SetPageMode
                 U HPDF_SetPagesConfiguration
                 U HPDF_SetPassword
                 U HPDF_SetPermission
                 U HPDF_SetViewerPreference
                 U HPDF_TextAnnot_SetIcon
                 U HPDF_TextAnnot_SetOpened
                 U HPDF_UseCNSEncodings
                 U HPDF_UseCNSFonts
                 U HPDF_UseCNTEncodings
                 U HPDF_UseCNTFonts
                 U HPDF_UseJPEncodings
                 U HPDF_UseJPFonts
                 U HPDF_UseKREncodings
                 U HPDF_UseKRFonts
                 U HPDF_UseUTFEncodings
0000000000000000 T LclErrHandler
                 U fclose
                 U fopen
                 U luaL_argerror
                 U luaL_checkinteger
                 U luaL_checklstring
                 U luaL_checknumber
                 U luaL_checkoption
                 U luaL_error
                 U luaL_optlstring
                 U luaL_setfuncs
                 U lua_concat
                 U lua_createtable
                 U lua_error
                 U lua_isnumber
                 U lua_isuserdata
                 U lua_pushboolean
                 U lua_pushfstring
                 U lua_pushinteger
                 U lua_pushlightuserdata
                 U lua_pushnumber
                 U lua_pushstring
                 U lua_pushvalue
                 U lua_rawget
                 U lua_rawgeti
                 U lua_rawlen
                 U lua_rawset
                 U lua_rawseti
                 U lua_setfield
                 U lua_settop
                 U lua_toboolean
                 U lua_tointegerx
                 U lua_tolstring
                 U lua_tonumberx
                 U lua_touserdata
                 U lua_type
0000000000000160 T luaopen_hpdf
                 U sprintf

I don't have much time tonight to keep experimenting, but does this look more on track to you?

Thanks!

jung-kurt commented 6 years ago

I don't have much time tonight to keep experimenting, but does this look more on track to you?

Definitely. I think you are one small step away.