c-for-go icon indicating copy to clipboard operation
c-for-go copied to clipboard

Parsing stdio.h fails (unexpected char)

Open ePirat opened this issue 7 years ago • 18 comments

Trying to use c-for-go, I get the following error:

processing foo.yml ⠇[ERR] /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdio.h:461:16: unexpected char, expected one of [',', ';', '='] (and 3 more errors)

ePirat avatar Dec 12 '17 19:12 ePirat

Same but for stdbool.h.

1l0 avatar Dec 12 '17 19:12 1l0

Install Command Line Tools from there https://developer.apple.com/download/more/

xlab avatar Dec 12 '17 20:12 xlab

I have them installed. Xcode too. I have a full development environment set-up and can compile C, C++, Objective C fine with it.

Just to make sure, I checked with xcode-select:

xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

ePirat avatar Dec 12 '17 20:12 ePirat

Same:

$ pwd
/Applications/Xcode.app/Contents/Developer
$ find . -name stdbool.h
./Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/c++/4.2.1/tr1/stdbool.h
./Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1/tr1/stdbool.h
./Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A/lib/clang/2.0/include/stdbool.h
./Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/stdbool.h
./Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/c++/4.2.1/tr1/stdbool.h
./Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdbool.h
./Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include/stdbool.h

1l0 avatar Dec 12 '17 22:12 1l0

I'm reopening this so I won't look like a complete douche. But I still believe the problem is in your environment configuration.

Normally stdio.h is located in /usr/include when Command Line Tools are installed. I did that for myself a couple of hours ago, after updating my Xcode to the newest.

$ find /usr/include -name "stdio.h"
/usr/include/c++/4.2.1/tr1/stdio.h
/usr/include/sys/stdio.h
/usr/include/stdio.h

I don't understand why you're looking in /Applications/Xcode.app/Contents/Developer path, since these paths are for Objective-C development. If you are using a UNIX-style toolchain, after installing Command Line Tools your import path is /usr/include and /usr/local/include.

From CLT description:

This package enables UNIX-style development via Terminal by installing command
line developer tools, as well as macOS SDK frameworks and headers. Many useful
tools are included, such as the Apple LLVM compiler, linker, and Make. If you use
Xcode, these tools are also embedded within the Xcode IDE.

They are embedded, but for proper development it's important to use /usr-based tools.

E.g.

$ which gcc
/usr/bin/gcc
$ which make
/usr/bin/make

xlab avatar Dec 12 '17 23:12 xlab

@1l0 stdbool.h is another issue, just place this stub into your bindings directory: https://gist.github.com/xlab/e5f1f1f4bdc7568af5b1c81a305a1e7d

#ifndef STDBOOL_H
#define STDBOOL_H

typedef int bool;
#define true 1
#define false 0

#endif // STDBOOL_H

There is no stdbool header easily available on OS X.

xlab avatar Dec 12 '17 23:12 xlab

@ePirat your situation seems weird, I have no issues on OS X with this manifest:

--- 
GENERATOR: 
  PackageName: foo
  Includes: ["stdio.h"]

PARSER: 
  IncludePaths: ["/usr/include"]
  SourcesPaths: ["/usr/include/stdio.h"]
c-for-go foo.yml

Could you please share a reproducible example of YAML + headers? You can e-mail them to me.

xlab avatar Dec 12 '17 23:12 xlab

What I am trying to do is generate the headers for the VLC plugin headers.

I've removed the Xcode include path now, so I have now:

IncludePaths: ["/usr/include"]

which does work, but now I get:

include file not found: stdarg.h

So I tried adding "/usr/include/c++/4.2.1/tr1" as that contains stdarg.h, but with that I got:

[ERR] /usr/include/c++/4.2.1/tr1/stdarg.h:37:10: include file not found: tr1/cstdarg.

When omitting -ccdefs, it seem to kinda work. (Still getting errors but probably because I need to work more on the Translator section in my config?)

ePirat avatar Dec 12 '17 23:12 ePirat

Hm, seems I can't get this to work properly, getting errors after errors and right when solving one, running into another…

In case anyone can offer some advice, that's how the yaml looks right now:

--- 
GENERATOR: 
  PackageName: vlc-plugin
  PackageDescription: "Package vlc-plugin provides Go bindings for VLC plugin implementations"
  PackageLicense: "THE AUTOGENERATED LICENSE. ALL THE RIGHTS ARE RESERVED BY ROBOTS."
  PkgConfigOpts: [vlc-plugin]
  Includes: ["vlc_common.h"]

PARSER: 
  IncludePaths: ["/usr/include"]
  SourcesPaths: ["vlc_common.h", "vlc_messages.h"]

TRANSLATOR: 
  ConstRules: 
    defines: expand
    enum: expand

I've tried adding some more IncludePaths, running with or without -ccdefs, but so far getting tons of errors. I am already using VLC plugin headers with success in Go, as can be seen here, but was hoping I could use c-for-go to reduce boilerplate code I will have to write, to wrap the C functions.

The VLC headers can be found here: vlc.zip

I was hoping to be able to get at least some sort of result, which I could then further improve using the Translator settings, but without any result at all and a lot of weird errors when parsing system headers, I have no clue how to continue.

ePirat avatar Dec 13 '17 00:12 ePirat

Anything from /usr/include/c++/4.2.1/tr1 or similar won't work, it's a private path for compiler.

I will get back to you soon, about the issues related to the code.

xlab avatar Dec 13 '17 00:12 xlab

I was looking in /Applications/Xcode.app/Contents/Developer because c-for-go --ccincl pointed out that path. After adding /usr/include I'm in the same situation with https://github.com/xlab/c-for-go/issues/41#issuecomment-351235074. I uploaded a repo that don't work.

1l0 avatar Dec 13 '17 01:12 1l0

I've finally managed by just adding following defines:

PARSER:
  Defines:
    __has_include_next(x): 1

No /usr/include, just --ccincl. I've not tested further but at least succeeded to generate the Go package.

1l0 avatar Dec 23 '17 21:12 1l0

Ok, it works fine on my OS X though without additional flags or defines.

I cloned your package https://github.com/1l0/godot on commit d136ba5, added two files to its root:

  • stadarg.h https://gist.github.com/xlab/b43e9fd605e53d478c3d02176ccc036c
  • stdbool.h https://gist.github.com/xlab/e5f1f1f4bdc7568af5b1c81a305a1e7d

Added this to PARSER section:

PARSER:
  IncludePaths: 
    - /usr/include

Generated with

$ c-for-go -out .. godot.yml

No XCode or __has_include_next(x) was involved.

See https://github.com/1l0/godot/pull/1

xlab avatar Dec 24 '17 12:12 xlab

It works for me too without --ccincl in that way. So we should just add stubs. Thanks for helping.

1l0 avatar Dec 24 '17 13:12 1l0

I'm seeing this issue. Here's the output with the YAML from the comment above:

$ xcode-select -v
xcode-select version 2349.
$ xcode-select -p
/Applications/Xcode.app/Contents/Developer
$ cat foo.yml
---
GENERATOR:
  PackageName: foo
  Includes: ["stdio.h"]

PARSER:
  IncludePaths: ["/usr/include"]
  SourcesPaths: ["/usr/include/stdio.h"]
$ c-for-go --ccdefs foo.yml
  processing foo.yml ⠼[ERR] /usr/include/stdio.h:372:16: unexpected char, expected one of [',', ';', '=']
$

Anything else I should try to troubleshoot?

jancona avatar Dec 31 '18 11:12 jancona

@jancona Hi, please share stdio.h here, I think my file is different — no line at /usr/include/stdio.h:372:16

xlab avatar Jan 02 '19 11:01 xlab

Thanks! Here's the file: stdio.h.zip I'm running High Sierra version 10.13.6

jancona avatar Jan 03 '19 01:01 jancona

I had a similar issue, but seemed to progress by defining _POSIX_C_SOURCE which sets _DARWIN_C_LEVEL and skips the Darwin extensions.

PARSER:
  Defines:
    _POSIX_C_SOURCE: 1

leedenison avatar Jan 20 '19 20:01 leedenison