Skip to content

Add dll export to the callback functions.#270

Open
jeroen1602 wants to merge 1 commit intoklippa-app:mainfrom
jeroen1602:dll-export
Open

Add dll export to the callback functions.#270
jeroen1602 wants to merge 1 commit intoklippa-app:mainfrom
jeroen1602:dll-export

Conversation

@jeroen1602
Copy link

I was having issues tyring to build this project for windows. It was complaining that the callback functions have already been defined and can thus not add the dllexport attribute.

Here is an example error:

cgo-gcc-export-header-prolog:123:40: error: redeclaration of 'go_formfill_FFI_GetPage_cb' cannot add 'dllexport' attribute
  123 | extern __declspec(dllexport) FPDF_PAGE go_formfill_FFI_GetPage_cb(FPDF_FORMFILLINFO* me, FPDF_DOCUMENT document, int nPageIndex);
      |                                        ^
fpdf_formfill.go:16:18: note: previous declaration is here
   16 | extern FPDF_PAGE go_formfill_FFI_GetPage_cb(struct _FPDF_FORMFILLINFO *this, FPDF_DOCUMENT document, int nPageIndex);

I go this problem when using the zig (cross) compiler and clang (running native on Windows).

So I made a change to add the dllexport required to the first definitions of these methods when targeting windows.

Using this I did get it to compile for Windows.

When using the cgo version for windows it complains about the callback functions already being defined and thus not being able to add the dll export attribute. This change adds this attribute to the first definition of the functions when targeting windows.
@Alexufo
Copy link

Alexufo commented Dec 10, 2025

Did you try to compile go-pdfium with mingw64 for windows?

@jeroen1602
Copy link
Author

I did not try mingw64. Either before or after this change.

I did eventually not have to use because the FPDF_RenderPage call I needed cgo for. Checks if the device handle is of a specific type. But because this type has its origin in cgo it is unique to this package so you can never create a handle that has the correct type.

See the code here:

hdc, ok := request.DC.(C.HDC)
if !ok {
return nil, errors.New("DC is not of type C.HDC")
}

@Alexufo
Copy link

Alexufo commented Dec 11, 2025

tnx. Have you some manual for zig and your pullrequest? I tried without success

@jeroen1602
Copy link
Author

I set the C and C++ compiler it should use using

CC="zig cc -target x86_64-windows" CXX="zig c++ -target x86_64-windows"

@Alexufo
Copy link

Alexufo commented Dec 11, 2025

thx, go compiler does not say about wrong path to pkg-config ?

@jeroen1602
Copy link
Author

That does sound familiar.

I believe I searched for a windows port of pkg-config which may work. But decided that cross compiling using either WSL, Macos or a real Linux host was a lot easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants