链接的Visual C反对票的MinGW的静态库 [英] Link Visual C againts MinGW's static library

查看:119
本文介绍了链接的Visual C反对票的MinGW的静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何才能链接的Visual C ++(2010年),由的MinGW 创建一个静态库的控制台应用程序( *一个格式)?它是用Visual C ++ 2010兼容?

How can one link Visual C++ (2010) console app with a STATIC library created by MinGW (*.a format)? Is it compatible with Visual C++ 2010?

感谢您。

推荐答案

这是不兼容的。

但是,如果从库中提取所有的目标文件(使用 AR ),在VC ++链接器能够处理那些(我测试过,虽然我用cygwin的GCC,而不是MinGW的GCC)。请注意,您可能仍然有名字改编的问题,如果你不使用的externC

However, if you extract all the object files from the library (use ar), the VC++ linker is able to deal with those (I tested it, although I used cygwin gcc rather than mingw gcc). Note that you may still have name mangling problems if you don't use extern "C".

您当然可以用VC ++的 LIB.EXE 工具,使这些成VC ++格式的静态库。

You may of course use VC++'s LIB.EXE tool to make these into a static library in VC++ format.

作为@迈克尔所指出的,你一定会出现问题,如果你尝试通过不同的编译器内置模块之间的非POD C ++对象。造成这种情况的解决方法是一样的DLL情况下:写有相同的编译器(在这种情况下MinGW的)建立了一个包装,暴露了一个C兼容接口与其他工具链可用

As @Michael points out, you will definitely have problems if you try to pass non-POD C++ objects between modules built with different compilers. The fix for this is the same as the DLL case: write a wrapper built with the same compiler (in this case mingw) that exposes a C-compatible interface usable from other toolchains.

// minimal.cpp
extern "C" int m(void) { return 7; }


$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-pc-cygwin/4.5.0/lto-wrapper.exe
Target: i686-pc-cygwin
Configured with: /gnu/gcc/releases/respins/4.5.0-1/gcc4-4.5.0-1/src/gcc-4.5.0/co
nfigure --srcdir=/gnu/gcc/releases/respins/4.5.0-1/gcc4-4.5.0-1/src/gcc-4.5.0 --
prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdi
r=/usr/lib --datadir=/usr/share --localstatedir=/var --sysconfdir=/etc --dataroo
tdir=/usr/share --docdir=/usr/share/doc/gcc4 --datadir=/usr/share --infodir=/usr
/share/info --mandir=/usr/share/man -v --with-gmp=/usr --with-mpfr=/usr --enable
-bootstrap --enable-version-specific-runtime-libs --libexecdir=/usr/lib --enable
-static --enable-shared --enable-shared-libgcc --disable-__cxa_atexit --with-gnu
-ld --with-gnu-as --with-dwarf2 --disable-sjlj-exceptions --enable-languages=ada
,c,c++,fortran,java,lto,objc,obj-c++ --enable-graphite --enable-lto --enable-jav
a-awt=gtk --disable-symvers --enable-libjava --program-suffix=-4 --enable-libgom
p --enable-libssp --enable-libada --enable-threads=posix --with-arch=i686 --with
-tune=generic --enable-libgcj-sublibs CC=gcc-4 CXX=g++-4 CC_FOR_TARGET=gcc-4 CXX
_FOR_TARGET=g++-4 GNATMAKE_FOR_TARGET=gnatmake GNATBIND_FOR_TARGET=gnatbind --wi
th-ecj-jar=/usr/share/java/ecj.jar
Thread model: posix
gcc version 4.5.0 (GCC)

$ gcc -c minimal.cpp


// minmain.cpp
extern "C" int m(void);

#include <iostream>

int main(void) { std::cout << m() << "\n"; }


R:\>cl /c /EHsc minmain.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

minmain.cpp

R:\>link minmain.obj minimal.o
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.


R:\>minmain
7

这篇关于链接的Visual C反对票的MinGW的静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆