JuliaHubOSS / llvm-cbe

resurrected LLVM "C Backend", with improvements
Other
838 stars 144 forks source link

c++ code does not compile #183

Open rfx77 opened 1 year ago

rfx77 commented 1 year ago

This is my code:

#include <iostream>
#include <memory>

using namespace std;

#define PROPERTY(t,n)  __declspec( property( put = property__set_##n, get = property__get_##n ) ) t n;\
        typedef t property__tmp_type_##n

#define GET(n) property__tmp_type_##n property__get_##n()
#define SET(n) void property__set_##n(const property__tmp_type_##n& value)

#define RWPROPERTY(t,n,g, s) PROPERTY(t,n);\
    GET(n) g;\
    SET(n) s;

class Test {
private:
    int val = 0;
public:
    RWPROPERTY(int, foo, {return val;}, {val = value;});
};

int main() {
    Test(test);
    test.foo = 1;

    std::cout << "val is: " << test.foo << endl;

    return 0;
}

commands for compilation:

clang++ -fdeclspec -S -emit-llvm -g main.cpp ./llvm-cbe main.ll g++ -fpermissive main.cbe.c

The output of g++ is:

g++ -fpermissive  main.cbe.c
/test/main.cpp: In function 'int main()':
/test/main.cpp:31:79: warning: invalid conversion from 'const void*' to 'void*' [-fpermissive]
   31 |     std::cout << "val is: " << test.foo << endl;
      |                                                                               ^
      |                                                                               |
      |                                                                               const void*
main.cbe.c:108:80: note:   initializing argument 2 of 'void* _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(void*, void*)'
  108 | void* _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(void* _28, void* _29);
      |                                                                          ~~~~~~^~~
/usr/bin/ld: /tmp/ccvMifE1.o: in function `__cxx_global_var_init()':
main.cbe.c:(.text+0x13): undefined reference to `_ZNSt8ios_base4InitC1Ev(void*)'
/usr/bin/ld: main.cbe.c:(.text+0x2e): undefined reference to `_ZNSt8ios_base4InitD1Ev(void*)'
/usr/bin/ld: main.cbe.c:(.text+0x36): undefined reference to `__cxa_atexit(void*, void*, void*)'
/usr/bin/ld: /tmp/ccvMifE1.o: in function `main':
main.cbe.c:(.text+0x8a): undefined reference to `_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(void*, void*)'
/usr/bin/ld: main.cbe.c:(.text+0xae): undefined reference to `_ZNSolsEi(void*, unsigned int)'
/usr/bin/ld: main.cbe.c:(.text+0xbd): undefined reference to `_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(void*)'
/usr/bin/ld: main.cbe.c:(.text+0xc8): undefined reference to `_ZNSolsEPFRSoS_E(void*, void*)'
collect2: error: ld returned 1 exit status

Maybe someone can help.

vtjnash commented 1 year ago

The output of CBE is C89 code, and is therefore not meant to be compiled with a C++ compiler (which is not a compatible language), and is not legal to link to a C++ stdlib (or any other existing shared libraries for that matter)