This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gcc-mingw cannot link with MSVC compiled static libraries


Hi all,

I recently ugrade to 
gcc                     3.3.1-2
gcc-mingw               20030911-3

But now got some problems linking MSVC compiled static libraries with the 
gcc and the -mno-cygwin option

here is an example where MS.c/MS.h which contains a very simple function 
(plus, see code below) is compiled into MS.lib using Visual Studio

$ CL /c MS.c
$ LINK -lib MS.obj

I then obtain MS.lib

$ nm MS.lib
MS.obj:
00000000 i .drectve
00000000 t .text
000a2306 a @comp.id
00000000 T _plus


Then I take a main.c source that calls the function 'plus' but compiled 
with gcc.
$ gcc -mno-cygwin main.c -o main MS.lib
Warning: .drectve `-defaultlib:LIBC ' unrecognized
Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized
Cannot export _plus: symbol not found
collect2: ld returned 1 exit status

This used to work with the previous versions of GCC/Mingw I was using.
Is there something I am doing wrong?
Is it possible that the upgrade to the new version of gcc/mingw went 
wrong?

Here is the output of gcc in verbose mode:
$ gcc -v -mno-cygwin main.c -o main MS.lib
Reading specs from /usr/lib/gcc-lib/i686-pc-mingw32/3.3.1/specs
Configured with: /netrel/src/gcc-3.3.1-2/configure 
--enable-languages=c,c++,f77,java --enable-libgcj --enable-threads=posix 
--with-system-zlib --enable-nls --without-included-gettext 
--enable-interpreter --enable-sjlj-exceptions 
--disable-version-specific-runtime-libs --enable-shared 
--build=i686-pc-linux --host=i686-pc-cygwin --target=i686-pc-cygwin 
--prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib 
--includedir=/nonexistent/include -libexecdir=/usr/sbin
Thread model: posix
gcc version 3.3.1 (cygming special)
 /usr/lib/gcc-lib/i686-pc-mingw32/3.3.1/cc1.exe -quiet -v -D__GNUC__=3 
-D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=1 -D__MSVCRT__ -D__MINGW32__ 
-DWIN32 -D_WIN32 -D__WIN32 -D__WIN32__ -DWINNT -idirafter 
/usr/lib/gcc-lib/i686-pc-mingw32/3.3.1/../../../../include/w32api 
-idirafter 
usr/lib/gcc-lib/i686-pc-mingw32/3.3.1/../../../../i686-pc-mingw32/lib/../../include/w32api 
main.c -quiet -dumpbase main.c -mno-cygwin -auxbase main -version -o 
tmp/ccit4dum.s
GNU C version 3.3.1 (cygming special) (i686-pc-cygwin)
        compiled by GNU C version 3.3.1 (cygming special).
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=130946
ignoring nonexistent directory "/usr/local/include/mingw"
ignoring duplicate directory "/usr/include/mingw"
ignoring duplicate directory 
"/usr/i686-pc-mingw32/lib/../../include/w32api"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/include
 /usr/i686-pc-mingw32/include
 /usr/include/w32api
End of search list.
 
/usr/lib/gcc-lib/i686-pc-mingw32/3.3.1/../../../../i686-pc-mingw32/bin/as.exe 
--traditional-format -o /tmp/ccGGljbC.o /tmp/ccit4dum.s
 /usr/lib/gcc-lib/i686-pc-mingw32/3.3.1/collect2.exe -Bdynamic -o main.exe 
/usr/lib/gcc-lib/i686-pc-mingw32/3.3.1/../../../../i686-pc-mingw32/lib/crt2.o 
/usr/lib/gcc-lib/i686-pc-mingw32/3.3.1/crtbegin.o 
-L/usr/lib/gcc-lib/i686-pc-mingw32/3.3.1 
-L/usr/lib/gcc-lib/i686-pc-mingw32/3.3.1/../../../../i686-pc-mingw32/lib 
-L/usr/lib/gcc-lib/i686-pc-mingw32/3.3.1/../../.. /tmp/ccGGljbC.o MS.lib 
-lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -lmingw32 -luser32 
-lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex 
-lmsvcrt /usr/lib/gcc-lib/i686-pc-mingw32/3.3.1/crtend.o
Warning: .drectve `-defaultlib:LIBC ' unrecognized
Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized
Cannot export _plus: symbol not found
collect2: ld returned 1 exit status


-------------------------------------------------------------------------------
Now here are the sources...

MS.c:
#include "MS.h"

__declspec(dllexport)
int plus(const int a, const int b)
{
        return a+b;
}

MS.h:
#ifdef __MS_H_
#define __MS_H_ 1

int plus(const int a, const int b);

#endif

and main.c:
#include "MS.h"

int main(int argc, char *argv[])
{
        int a = 5;
        int b = 6;

        int c = plus(a,b);

        printf ("%d + %d = %d\n", a, b, c);

        return 0;
}



-------------------------------------------------------------------------------------------------------------
Jean-Michel Rouet (PhD), Senior Scientist
Philips France / Medical Imaging Systems (Medisys) Research Group
51, rue Carnot - BP 301 - 92156 Suresnes Cedex - France

Phone:  (+33) 1.47.28.36.13      Fax: (+33) 1.47.28.36.00
mailto:Jean-Michel.Rouet@philips.com


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]