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++ code does not compile #183

Open
rfx77 opened this issue Aug 28, 2023 · 1 comment
Open

c++ code does not compile #183

rfx77 opened this issue Aug 28, 2023 · 1 comment

Comments

@rfx77
Copy link

rfx77 commented Aug 28, 2023

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
Copy link
Member

vtjnash commented Aug 28, 2023

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)

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

No branches or pull requests

2 participants