Skip to content

Cinder incompatible with C++ modules in Gcc #2401

@fedapo

Description

@fedapo

When using C++ modules on an application that uses Cinder compilation with Gcc fails.

I believe the errors are due to Gcc limitations (a bug?), Clang is not affected and compiles correctly.
Nevertheless, Cinder could play nice and easily fix the Gcc problem while also resulting in code that is a tiny bit cleaner.

This is the error:

/home/user/Cinder/include/cinder/ImageIo.h:48:81: note: existing declaration ‘typedef enum cinder::ImageIo::DataType cinder::ImageIo::DataType’
   48 |         typedef enum DataType { UINT8, UINT16, FLOAT32, FLOAT16, DATA_UNKNOWN } DataType;
      |                                                                                 ^~~~~~~~
/home/user/Cinder/include/cinder/ImageIo.h:47:65: error: conflicting imported declaration ‘typedef enum cinder::ImageIo::ColorModel cinder::ImageIo::ColorModel’
   47 |         typedef enum ColorModel { CM_RGB, CM_GRAY, CM_UNKNOWN } ColorModel;
      |                                                                 ^~~~~~~~~~
/home/user/Cinder/include/cinder/ImageIo.h:47:65: note: existing declaration ‘typedef enum cinder::ImageIo::ColorModel cinder::ImageIo::ColorModel’
   47 |         typedef enum ColorModel { CM_RGB, CM_GRAY, CM_UNKNOWN } ColorModel;
      |                                                                 ^~~~~~~~~~
/home/user/Cinder/include/cinder/ImageIo.h:51:56: error: conflicting imported declaration ‘typedef enum cinder::ImageIo::ChannelType cinder::ImageIo::ChannelType’
   51 |                                         CHAN_UNKNOWN } ChannelType;
      |                                                        ^~~~~~~~~~~
/home/user/Cinder/include/cinder/ImageIo.h:51:56: note: existing declaration ‘typedef enum cinder::ImageIo::ChannelType cinder::ImageIo::ChannelType’
   51 |                                         CHAN_UNKNOWN } ChannelType;
      |                                                        ^~~~~~~~~~~
/home/user/my_app/src/MyApp.cpp:32:6: note: during load of binding ‘::MyApp@MyApp’
   32 | void MyApp::setup()
      |      ^~~~~

Cinder's headers are placed only in the global module fragment of the C++ module's code, as they should.

module;

#include <cinder/GeomIo.h>
#include <cinder/CameraUi.h>
#include <cinder/app/App.h>
#include <cinder/gl/gl.h>

export module MyApp;

// ... actual code of the module interface

In order to silence the error enum definitions should be converted from this:

	typedef enum ColorModel { CM_RGB, CM_GRAY, CM_UNKNOWN } ColorModel;

To this:

	enum ColorModel { CM_RGB, CM_GRAY, CM_UNKNOWN };

I have tried this change and after that everything works. I believe Cinder would not get worse after this. Using a typedef in all enum and struct definitions is not necessary in C++ and it looks a lot like a leftoever style that was only needed in C.

I can propose a pull request with the change above. What are the chances that it gets approved? What are the reasons for objecting to it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions