JuliaInterop / Clang.jl

C binding generator and Julia interface to libclang
https://juliainterop.github.io/Clang.jl/
MIT License
218 stars 68 forks source link

Conflicting `enum` and `#define` identifiers make a translated header cause `invalid redefinition of constant` #467

Open topolarity opened 5 months ago

topolarity commented 5 months ago

NgSpice has a habit of establishing most enum-like constants with #define: https://github.com/imr/ngspice/blob/902a62d2f442a1d8322ae4fcad35c143c7a14561/src/include/ngspice/noisedef.h#L72-L74

but then occasionally introducing an enum { ... } with the same names wrapped in an ifdef guard: https://github.com/imr/ngspice/blob/902a62d2f442a1d8322ae4fcad35c143c7a14561/src/include/ngspice/acdefs.h#L29-L35

Example:

// test1.h
#ifndef TEST_H_
#define TEST_H_
enum {
    DECADE = 1,
    OCTAVE,
    LINEAR,
};
#endif // TEST_H_
// test2.h
#ifndef TEST_H_
#define DECADE 1
#endif

result:

module TestModule

const __JL_Ctag_1 = UInt32
const DECADE = 1 % UInt32
const OCTAVE = 2 % UInt32
const LINEAR = 3 % UInt32

const DECADE = 1
# ...
end # module

It would be nice if Clang.jl either:

topolarity commented 5 months ago

As a workaround, it does work if I use a wrapper header:

// wrapper.h
#include "test1.h"
#include "test2.h"

and translate only that

Gnimuc commented 5 months ago

does it work if you pass a macro-define compiler flag to args?