Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
156 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...