stardot / b-em

An opensource BBC Micro emulator for Win32 and Linux
http://stardot.org.uk/forums/viewtopic.php?f=4&t=10823
GNU General Public License v2.0
112 stars 56 forks source link

build issues when cpp calling to c in debugger_symbols #195

Open Pinjontall94 opened 1 year ago

Pinjontall94 commented 1 year ago

I'm trying to get b-em built on fedora 37, but even after ensuring I have both development libs for zlib and allegro 5.2, I'm receiving the following error. This is apparently when CPP code for debugger symbols encounters a malloc call. Adding includes for cstdlilb where specified did not alleviate the problem, sadly!

In file included from /usr/include/c++/12/ext/string_conversions.h:41,
                 from /usr/include/c++/12/bits/basic_string.h:3960,
                 from /usr/include/c++/12/string:53,
                 from debugger_symbols.h:29,
                 from debugger_symbols.cpp:4:
/usr/include/c++/12/cstdlib:151:11: error: ‘malloc’ has not been declared in ‘::’
  151 |   using ::malloc;
      |           ^~~~~~
debugger_symbols.h: In constructor ‘symbol_entry::symbol_entry(const char*, uint32_t)’:
debugger_symbols.h:48:30: error: ‘malloc’ was not declared in this scope
   48 |             symbol = (char *)malloc(strlen(_symbol) + 1);
      |                              ^~~~~~
debugger_symbols.h:30:1: note: ‘malloc’ is defined in header ‘<cstdlib>’; did you forget to ‘#include <cstdlib>’?
   29 | #include <string>
  +++ |+#include <cstdlib>
   30 | 
In file included from cpu_debug.h:6,
                 from debugger_symbols.cpp:6:
/usr/include/c++/12/stdlib.h: At global scope:
/usr/include/c++/12/stdlib.h:65:12: error: ‘malloc’ has not been declared in ‘std’
   65 | using std::malloc;
      |            ^~~~~~
debugger_symbols.cpp: In function ‘bool symbol_find_by_name(symbol_table*, const char*, uint32_t*, const char**)’:
debugger_symbols.cpp:143:23: error: ‘malloc’ was not declared in this scope
  143 |     char *n = (char *)malloc(i + 1);
      |                       ^~~~~~
debugger_symbols.cpp:7:1: note: ‘malloc’ is defined in header ‘<cstdlib>’; did you forget to ‘#include <cstdlib>’?
    6 | #include "cpu_debug.h"
  +++ |+#include <cstdlib>
    7 | 
make[1]: *** [Makefile:2390: debugger_symbols.o] Error 1
SteveFosdick commented 1 year ago

Do you know which compiler this is using, i.e. gcc (g++) or clang?

Could you try adding #include <cstdlib> to debugger_symbols.h, probably in the part that makes reference to malloc so, for example, before #include <map> and #include <string>.