on linking gnu and msvc etc

Jeffrey Russell Horner jhorner@cs.utk.edu
Fri Sep 18 22:21:00 GMT 1998

>On Wed, 16 Sep 1998, Jeffrey Russell Horner wrote:
>[ on linking gnu and msvc etc ]
>> I don't know if this discussion is relevant to the list, but you can
>> email me if you need more help.
>I believe this is very relevant, and quite in demand! Please share your
>experiences and expecially the list of gotchas. I and lots of others will
>appreciate it.
>Thanks in advance,

Okay, I've changed the name of the thread... hope there's no opposition.

My purpose of using cygwin32 gcc and various NT compilers was to
evaluate the performance of my project's code on NT (plug:
www.netlib.org/atlas). It's mixed c and fortran77 code. Thus, I felt
myself being thwopped on the head day in and day out when trying
various combinations and permutations of compilers and languages. It
was not fun, but I learned plenty.  Surprisingly enough, out of all the
compilers we tried, gcc outperformed them. G77 still needs some work,

Here are various things I found out about linking together MSVC/C++ and
CYGWIN32 gcc objects (I'm actually running egcs 1.0.2 for cygwin32
b19). Both cygnus gcc and msvc objects default to using the cdecl
calling convention, and they use the same symbol naming convention of
prepending an underscore to the symbol name. So that makes things nice:

gcc -c gcc_func.c

cl -c vcc_app.c

cl -Fevcc_app.exe vcc_app.obj gcc_func.o

Cl with complain about the gcc_func.o not being a recognized source file type,
but it will default to assuming it's an object. Also notice that all symbols
in a gcc object will be resolved by the msvc linker, and of course here's where
most problems leak in.

Now, with Visual C++, one notices that when wanting to invoke ANY external
c function, the symbol name for that c function gets mangled. To get around
that you must declare the function prototype this way:

in vcc_app.cpp:
extern "C" gcc_func();

I'm not sure that this declaration can be used for other NT c++
compilers, though.

The gotchas that I've found so far have been minimal. Gcc and msvc have
different implementations of stdin, stout, etc so fat chance of
referencing them from gcc objects. However, one is still able to call
printf from gcc objects. Some arithmetic operations invoked in a gcc
object are actually function calls themselves, defined in libgcc1.c.
But for this release of gcc I don't find that problem at all.

As far as DLL's, I haven't worked with them at all. 

I've discovered many other things about compiling and linking objects
on NT , and I am more than happy to share my experiences with the
list.  But, I'm afraid that my email might get pretty lengthy when
doing a complete brain dump, so let me know if you have more questions.
I'd also be happy to share source code.


Jeff Horner        The University of Tennessee     CS Department
423 974-2841            fax: 423 974-8296         104 Ayres Hall
http://www.cs.utk.edu/~jhorner/        Knoxville, TN  37996-1301              
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

More information about the Cygwin mailing list