Clang-cl and C Blocks extension

Hi guys,

I’m trying to compile C code that uses the Blocks extension using clang-cl on Windows, via CMake’s LLVM-vs2014 toolset.
The compilation errors out, telling me I’d need to enable blocks by passing “-fblocks” to clang, however clang-cl doesn’t recognize that flag.

Anything I can do?

Thanks,

Thorben

You can pass “-Xclang -fblocks” on the command line to pass the option to cc1 directly.

(adding back cfe-dev)

You’ll need to link against a blocks runtime library. compiler-rt provides one (under lib/BlocksRuntime). I haven’t tried building that under Windows, but I do see some _WIN32 defines in the source code, so hopefully it should work?

Hi!
In my experience blocks are almost like lambdas. In many cases it’s quite simple to rewrite them using std::function or something similar.

Regards,

Ivan

(adding back cfe-dev)

You'll need to link against a blocks runtime library. compiler-rt provides
one (under lib/BlocksRuntime). I haven't tried building that under Windows,
but I do see some _WIN32 defines in the source code, so hopefully it should
work?

The better maintained version is currently in swift-corelibs-foundation,
under a directory called closure.

https://github.com/apple/swift-corelibs-foundation/tree/master/closure