C++ with OpenWatcom
I'm trying to build a c++, and indeed I can build and link a very simple C++ code, but any header I try to add, I get errors like:
owcc -c -bnone -march=i86 -fno-stack-check -fnostdlib -Wc,-fpi87 -Wc,-zls -Wc,-x -Wall -Wextra -I/home/rafael2k/programs/devel/elks/libc/include -I/home/rafael2k/programs/devel/elks/elks/include -I/home/rafael2k/programs/devel/elks/libc/include/watcom -D__ELKS__ -DNDEBUG -o test.obj test.cpp
/home/rafael2k/programs/devel/elks/libc/include/watcom/stdarg.h(28): Error! E059: col(18) unable to open 'cstdarg'
/home/rafael2k/programs/devel/elks/libc/include/watcom/stdarg.h(28): Note! N393: col(18) included from /home/rafael2k/programs/devel/elks/libc/include/stdio.h(5)
/home/rafael2k/programs/devel/elks/libc/include/watcom/stdarg.h(28): Note! N393: col(18) included from test.cpp(4)
/home/rafael2k/programs/devel/elks/libc/include/watcom/stdarg.h(30): Error! E241: col(12) class or namespace 'std' has not been declared
/home/rafael2k/programs/devel/elks/libc/include/watcom/stdarg.h(30): Error! E926: col(12) syntax error: 'std::va_list' has not been declared as a member
/home/rafael2k/programs/devel/elks/libc/include/stdio.h(105): Error! E498: col(35) syntax error before 'lineptr'; probable cause: incorrectly spelled type name
/home/rafael2k/programs/devel/elks/libc/include/stdio.h(107): Error! E498: col(34) syntax error before 'lineptr'; probable cause: incorrectly spelled type name
/home/rafael2k/programs/devel/elks/libc/include/stdio.h(137): Error! E498: col(51) syntax error before 'va_list'; probable cause: incorrectly spelled type name
/home/rafael2k/programs/devel/elks/libc/include/stdio.h(138): Error! E498: col(47) syntax error before 'va_list'; probable cause: incorrectly spelled type name
/home/rafael2k/programs/devel/elks/libc/include/stdio.h(139): Error! E498: col(56) syntax error before 'va_list'; probable cause: incorrectly spelled type name
/home/rafael2k/programs/devel/elks/libc/include/stdio.h(151): Error! E121: col(41) syntax error
/home/rafael2k/programs/devel/elks/libc/include/stdio.h(159): Error! E498: col(52) syntax error before 'va_list'; probable cause: incorrectly spelled type name
/home/rafael2k/programs/devel/elks/libc/include/stdio.h(160): Error! E498: col(29) syntax error before 'va_list'; probable cause: incorrectly spelled type name
/home/rafael2k/programs/devel/elks/libc/include/stdio.h(161): Error! E498: col(40) syntax error before 'va_list'; probable cause: incorrectly spelled type name
test.cpp(13): Error! E121: col(1) syntax error
Error: Compiler returned a bad status compiling 'test.cpp'
but any header I try to add, I get errors like:
First, I believe this could easily turn into a very long road, trying to get C++ programs running for ELKS. If this is for MicroWeb, I suggest taking a hard look at the existing source to make sure that even after the arduous process of getting any C++ programs running, its DOS architecture is analyzed so that the program can be converted without a major rewrite.
That said, the way you'll need to move forward on any efforts is to read the error messages, starting with just the first error. My plate is very full and I won't have time to solve all the C++ related problems likely to come up (but am glad to help when I can).
The first error is "unable to open 'cstdarg'". That means you need to go find cstdarg somewhere in the OWC source (there may be multiple directories, and the header may pull in other headers), and make sure the compiler has additional include directories specified. This can get tricky since OWC supports 16- and 32- bit compilations and a number of different targets.
After you get through that, you'll likely start requiring many more compiler-generated call to internal routines written in ASM, or possibly C++. These routines will need to be pulled out into another directory and compiled/assembled. Read the error messages, that'll tell you what needs to be done.
C++ requires run-time memory allocation and constructor/destructors, and a huge standard library. All of this needs to be looked at. I have no idea how much or little MicroWeb uses, hopefully very little and is only using the C++ language for its very good features, without pulling in tons of class libraries or using specialized C++ features like RTTI (run time type information) or exceptions.
On the ELKS OpenWatcom C compiler/library port, after a long porting process and coming to understand how OWC worked, all the required files were moved to libc/watcom, libc/include/watcom, libc/watcom/asm and libc/watcom/syscall, but ultimately only because of the confusion that started occurring with the mess of C header files written specially for ia16-elf-gcc vs OWC vs C86. You'll probably want to keep all these changes on a fork on your system, as ELKS headers don't support any kind of C++ special requirements, such as extern "C" { ... } around every header, etc. These issues will want to be handled in the MicroWeb source, not the ELKS C library. We can look further into next steps after you've got more running and have learned how big a project this is.
Thanks for the message @ghaerr. This is not top-priority for me, I just wanted to give a shot. And indeed, it is for MicroWeb. I'll take a look carefully in Watcom includes and the error messages I'm seeing, and see how far I can get without spending lots of time on this.
This issue is related to: https://github.com/jhhoward/MicroWeb/issues/40