简体   繁体   English

使用qmake开发跨平台C ++静态库(通过Mac上的Qt Creator IDE)

[英]Developing cross platform C++ static library using qmake (via Qt creator IDE on Mac)

I am developing a library which is intended to work on all platforms (linux, mac, and windows). 我正在开发一个旨在在所有平台(Linux,Mac和Windows)上工作的库。 This library is based on Qt, which is a cross platform User interface library. 该库基于Qt,它是一个跨平台的用户界面库。 I am developing this library using a Mac. 我正在使用Mac开发该库。 The current build that I develop is a static library (.a), which works on Linux and Mac. 我开发的当前构建是一个静态库(.a),可在Linux和Mac上使用。 Will this .a library also work in Windows (let's say using Visual Studio), or do I have to create a separate library type for that? 这个.a library也可以在Windows中使用(例如使用Visual Studio),还是必须为此创建一个单独的库类型? And if yes, how can I create the windows static library from my Mac? 如果是的话,如何从我的Mac创建Windows静态库? For your information, I am using QtCreator IDE to create the static library. 供您参考,我正在使用QtCreator IDE创建静态库。 A simple guideline / code examples / useful links would be really helpful. 一个简单的指南/代码示例/有用的链接将非常有用。

First, if you want to write crossplatform software, you'll need to test it on the platforms you target. 首先,如果您想编写跨平台软件,则需要在目标平台上进行测试。 If you don't have a Windows computer to test on, then you can kiss Windows compatibility goodbye. 如果您没有要测试的Windows计算机,那么您可以亲吻Windows兼容性再见。

Second, Windows does have static libraries, but they use the .lib extension instead of .a . 其次,Windows确实有静态库,但它们使用.lib扩展名而不是.a Serious build systems like qmake should be able to handle this. 像qmake这样严肃的构建系统应该能够解决这个问题。 If you tell it to generate a static library, it will generate a .lib on Windows, and .a on other platforms. 如果你告诉它生成一个静态库,它将在Windows上生成.lib,在其他平台上生成.a。

Of course, for it to work with anything , it'll have to be compiled with the same compiler as is used for the program it is being linked into. 当然,为了能够处理任何事情 ,它必须使用与链接到的程序相同的编译器进行编译。

If you generate the .lib file with GCC (or MinGW, the Windows port of GCC), then it can't be linked into a Visual Studio project, because they use different ABIs, different standard library implementations and different runtimes (and because the format of MSVC .lib files is undocumented and changes between compiler versions). 如果使用GCC(或MinGW,GCC的Windows端口)生成.lib文件,则无法将其链接到Visual Studio项目,因为它们使用不同的ABI,不同的标准库实现和不同的运行时(并且因为MSVC .lib文件的格式未记录,并在编译器版本之间更改)。

However, since qmake works with most compilers, there should be no problem in generating the .lib file with Visual Studio. 但是,由于qmake可用于大多数编译器,因此使用Visual Studio生成.lib文件应该没有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM