vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.5k stars 2.15k forks source link

Compiler bug - C error #20634

Open fatteneder opened 5 months ago

fatteneder commented 5 months ago

Describe the bug

I was looking into wrapping https://github.com/HDFGroup/hdf5 with V.

Reproduction Steps

MWE:

// hdf5.v
#flag linux -I/usr/include -L/usr/lib
#flag -lhdf5
#include "H5File.h"

Expected Behavior

No compiler bug.

Current Behavior

$ v -cg run hdf5.v
In file included from /tmp/v_1000/hdf5.01HMSEZARBZT1GJ86GYHNEH8NK.tmp.c:749:
/usr/include/H5File.h:18: warning: type defaults to int
In file included from /tmp/v_1000/hdf5.01HMSEZARBZT1GJ86GYHNEH8NK.tmp.c:749:
/usr/include/H5File.h:18: error: ';' expected (got "H5")
builder error:
==================
C error. This should never happen.

This is a compiler bug, please report it using `v bug file.v`.

https://github.com/vlang/v/issues/new/choose

You can also use #help on Discord: https://discord.gg/vlang

Possible Solution

Well, turns out that H5File.h is a C++ header and on my installation line 18 is

namespace H5 {

So perhaps just throw an error saying it's not a valid C header.

Also: the right header to use is hdf5.h, no error there.

Additional Information/Context

No response

V version

V 0.4.4 0205154

Environment details (OS name and version, etc.)

OS: void linux 6.6.10_1

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

JalonSolov commented 5 months ago

V doesn't try to parse any headers - it doesn't look at them at all. It simply adds the #include lines to the generated C code, and let's the C compiler do what it likes with them.