Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ : export-attribute not applied to enums #861

Closed
zvrba opened this issue Apr 20, 2018 · 8 comments
Closed

C++ : export-attribute not applied to enums #861

zvrba opened this issue Apr 20, 2018 · 8 comments
Assignees
Labels

Comments

@zvrba
Copy link

zvrba commented Apr 20, 2018

Free-standing functions FromString, ToString, etc. are generated for enums. When I invoke Bond compiler with --header=\"QS_exports.h\" --export-attribute=QS_API, this attribute is not applied to these functions, an example from the generated types file:

const std::string& ToString(enum DeviceType value);

This in turn makes it impossible to use these functions when the generated code is compiled as DLL. Interestingly, #include "QS_exports.h" is present in the file.

As a workaround, I use functions GetValueToNameMap and GetNameToValueMap, which are defined inline in the header file, but this is.. quite inelegant.

@ara-ayvazyan
Copy link
Contributor

The --export-attribute is used in generated _apply.cpp file only. It is meant for pre-compiling de/serialization code into a DLL, and not the struct itself along with related functionality.

@zvrba
Copy link
Author

zvrba commented Apr 21, 2018

Ah, I understand now. Then I have a feature request:

  • Add support for pre-compiling the struct code to a DLL/LIB
  • Alternatively, generate it inline

@zvrba
Copy link
Author

zvrba commented Apr 21, 2018

Addition: the generated code is inconsistent anyway when --export-attribute is used. I have now added *_types.cpp to the project where I'm using the struct functionality (since it's not exported from the DLL), and this results in the following error:

1>[..]\quine.schemas_types.cpp(24): error C2491: 'quine::schemas::UUID::Schema::metadata': definition of dllimport static data member not allowed

This is how it appears in *_types.cpp file:

    const ::bond::Metadata UUID::Schema::metadata
        = UUID::Schema::GetMetadata();

and this is how it appears in the generated *_reflection.h header file which is included by *_types.cpp:

    struct UUID::Schema
    {
        typedef ::bond::no_base base;

        QUINE_SCHEMAS_API
        static const ::bond::Metadata metadata;
---snip---

So how is one supposed to use the struct-related functionality together with --export-attribute ?

@chwarr
Copy link
Member

chwarr commented Apr 21, 2018

Generating the struct code in a static library is already available. There's an example that demonstrates this. It's written in CMake, so you will need to adapt this to whatever build system you're using.

Metadata access is working in the DLL example, so there's probably something slightly different between that example and the UUID project. Could this project be minimized to just the problem so that we can look deeper?

@zvrba
Copy link
Author

zvrba commented Apr 22, 2018

I want to have both struct code (functions that end up in *_types.{h,cpp} and metadata code (reflection/apply files) in a DLL. I can get only metadata code to work.

To get a minimal example, modify the DLL example you referenced as follows:

  • add some enum to the .bond file
  • in main() add std::cout << ToString(examples::dll::SomeEnumValue)

When the generated code is built as static library, everything works. But I'm using the same code in different executables, and I'd like to both have the option of easily upgrading the schema as well as the advantage of the code being loaded only once in memory (shared across EXEs).

chwarr added a commit to chwarr/bond that referenced this issue Apr 24, 2018
@chwarr
Copy link
Member

chwarr commented Apr 24, 2018

We were able to reproduce the mismatched DLL export problem with the details you provided. @ara-ayvazyan is working on a fix.

@chwarr
Copy link
Member

chwarr commented Apr 25, 2018

This has been fixed in commit 101a8f5. If you want to get that fix today, you'll need to build gbc from source. We're working on a release, but the target date is in a few weeks.

@zvrba
Copy link
Author

zvrba commented Apr 26, 2018

Cool, thanks for the quick fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants