hra1129 / msx_basic_compiler

MSX-BASICコンパイラ
MIT License
22 stars 2 forks source link

Building on Linux... #18

Open MBilderbeek opened 5 months ago

MBilderbeek commented 5 months ago

Hi, thanks for your work! I'm trying to compile the code on Linux and I ran into a few issues;

  1. expressions/expression_operator_power.cpp needs #include <cmath> and use std::pow on/around line 38
  2. With this, all files compile but I get linker errors:
    /usr/bin/ld: compiler.o: in function `CCIRCLE::CCIRCLE()':
    compiler.cpp:(.text._ZN7CCIRCLEC2Ev[_ZN7CCIRCLEC5Ev]+0x1b): undefined reference to `vtable for CCIRCLE'
    /usr/bin/ld: compiler.o: in function `CGET::CGET()':
    compiler.cpp:(.text._ZN4CGETC2Ev[_ZN4CGETC5Ev]+0x1b): undefined reference to `vtable for CGET'
    /usr/bin/ld: compiler.o: in function `CSETADJUST::CSETADJUST()':
    compiler.cpp:(.text._ZN10CSETADJUSTC2Ev[_ZN10CSETADJUSTC5Ev]+0x1b): undefined reference to `vtable for CSETADJUST'
    /usr/bin/ld: compiler.o: in function `CSETBEEP::CSETBEEP()':
    compiler.cpp:(.text._ZN8CSETBEEPC2Ev[_ZN8CSETBEEPC5Ev]+0x1b): undefined reference to `vtable for CSETBEEP'
    /usr/bin/ld: compiler.o: in function `CSETPROMPT::CSETPROMPT()':
    compiler.cpp:(.text._ZN10CSETPROMPTC2Ev[_ZN10CSETPROMPTC5Ev]+0x1b): undefined reference to `vtable for CSETPROMPT'
    /usr/bin/ld: compiler.o: in function `CSETSCREEN::CSETSCREEN()':
    compiler.cpp:(.text._ZN10CSETSCREENC2Ev[_ZN10CSETSCREENC5Ev]+0x1b): undefined reference to `vtable for CSETSCREEN'
    /usr/bin/ld: compiler.o: in function `CSETTITLE::CSETTITLE()':
    compiler.cpp:(.text._ZN9CSETTITLEC2Ev[_ZN9CSETTITLEC5Ev]+0x1b): undefined reference to `vtable for CSETTITLE'
    /usr/bin/ld: expressions/expression.o: in function `CEXPRESSION_POINT::CEXPRESSION_POINT()':
    expression.cpp:(.text._ZN17CEXPRESSION_POINTC2Ev[_ZN17CEXPRESSION_POINTC5Ev]+0x1b): undefined reference to `vtable for CEXPRESSION_POINT'

    I have tried to add virtual emtpy destructor definitions here and there, but that didn't seem to help enough... any idea?

hra1129 commented 5 months ago

Thanks!

I have added the include you suggested. In addition, changed int i to size_t i in compile.h. With these modifications, both compilation and linking are complete in my environment (gcc 11.4). Please try it.

MBilderbeek commented 5 months ago

Thanks for trying to solve the issue.

I still get the following link errors:

usr/bin/ld: compiler.o: warning: relocation against `_ZTV10CSETPROMPT' in read-only section `.text._ZN10CSETPROMPTC2Ev[_ZN10CSETPROMPTC5Ev]'
/usr/bin/ld: compiler.o: in function `CCIRCLE::CCIRCLE()':
compiler.cpp:(.text._ZN7CCIRCLEC2Ev[_ZN7CCIRCLEC5Ev]+0x1b): undefined reference to `vtable for CCIRCLE'
/usr/bin/ld: compiler.o: in function `CGET::CGET()':
compiler.cpp:(.text._ZN4CGETC2Ev[_ZN4CGETC5Ev]+0x1b): undefined reference to `vtable for CGET'
/usr/bin/ld: compiler.o: in function `CCLOSE::CCLOSE()':
compiler.cpp:(.text._ZN6CCLOSEC2Ev[_ZN6CCLOSEC5Ev]+0x1b): undefined reference to `vtable for CCLOSE'
/usr/bin/ld: compiler.o: in function `COPEN::COPEN()':
compiler.cpp:(.text._ZN5COPENC2Ev[_ZN5COPENC5Ev]+0x1b): undefined reference to `vtable for COPEN'
/usr/bin/ld: compiler.o: in function `CSETADJUST::CSETADJUST()':
compiler.cpp:(.text._ZN10CSETADJUSTC2Ev[_ZN10CSETADJUSTC5Ev]+0x1b): undefined reference to `vtable for CSETADJUST'
/usr/bin/ld: compiler.o: in function `CSETBEEP::CSETBEEP()':
compiler.cpp:(.text._ZN8CSETBEEPC2Ev[_ZN8CSETBEEPC5Ev]+0x1b): undefined reference to `vtable for CSETBEEP'
/usr/bin/ld: compiler.o: in function `CSETPROMPT::CSETPROMPT()':
compiler.cpp:(.text._ZN10CSETPROMPTC2Ev[_ZN10CSETPROMPTC5Ev]+0x1b): undefined reference to `vtable for CSETPROMPT'
/usr/bin/ld: compiler.o: in function `CSETSCREEN::CSETSCREEN()':
compiler.cpp:(.text._ZN10CSETSCREENC2Ev[_ZN10CSETSCREENC5Ev]+0x1b): undefined reference to `vtable for CSETSCREEN'
/usr/bin/ld: compiler.o: in function `CSETTITLE::CSETTITLE()':
compiler.cpp:(.text._ZN9CSETTITLEC2Ev[_ZN9CSETTITLEC5Ev]+0x1b): undefined reference to `vtable for CSETTITLE'
/usr/bin/ld: expressions/expression.o: in function `CEXPRESSION_POINT::CEXPRESSION_POINT()':
expression.cpp:(.text._ZN17CEXPRESSION_POINTC2Ev[_ZN17CEXPRESSION_POINTC5Ev]+0x1b): undefined reference to `vtable for CEXPRESSION_POINT'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [Makefile:162: msx_bacon] Fout 1
$ g++ --version
g++ (Debian 13.2.0-13) 13.2.0
hra1129 commented 5 months ago

No error occurs in my environment.

gcc version 11.4.0

On Ubuntu 22.04 on WSL, gcc 11.4 seems to be the standard, so 13.2 cannot be easily tried.

MBilderbeek commented 5 months ago

Hi, thanks for looking into this. I get the same link errors when using g++-11....

$ g++-11 --version
g++-11 (Debian 11.4.0-7) 11.4.0

so giving

/usr/bin/ld: compiler.o: warning: relocation against `_ZTV10CSETPROMPT' in read-only section `.text._ZN10CSETPROMPTC2Ev[_ZN10CSETPROMPTC5Ev]'
/usr/bin/ld: compiler.o: in function `CCIRCLE::CCIRCLE()':
compiler.cpp:(.text._ZN7CCIRCLEC2Ev[_ZN7CCIRCLEC5Ev]+0x1b): undefined reference to `vtable for CCIRCLE'
/usr/bin/ld: compiler.o: in function `CGET::CGET()':
compiler.cpp:(.text._ZN4CGETC2Ev[_ZN4CGETC5Ev]+0x1b): undefined reference to `vtable for CGET'
/usr/bin/ld: compiler.o: in function `CCLOSE::CCLOSE()':
compiler.cpp:(.text._ZN6CCLOSEC2Ev[_ZN6CCLOSEC5Ev]+0x1b): undefined reference to `vtable for CCLOSE'
/usr/bin/ld: compiler.o: in function `COPEN::COPEN()':
compiler.cpp:(.text._ZN5COPENC2Ev[_ZN5COPENC5Ev]+0x1b): undefined reference to `vtable for COPEN'
/usr/bin/ld: compiler.o: in function `CSETADJUST::CSETADJUST()':
compiler.cpp:(.text._ZN10CSETADJUSTC2Ev[_ZN10CSETADJUSTC5Ev]+0x1b): undefined reference to `vtable for CSETADJUST'
/usr/bin/ld: compiler.o: in function `CSETBEEP::CSETBEEP()':
compiler.cpp:(.text._ZN8CSETBEEPC2Ev[_ZN8CSETBEEPC5Ev]+0x1b): undefined reference to `vtable for CSETBEEP'
/usr/bin/ld: compiler.o: in function `CSETPROMPT::CSETPROMPT()':
compiler.cpp:(.text._ZN10CSETPROMPTC2Ev[_ZN10CSETPROMPTC5Ev]+0x1b): undefined reference to `vtable for CSETPROMPT'
/usr/bin/ld: compiler.o: in function `CSETSCREEN::CSETSCREEN()':
compiler.cpp:(.text._ZN10CSETSCREENC2Ev[_ZN10CSETSCREENC5Ev]+0x1b): undefined reference to `vtable for CSETSCREEN'
/usr/bin/ld: compiler.o: in function `CSETTITLE::CSETTITLE()':
compiler.cpp:(.text._ZN9CSETTITLEC2Ev[_ZN9CSETTITLEC5Ev]+0x1b): undefined reference to `vtable for CSETTITLE'
/usr/bin/ld: expressions/expression.o: in function `CEXPRESSION_POINT::CEXPRESSION_POINT()':
expression.cpp:(.text._ZN17CEXPRESSION_POINTC2Ev[_ZN17CEXPRESSION_POINTC5Ev]+0x1b): undefined reference to `vtable for CEXPRESSION_POINT'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE

I wouldn't expect it to make a difference with link errors though.

What I do is this: $ cd msx_basic_compiler $ make and this gives me the above results.

hra1129 commented 5 months ago

Where did you use the script to compile? If you used Makefile, you must run python makefile_gen.py beforehand or you may get an error.

If you used Linux/compile.sh, you will not get an error.

For now, I have updated the Makefile.