如何将多个源文件转换为一个.a文件 [英] How to convert multiple source files into one .a file

查看:261
本文介绍了如何将多个源文件转换为一个.a文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现代码块(和MingW编译器)只需要.a库文件,而不是.lib什么是最简单的方法来转换.lib到.a文件...任何教程等都将不胜感激。
编辑
让我稍微修改我的问题如何将大量的源文件转换成一个.a存档文件。

i have just found out that Code Blocks (and MingW compiler) only takes .a library files rather then .lib what is the easiest way to convert .lib to .a files... any tutorials etc would be appreciated. Edit let me modify my question slightly how can you convert numerous source files into one .a archive file.

推荐答案

.lib(和.a也)在两种不同的能力下工作:

The .lib (and .a also) works under two different capacities:



你没有真正地在你的问题中指定使用哪种形式。如果你打算做第二种形式,你必须建立源代码在gcc下作为Persson建议的静态库,因为msvc工具使用的库格式不兼容。

You didn't really specify in your question which form you're working with. If you're looking to do the second form, you'll have to build the source under gcc as a static library as suggested by Persson since the library format used by msvc tools aren't compatible.

但是,如果你使用第一种形式,有一些好消息。 gcc的MinGW端口应该能够与使用msvc开发工具创建的coff格式导入库透明地工作。你可以做的只是将 *。lib import重命名为 lib * .a 像是任何其他 *。a 文件。链接器应该能够整理出它的真实格式。

However, there's some good news if you're working with the first form. The MinGW port of gcc should be able to work transparently with a coff-format import library created with msvc development tools. What you can do is simply rename the *.lib import into lib*.a and just pass that to the linker like it's any other *.a file. The linker should be able to sort out its real format.

我在tdm-gcc-4.5.2下测试了这个版本的最新版本的代码块,看起来工作正常。

I've tested this under tdm-gcc-4.5.2 with the latest nightly build of codeblocks and it appears to work ok.

编辑:合并了我的评论,作为答案的一部分。
如果你使用第二种形式,并且需要从源代码构建一个静态库,步骤大致如下:

Merged my comment as part of the answer. If you're working with the second form and need to build a static library from source, the steps are roughly as follows:

如果有一个现有的msvc项目,您可以使用它作为起点通过将其导入代码块。它将在 File-> Import Project-> Visual Studio 下。

If there's an existing msvc project you can use it as a starting point by importing it into codeblocks. It'll be under File->Import Project->Visual Studio etc.

如果没有可用的项目,则创建一个新的C :: B项目从头开始不是太难。只需转到文件 - >新建 - >项目选择静态库作为项目类型,然后添加任何所需的源文件。如果图书馆是用半便携的方式编写的,它应该编译而不会有太多的麻烦。

If none is available making a new C::B project from scratch isn't too difficult. Just goto File->New->Project select 'Static Library' as the project type then add whatever source file is needed. If the library is written in a semi-portable matter it should compile without too much trouble.

这篇关于如何将多个源文件转换为一个.a文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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