import "C" keeps getting removed

This is likely a newbie question but I'm building a shared library to be invoked from Python. I compile it with -buildmode=c-shared option. In the top of my go file, I am inserting::

import "C"

For some reason, the editor removes this every time I touch the file and I keep having to readd before compiling. Anyway to prevent this ?

 

0
3 comments
Official comment

Hi Michsmit,

 

Are you not using any "C" function or identifier at all? Do you just need this for building? If so, I'll open a follow-up issue.

Meanwhile, you can use this as a sample of how to avoid the import being automatically removed (add a comment before the import):

 

package main

// //Needed for build
import "C"

func main() {
println("demo")
}

 

Thank you.

Avatar
Permanently deleted user

Thanks for the tip, the comment before works !

I am using this just to export a function such as the following snippet:

//export start

func start() {

0

Hi Michsmit,

 

Thank you for your update, I'm happy this works now.
I've created this issue https://youtrack.jetbrains.com/issue/GO-5781 in order to track this bug, sorry for the inconvenience.
Have a great weekend!

0

Please sign in to leave a comment.