在与macOS和Linux兼容的Windows上创建静态库 [英] Create a Static Library on Windows Which Is macOS and Linux Compatible

查看:121
本文介绍了在与macOS和Linux兼容的Windows上创建静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows中使用与MacOS和Linux兼容的MSVC / IXX在Windows中生成静态库文件。

I would like to generate a Static Library file in Windows using MSVC / IXX which is macOS and Linux compatible.

我正在使用 C (比方说 C99 )和功能真的很简单。例如:

I'm using C (Let's say C99) and the functions are really simple. For example:

void AddArray(float* mA, float* mB, float* mC, int numElements){

    int ii;


    for(ii = 0; ii < numElements; ii++){
        mC[ii] = mA[ii] + mB[ii];
    }
}

有没有办法仅一次构建库Windows是否可以在任何地方使用它?

如果不是在Windows上,可以在Linux上完成并在Windows和macOS上运行吗?

Is there a way to build the Library only once on Windows and use it everywhere?
If not on windows, could it be done on Linux and work on Windows and macOS?

这个想法是可编译的一次使用相同的编译器,例如在Linux上不使用 MinGW

The idea is compile once with the same compiler and not use MinGW on Linux for instance.

推荐答案

这不可能以您想要的简单方式实现(每个OS /编译器只有一个库文件),因为静态库是编译后的二进制代码,它不可避免地引用了平台特定信息,并且(通常)必须在特定于编译器中格式。同一操作系统上的多个编译器之间存在某种程度的兼容性,但是永远不会在不同的操作系统上工作。 Mac OS曾经有胖二进制文件的概念(32位和64位二进制代码都位于彼此相邻的位置),但是由于它们移到了唯一的64位,因此这不再是真正意义上的了(尽管它们仍然存在并且仍可以使用。)

This is not possible in the simple way you want (one library file for each OS/compiler) due to the fact that static libraries are compiled binary code, which inevitably reference platform specifics and must (in general) be in a compiler specific format. Some level of compatibility exists between several compilers on the same OS, but never ever is that going to work across different OSes. Mac OS used to have the concept of fat binaries (in which both the 32-bit and 64-bit binary code resided next to each other), but since they moved to exclusively 64-bit, this isn't really relevant anymore (although they still exist and still can be used).

如果要以二进制形式分发,则需要为每个平台提供不同的二进制文件(OS /体系结构/工具链) )组合。

If you want to distribute in binary form, you will need to provide different binaries for each platform (OS/architecture/toolchain) combination you want to support.

这篇关于在与macOS和Linux兼容的Windows上创建静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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