Link CL and CC

R

Rick C. Hodgin

Is it possible to link object files generated from Microsoft's C compiler and GNU's C Compiler?

Best regards,
Rick C. Hodgin
 
R

Rick C. Hodgin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top