ReactiveX / RxCpp

Reactive Extensions for C++
Apache License 2.0
3.03k stars 390 forks source link

Is it possible to use RxCpp as a module? #557

Closed serg06 closed 3 years ago

serg06 commented 3 years ago

I'm using VS 2022 Preview 3.1.

I tried just importing it:

// main.cpp
import "RxCpp/rx.hpp";

but got some errors like:

Severity    Code    Description Project File    Line    Suppression State
Error (active)  E3344   module file mapping for 'RxCpp/rx.hpp' is invalid   TestProject D:\repo\test\main.cpp   7   
Error   C7612   could not find header unit for 'D:\repo\test\SDK\RxCpp\Rx\v2\src\RxCpp/rx.hpp'  TestProject D:\repo\test\main.cpp   7   

Then I tried creating a module for it:

// RxCpp.ixx
export module RxCpp;
#pragma once
#include "common.h"
#include "RxCpp/rx.hpp"

export namespace rxcpp2 {
    using namespace rxcpp;
}

// main.cpp
import RxCpp;
void test(rxcpp2::observable<int>) {}

But I got a different error:

Severity    Code    Description Project File    Line    Suppression State
Error   C2039   'observable': is not a member of 'rxcpp2'   TestProject D:\repo\test\main.cpp   116 

Is there a way to do it?

serg06 commented 3 years ago

Got it working: https://github.com/serg06/RxModuleTest/blob/master/RxModuleTest/RxModuleTest.cpp

Key points:

Unfortunately I still haven't found a way to import them like this:

import RxCpp
serg06 commented 3 years ago

Update: Got it working! See: https://github.com/serg06/RxModuleTest/blob/master/RxModuleTest/RxModuleTest.cpp

Maybe we can add this to the library? I don't know if it's possible with CMake.