LRN
2011-10-05 15:39:19 UTC
LGPL (at least LGPLv3) is mostly used for shared libraries, but you
can do static linking as well, you just need to provide object files
(not source files) for the whole program, so that end user can re-link
it with a different version of the library. I've asked FSF to clarify
that, should hear back from them in a couple of months.
Meanwhile, here's a HelloWorld program i've used:
---------------main.go------------------
package main
import (
"fmt"
"libhelloworld"
)
func main() {
fmt.Printf(libhelloworld.GetRandomHello ())
}
---------------------------------
---------------libhelloworld.go------------------
package libhelloworld
import (
"rand"
"fmt"
"time"
)
var langs = []string {
"en_US",
"ru_RU",
"gr_GR",
"jp_JP"}
var hellos = map[string]string {
"en_US" : "Hello, World",
"ru_RU" : "Здравствуй, Мир",
"gr_GR" : "Καλημέρα κόσμε",
"jp_JP" : "こんにちは 世界",
}
func GetRandomHello () string {
rand.Seed (time.Nanoseconds ())
n := rand.Intn (len (langs))
return hellos[langs[n]]
}
---------------------------------
You can run:
8g libhelloworld.go
8g main.go
8l -L . main.8
then run main.out a few times and see [mostly] different helloworld
printed every time.
Then modify libhelloworld.go (for example, remove all map pairs,
except for "en_US" one), run
8g libhwlloworld.go
8l -L . main.8
and run main.out again to see that now you only get English
helloworld, and you didn't need to re-compile main.8 to make the
change (hence, you don't need main.go, only main.8).
Ok, this is a bit silly, but you never know.
But what if main.8 was compiled with older/newer version of the
compiler (or a different compiler)? Are there any other problems with
this scheme?
can do static linking as well, you just need to provide object files
(not source files) for the whole program, so that end user can re-link
it with a different version of the library. I've asked FSF to clarify
that, should hear back from them in a couple of months.
Meanwhile, here's a HelloWorld program i've used:
---------------main.go------------------
package main
import (
"fmt"
"libhelloworld"
)
func main() {
fmt.Printf(libhelloworld.GetRandomHello ())
}
---------------------------------
---------------libhelloworld.go------------------
package libhelloworld
import (
"rand"
"fmt"
"time"
)
var langs = []string {
"en_US",
"ru_RU",
"gr_GR",
"jp_JP"}
var hellos = map[string]string {
"en_US" : "Hello, World",
"ru_RU" : "Здравствуй, Мир",
"gr_GR" : "Καλημέρα κόσμε",
"jp_JP" : "こんにちは 世界",
}
func GetRandomHello () string {
rand.Seed (time.Nanoseconds ())
n := rand.Intn (len (langs))
return hellos[langs[n]]
}
---------------------------------
You can run:
8g libhelloworld.go
8g main.go
8l -L . main.8
then run main.out a few times and see [mostly] different helloworld
printed every time.
Then modify libhelloworld.go (for example, remove all map pairs,
except for "en_US" one), run
8g libhwlloworld.go
8l -L . main.8
and run main.out again to see that now you only get English
helloworld, and you didn't need to re-compile main.8 to make the
change (hence, you don't need main.go, only main.8).
Ok, this is a bit silly, but you never know.
But what if main.8 was compiled with older/newer version of the
compiler (or a different compiler)? Are there any other problems with
this scheme?