2

I need to compile my program - main.go with package bigPak without source. Exist only bigPak.a tnto GOPATH/pkg.

Can you give me example of compile main.go with bigPak.a ?

2
  • It might be possible, but if it is you'd have to manually invoke the linker and compiler, it would be pretty hard to work with. Commented Oct 23, 2014 at 8:18
  • Related question: stackoverflow.com/questions/28406122 Commented Dec 22, 2015 at 13:53

1 Answer 1

5

That's dead simple: Just produce a fake bigPak package in the right $GOPATH/src location (an empty package bigPak will do) and (important!!) make sure this synthetic source has a modification time before the modification time of bigPak.a. The go tool should just work like this.

Go is designed to be able to compile from the .a files without transitively reading their includes. The Go tool uses the source (only) to check if an .a files needs to be recompiled (because the source is newer.

Sign up to request clarification or add additional context in comments.

9 Comments

I tried it locally and it did work. Make sure the .a stems from the right compiler version and the paths are ok. (And: showing error messages and detailed setup would make debugging easier.)
Maybe I did not understand you... I have bigPak.a what should I do so that my program main.go compile? Please give me an example that would be great!
Assuming bigPak.a is the object file of package some/big/code and your main program does import "some/big/code" and is located in $GOPATH/src/me/myprog. You are on 64bit linux and bigPak.a has been compiled for this platform by the Go compiler (not C code!) and declares itself as package sbc. tbc...
You forgot to touch the fake source. What you did makes the go tool think it has to recompile src/book/bigPak/bigPak.go which it does and then getData is missing.
@user2614682, no there's no simpler way yet.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.