I was able to get it working. I wound up using a combination of GCC's
g++ and Microsoft's Visual C++ compiler. COFF object file output in
GCC was the key.
Here's are the steps for a sample build on a Windows 7 machine 64-bit:
(1) Install MinGW on Windows with GCC and bases.
(2) Create the two source files below.
(3) Launch a command prompt that has the path for visual studio tools.
(4) Execute these steps:
(a) C:\>PATH=%PATH%;c:\mingw\bin\
(b) C:\>g++ -c -gcoff list.cpp -o list.obj
(c) C:\>cl /c main.cpp
(d) C:\>link main.obj list.obj /OUT:main.exe
(e) C:\>main
!ne
!wo
!three
=========list.cpp========
#define RW(x) (char []) { x }
extern "C"
{
char* list[] =
{
RW("one"),
RW("two"),
RW("three")
};
}
===========END===========
=========main.cpp========
#include <stdlib.h>
#include <stdio.h>
extern "C"
{
extern char* list[];
}
int main(int argc, char* argv[])
{
for (int i = 0; list
; i++)
{
list[0] = '!'; // Prove it's read-write
puts(list); // Show it
}
}
===========END===========
g++ and cl working hand-in-hand. Gotta love it.
Note: It also works on list.c and main.c using gcc and cl. To do so,
remove the extern "C" parts.
Best regards,
Rick C. Hodgin