Akkuman
Akkuman

Reputation: 41

How can I build a dll with cgo and .def file

I want to implement dll forwarding(or dll proxy)

In mingw, I can use cpp source with .def file, like gcc -shared -o test.dll functions.def test.cpp

But I don't know how to implement it in golang

Upvotes: 0

Views: 612

Answers (1)

Akkuman
Akkuman

Reputation: 41

I know what to do to solve this problem.

use the extldflags

First Way:

  1. compile the .def file to .exp file
dlltool --def functions.def --output-exp evildll.exp
  1. compile main.go

main.go

package main

import "C"

func main() {
    // Need a main function to make CGO compile package as C shared library
}

use command go build -buildmode=c-shared -o exportgo.dll -ldflags="-extldflags=-Wl,C:/Users/Akkuman/Desktop/go-dll-proxy/evildll.exp"

then you can get the dll

click me to view image

Second Way

use command go build -buildmode=c-shared -o exportgo.dll -ldflags="-extldflags=-Wl,C:/Users/Akkuman/Desktop/go-dll-proxy/functions.def"

then you can get the dll, but with a additional export function

click me to view image

Upvotes: 1

Related Questions