-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/cgo: cannot create file using cgo function: file name becomes an invalid encoding #26376
Comments
Using The |
By the way, for questions about using Go, including using with other languages like R and Python, you are much more likely to get a better answer in a forum than on the issue tracker. See https://golang.org/wiki/Questions . |
Thanks for the fast reply. This is the just the symbol, nothing else. About the forum; thanks I'll try that too. I tried Reddit without success. |
Trying doing the exact same thing with a C shared library and see what it gets for the string. |
I got a solution form a user on Reddit, here it is what he said: Since you are passing a string in this example, it will be easier to use .C — which is for passing data as C data types — instead of .Call — which is for passing R objects. According to the docs on "Foreign Function Interface", a string is passed as char **, so your function will take **C.char:
Using the function like that and the R Thanks |
Thanks for following up. Glad you got it working. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go1.10.2 linux/amd64
Does this issue reproduce with the latest release?
not sure, didn't tested with anything above the version I have
What operating system and processor architecture are you using (
go env
)?GOHOSTARCH="amd64"
GOHOSTOS="linux"
What did you do?
I'm trying to convert a GO program into a shared library to be used on my R script. At first I tested with something simple, I have a function that takes an input path (string) and creates a file on the disk. My problem is that the string with the path becomes something with an invalid encoding, see below:
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
This is my function:
I compile the library with:
And then I run my R script like this:
I also tried running this in a Python program:
And what I get is a file called ` � (invalid encoding) `. That's literally the file name, including that exclamation symbol you see there.
I added some print functions trying to understand the problem and this is what I get :
I also tried this without any success:
What I find curious is that the function ends at the return statement and I can see on the terminal the correct string with the path that was passed to the function.
What did you expect to see?
An empty file on my disk called test.txt
What did you see instead?
An empty file on my disk called
� (invalid encoding)
The text was updated successfully, but these errors were encountered: