1

我正在尝试为 Apache 模块系统构建一个 Go 接口。即我希望能够从我的 Apache 模块调用 Go 函数。这是我的 Go 文件:

package main

// #cgo CFLAGS: -I/usr/include/apache2 -I/usr/include/apr-1.0
// #include <httpd.h>
import "C"

//export handler
func handler(r *C.request_rec) int {
    ap_set_content_type(r, "text/html");
    ap_rprintf(r, "Hello, world from Go")
    return OK;
}

当我构建它(go build mod_frugal.go)时,我收到此错误:

# command-line-arguments
./mod_frugal.go:8:17: type conversion loop at volatile *struct apr_bucket

第 8 行是函数“handler”开始的行。有什么建议么?

或者,当我使用 cgo ( ) 构建时,go tool cgo mod_frugal.go它根本看不到我的包含指令:

/home/vagrant/mod_frugal/src/mod_frugal.go:4:20: fatal error: httpd.h: No such file or directory
// #include <httpd.h>
                ^
compilation terminated.

当我添加“C”时。为两个 apache 调用添加前缀:

package main

// #cgo CFLAGS: -I/usr/include/apache2 -I/usr/include/apr-1.0
// #include "mod_frugal.h"
import "C"

//export handler
func handler(r *C.struct_request_rec) int {
    C.ap_set_content_type(r, "text/html")
    C.ap_rprintf(r, "<h1>Hello, world from Go!</h1>")
    return OK
}

我收到一个新错误:

# _/home/vagrant/mod_frugal/src
37: error: 'ap_set_content_type' undeclared (first use in this function)
37: error: 'ap_rprintf' undeclared (first use in this function)

也许我需要链接 libhttpd?我只是在互联网上找不到任何关于链接到 apache2 的构建,包括 libhttpd 等。

编辑:

随时关注这里的对话:

4

0 回答 0