Unable to access folder containing C codes from Go

I get a message when I import a folder containing .cpp files

Prog Structure

| ccode      (this is a C folder)
   * c1.cpp
   * c1.h
   * c2.cpp 

| gocode	    (this is a go folder)
        | headers 
          * h1.go
          * h2.go
        | maingofile.go
               (From maingofile.go, I try to import ccode )


package gocode

#import C
import “main/ccode”

The error message I see when I do import “main/ccode” folder

"package main/gocode
imports ccode: no Go files in /home/user/go/src/ccode

What is the issue?

I don’t think you can have a separate C folder. The few places I see cgo being used, it appears to be a combination of .c files and “inline” C code in comments above the import "C" statement in .go files. For example, two that I found after Googling for “example cgo projects”:

If I may make an observation: In your first question here, you said that you are working on your first project and it is “in Go,” yet all of your questions have been about how to reference C or C++ code from Go. What exactly is this C/C++ code? Is it really worth a month’s worth of effort to figure out how to use it from Go instead of just learning and rewriting it into Go? The answer might be “yes,” of course, but I figured I’d ask. Most of the answerers on this forum are more inclined to answer questions about how to do things in pure Go and not cgo.

1 Like

True @skillian , I am working on Go projects and at same time there are some existing projects in C++ which requires to be called thru Go rather than re-developing it.
I just wanted to get help on how C can be called from Go or any wrappers that needs to be developed
Will keep my questions related to Go as much as possible
This link was helpful https://github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3)

It was not my intention to steer you away. Just to potentially offer an alternative solution that you may not have considered! We’ll still try to help you with cgo as best we can!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.