2

派手なコマンド ライン インターフェイスに GNU readline ライブラリを使用する Go プログラムを作成しています。インストールプロセスを簡素化し、ライブラリのバージョンなどを気にしないために、静的にリンクしたいと考えています。

問題は、私がそれを行う方法を本当に知らないことです。ライブラリをプリコンパイルする場合、.a または .lib readline ライブラリの異なるバージョンを使用して、いくつかのバージョンのコードを提供する必要があります。この問題を回避するために、現在の readline コードを go プロジェクトに含め、go ツールが go プロジェクトをビルドするときにそれをコンパイルすることを考えていました。ただし、readline ライブラリをビルドするには、 を使用する必要がありますmake。go ツールに C コードのビルド方法を伝える方法はありますか?

4

2 に答える 2

5

Yes, you can certainly do that. I've recently done something similar with a different project, mainly because the code was not available as a library (Ubuntu compiles just the command line tool for it). To achieve it, I've run the autoconf script with options that I figured would be sensible in most systems, and copied the C code together with the automatically built config.h header file into the Go package directory. Then, I've built the original C code with make once and observed which options gcc would get while compiling and linking it, and copied the appropriate ones into cgo's LDFLAGS and CFLAGS options (you can also inspect the Makefile, but that was easier).

A couple of side notes:

  • Have you considered doing the readline work in Go itself? The ssh terminal package works at least as a pretty good seed, if it doesn't solve your problem completely.

  • Remember that readline, although being a library, is GPL. You'll necessarily have to license your own software as GPL as well if you link or embed it. There are other smilar libraries available with less strict licenses, if you care.

于 2013-09-09T20:23:10.037 に答える
1

readline を避けることをお勧めします。より良い代替手段が存在します。https://github.com/edsrzf/finelineのように

于 2013-09-09T21:20:25.320 に答える