From 7779876a6b06755e3bb2c94ee3ded50635bcb0fa Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 1 Feb 2018 14:06:55 -0500 Subject: c++: add extern declaration to the generated file The extern declaration affects how the C++ compiler does name mangling of global variables. With: $ g++ -c -Wall -std=c++11 -o osx2win32.o osx2win32.cc $ nm osx2win32.o | grep code_map_osx_to_win32 0000000000000000 B code_map_osx_to_win32 00000000000000a1 t _GLOBAL__sub_I_code_map_osx_to_win32 Without: $ g++ -c -Wall -std=c++11 -o osx2win32.o osx2win32.cc $ nm osx2win32.o | grep code_map_osx_to_win32 0000000000000000 b _ZL21code_map_osx_to_win32 Not that unlike C, without "extern" you get a local variable ("b"), while "extern" is needed to get a global! Signed-off-by: Paolo Bonzini --- tools/keymap-gen | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/keymap-gen b/tools/keymap-gen index 4d583a3..5d4dca3 100755 --- a/tools/keymap-gen +++ b/tools/keymap-gen @@ -641,10 +641,12 @@ class CppLanguageGenerator(CLanguageGenerator): totypename = "const " + self.strtypename if totype == self.TYPE_STRING else self.inttypename if fromtype == self.TYPE_INT: print("#include ") + print("extern const std::vector<%s> %s;" % (totypename, varname)); print("const std::vector<%s> %s = {" % (totypename, varname)) else: print("#include ") print("#include ") + print("extern const std::map %s;" % (totypename, varname)) print("const std::map %s = {" % (totypename, varname)) def _array_end(self, fromtype, totype): -- cgit v1.1