DLL, Dylib and other libs (.lib, .o, .a)

Just starting out? Need help? Post your questions and find answers here.
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

DLL, Dylib and other libs (.lib, .o, .a)

Post by coder14 »

I just built the PDFium library on my Mac and it produced a 4KB libpdfium.dylib and a 30MB libfpdfapi.a file. They don't work with OpenLibrary or Import and I think maybe they were not built correctly.

I am rebuilding them again and it seems to be taking longer which makes me think that the first build was faulty. While waiting for it to finish I wanted to confirm that Dylibs on Mac can be called the same way that DLLs are called on Windows? I also wanted to check if Mac's .a (or should it be .o?) files can be imported?

OpenLibrary failed with IMA and Import failed with:
Undefined symbols for architecture x86_64: "_FPDF_InitLibrary" referenced from: _main in purebasic.o PStub_FPDF_InitLibrary in purebasic.o id:symbols(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1"
I'm lacking sleep and very confused. :shock:

Please help!

EDIT: Sorry I forgot - PB 5.5 x64 and El Capitan and XCode 6.1.1
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: DLL, Dylib and other libs (.lib, .o, .a)

Post by Keya »

yes, dylib on OSX is basically like a DLL in Windows, or .so on Linux

.o files can be packed together into a .a, this is the same as .obj and .lib on Windows (although compilers like gcc on Windows also produce .o and .a). For a simple hello world example of creating and using a lib on OSX see http://purebasic.fr/english/viewtopic.php?f=13&t=65722

In some cases a library comes in the form of a static library (.o/.a/.obj/.lib) etc but also a shared library (.dll, .dylib, .so), but im not familiar with PDFium sorry
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: DLL, Dylib and other libs (.lib, .o, .a)

Post by ts-soft »

@coder14
your are using a 32-bit "DLL" for a 64-bit Compiler, so this can't never working!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: DLL, Dylib and other libs (.lib, .o, .a)

Post by coder14 »

ts-soft wrote:@coder14
your are using a 32-bit "DLL" for a 64-bit Compiler, so this can't never working!
Thanks for the fast answers ts-soft and Keya. :D

I took your advice and tried them with x86 PB but same thing. I think the .a file is a no go because I get this error:
id: warning: ignoring file /Users/Sofia/code/library/libfpdfapi.a file was built for archive which is not the architecture being linked (i386): /Users/Sofia/Code/library/libfpdfapi.a Undefined symbols for architecture i386: "_FPDF_InitLibrary" referenced from: PStub_FPDF_InitLibrary in purebasic.o id: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1
The dylib is not loading and returning 0 for OpenLibrary on x86 and x64. I must be doing something wrong. :(
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: DLL, Dylib and other libs (.lib, .o, .a)

Post by jack »

could you list the steps you took to build pdfium?
I successfully built pdfium but the step required are new to me https://pdfium.googlesource.com/pdfium/
1: goto http://www.chromium.org/developers/how- ... epot-tools
2: git clone https://chromium.googlesource.com/chrom ... _tools.git
3: export PATH=`pwd`/depot_tools:"$PATH"
4: mkdir repo
5: cd repo
6: gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git
7: gclient sync
8: cd pdfium
9: mkdir mybuild
10: gn gen mybuild
11: gn args mybuild
12: ninja -C mybuild

I had to copy the dylibs in the folder mybuild to the PureBasic/compilers folder
after all that the following test code works

Code: Select all

Import "-stdlib=libc++ -mmacosx-version-min=10.9" : EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/libpdfium.a"
  InitLibrary () As "_FPDF_InitLibrary"
  LoadDocument (documentpath.p-utf8,password.p-utf8) As "_FPDF_LoadDocument"
  GetPageCount(HandleToDocument.i) As "_FPDF_GetPageCount"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/third_party/libbigint.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/libfdrm.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/libformfiller.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/libfpdfapi.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/libfpdfdoc.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/libfpdftext.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/third_party/libfx_agg.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/third_party/libfx_freetype.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/third_party/libfx_lcms2.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/third_party/libfx_libopenjpeg.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/third_party/libfx_lpng.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/third_party/libfx_zlib.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/libfxcodec.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/libfxcrt.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/libfxedit.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/libfxge.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/libfxjs.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/libjavascript.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/third_party/libjpeg.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/build/config/sanitizers/liboptions_sources.a"
EndImport

ImportC "/Users/jbk/Desktop/repo/pdfium/mybuild/obj/libpdfwindow.a"
EndImport

ImportC "libicui18n.dylib"
EndImport

ImportC "libicuuc.dylib"
EndImport

ImportC "libv8_libbase.dylib"
EndImport

ImportC "libv8_libplatform.dylib"
EndImport

ImportC "libv8.dylib"
EndImport

Procedure Main()
  
  InitLibrary()
  
  Protected pdf = LoadDocument("/Users/jbk/Desktop/maxima.pdf", "")
  
  Debug GetPageCount(pdf) 
  
EndProcedure

Main()
Last edited by jack on Fri Jan 13, 2017 10:19 pm, edited 2 times in total.
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: DLL, Dylib and other libs (.lib, .o, .a)

Post by jack »

coder14 wrote: The dylib is not loading and returning 0 for OpenLibrary on x86 and x64. I must be doing something wrong. :(
try placing the dylib in /usr/local/lib or in the purebasic/compilers folder
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: DLL, Dylib and other libs (.lib, .o, .a)

Post by coder14 »

jack wrote:could you list the steps you took to build pdfium?
Thank you for your great reply. I am lloking at it now. To answer your question I did it through Git similar to yours following the instructions here: https://pdfium.googlesource.com/pdfium/

I run these commands from Bash Terminal (El Capitan and XCode 6.1.1):
1. git clone https://chromium.googlesource.com/chrom ... _tools.git
2. export PATH=`pwd`/depot_tools:"$PATH"
3. mkdir repo
4. cd repo
5. gclient config --unmanaged https://pdfium.googlesource.com/pdfium.git
6. gclient sync
7. cd pdfium
8. gn gen pdfbuild
9. gn args pdfbuild

This opens Vim automatically and I insert these lines:

is_debug = false
is_component_build = false
is_official_build = true
pdf_enable_xfa = false
pdf_enable_v8 = false
pdf_is_standalone = true
clang_use_chrome_plugins = false

Then I save and close Vim and the build continues. Following instructions from:

https://github.com/pvginkel/PdfiumViewe ... ing-PDFium

I edit BUILD.gn in the /repo/pdfium folder as follows except the last one - I di not add pdfiumviewer.cpp:
In the section config("pdfium_common_config"):
Add the following include path to the include_dirs list: "v8/include";
Add the following define to the defines list: "FPDFSDK_EXPORTS";
Change static_library("pdfium") to shared_library("pdfium") to build a shared library;
And lastly I go into the pdfbuild folder and run:

ninja pdfium

It builds about 400++ files including the libpdfium.dylib but which is only 4KB. If I build the whole project which is about 1400++ files the libpdfium.dylib is about 20MB. And if I add [target_CPU = "x64"] in the args.gn file it builds more (i forget how many files) and the libpdfium.dylib is 50MB.

But they all don't work. Either OpenLibrary does not open them or it opens them and gives an IMA on _FPDF_InitLibrary. I am trying to run the example code given by acreis here:

http://www.purebasic.fr/english/viewtop ... 68#p500068

It works perfectly in Windows!

I am going to try your suggestions now. Thank you. :D
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: DLL, Dylib and other libs (.lib, .o, .a)

Post by coder14 »

I'm missing some of the .a files - rebuilding now with default options.

[626/626] Done! No dylibs were generated with the default settings so I commented all the dylib imports out - but it works with your import list!!!

Thank you jack! I am most grateful! :D :D :D

One very very funny thing - all the functions work (no errors at least) except for _FPDF_RenderPage - which is supposed to be the most important of all. The manual says that it is supported on Windows only. :shock:

https://pdfium.patagames.com/help/html/ ... 0e1d6a.htm

How to show the PDF then? :?: :evil: :(
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: DLL, Dylib and other libs (.lib, .o, .a)

Post by coder14 »

Experimenting with _FPDF_RenderPageImage... :lol:
coder14
Enthusiast
Enthusiast
Posts: 327
Joined: Tue Jun 21, 2011 10:39 am

Re: DLL, Dylib and other libs (.lib, .o, .a)

Post by coder14 »

Still no success although very very close. :|

Going to give PDFkit a try! :lol:
Post Reply