I build a lib.a static library.then compile main object,but I link the main.o,found some trouble:
main…inittask: relocation target lib…inittask not defined
source file:
src/lib/greet.go
package lib
import “fmt”
func Greet(word string){
fmt.Print(word);
}
src/main/main.go
package main
import (
“lib”
)
func main(){
lib.Greet(“Okay”);
}
command step:
1.go build -o lib.a src/lib/greet.go //if here using go build -o lib.a lib (package),it goes right.Why???
2.go tool compile -I . src/main/main.go
3.go tool link -L .main.o
main…inittask: relocation target lib…inittask not defined
It goes wrong. Why can’t build with source files?
WORK=/tmp/go-build592806929
command-line-arguments
mkdir -p $WORK/b001/
cat >$WORK/b001/importcfg << ‘EOF’ # internal
import config
packagefile fmt=/usr/local/go/pkg/linux_amd64/fmt.a
EOF
cd /tmp/go/src/lib
/usr/local/go/pkg/tool/linux_amd64/compile -o $WORK/b001/pkg.a -trimpath “$WORK/b001=>” -p command-line-arguments -complete -buildid rP94e3iTbzSluHW4oK35/rP94e3iTbzSluHW4oK35 -goversion go1.15.6 -D _/tmp/go/src/lib -importcfg $WORK/b001/importcfg -pack ./greet.go
/usr/local/go/pkg/tool/linux_amd64/buildid -w $WORK/b001/pkg.a # internal
cp $WORK/b001/pkg.a /root/.cache/go-build/04/04c8eab7a53e72ca62bc5f1ffd46a09eb7c7706d1aad671b93b2784fbe44edf9-d # internal
mkdir -p …/…/
mv $WORK/b001/pkg.a …/…/lib.a
rm -r $WORK/b001/
command-line-arguments should return package ? But it goes wrong???
system
(system)
Closed
4
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.