Using Go on existing C project

前端 未结 2 1522
天命终不由人
天命终不由人 2021-01-13 02:39

I have a program entirely written in C that uses multiple object (.o) files in it. These files are all packed inside an archive file (.a) which, in

2条回答
  •  一整个雨季
    2021-01-13 03:26

    There currently isn't a supported way to do what you want. Go always needs the support of its runtime, and the entry point for that is always main. AFAIK, gccgo also makes these same assumptions, and doesn't provide a way to easily link into from other programs.

    If you want to do this in a supported manner, you will have to wait until go1.5+ where work is being done to compile shared libraries from Go code.

    If you really want to hack on this now, you can look into how the Android port works using the default gc toolchain with -linkmode external, which renames main in the object file and calls it externally.

提交回复
热议问题