Create a Static Library on Windows Which Is macOS and Linux Compatible

时光毁灭记忆、已成空白 提交于 2019-12-25 18:24:39

问题


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

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];
    }
}

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?

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


回答1:


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).

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.



来源:https://stackoverflow.com/questions/55758704/create-a-static-library-on-windows-which-is-macos-and-linux-compatible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!