I'm using objcopy to convert a text file into an object file for linking with my DLL using MinGW and MinGW-64. With MinGW, everything works fine, but with MinGW-64 I get errors of the form "undefined reference to `binary_src_glsl_RGBtoHSV_glsl_end'". The original file is called RGBtoHSV.glsl and is in the folder binary\src\glsl. In the output from objcopy the variable name is _binary_src_glsl_RGBtoHSV_glsl_end. My code to access the variables for that file is as follows:
extern "C" const char binary_src_glsl_RGBtoHSV_glsl_start;
extern "C" const char binary_src_glsl_RGBtoHSV_glsl_end;
const std::string RGBtoHSV = std::string(&binary_src_glsl_RGBtoHSV_glsl_start, &binary_src_glsl_RGBtoHSV_glsl_end-&binary_src_glsl_RGBtoHSV_glsl_start);
If I change the variable names so that they have an undercore in front, e.g.:
extern "C" const char _binary_src_glsl_RGBtoHSV_glsl_start;
Then that symbol is found in MinGW-64, but not in MinGW (32 bits). I did try the --remove-remove-leading-char option to objcopy but that had no effect. As far as I can see, my options are to either add an underscore to the variable names generated by objcopy by using "--prefix-symbol _" when building for MinGW 32 bits, in which case the above variable name will work in 32 and 64 bits.
Is there another solution to this problem? Ideally I'd like something along the lines of
extern "C" fix_underscore_problem const char binary_src_glsl_RGBtoHSV_glsl_start;
Where fix_underscore_problem is a magic command to fix the leading underscore problem.
Update (2012-07-01): Using the advice given in Adding leading underscores to assembly symbols with GCC on Win32? I changed by header file to use
extern "C" const char binary_src_glsl_RGBtoHSV_glsl_start asm("_binary_src_glsl_RGBtoHSV_glsl_start");
This seems to fix the problem, but now I wonder how portable this is. Is there an equivalent syntax available in MSVC or a C++ standard way of doing this?