build a file.lib to a file.a usable on linux

2020-05-03 18:37发布

问题:

I'm trying to port a api from windows to linux. So far I've done the work on file.cpp and file.h but I still have a library .lib specified to windows that is needed in order for the api to work. how can I build a file.a usable on linux from this library?

回答1:

Static libraries in Linux (or all POSIX systems, like Mac OSX) are actually archives containing all object files. These archives are created with the ar command:

ar crv some_library.a some_object_file.o

The above command creates the "archive" (i.e. static library) some_library.a from the object file some_object_file.o. This library can now be used when linking other programs.