Search code examples
gocgo

how do I tell cgo not to compile a file?


for a regular go file I say

// +build !windows

however cgo interprets this as c code to get compiled

So what do I have to do?


Solution

  • The build constraint must appear before your package declaration.

    Incorrect

    package mypackage
    
    // +build !windows
    
    // #include <header.h>
    //
    // ...
    import "C"
    

    Correct

    // +build !windows
    
    package mypackage
    
    // #include <header.h>
    //
    // ...
    import "C"