Same source, all that, just want a static and shared version both. Easy to do?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, it’s moderately easy. Just use two "add_library" commands:
Even if you have many source files, you can place the list of sources in a
Cmakevariable, so it’s still easy to do.On Windows you should probably give each library a different name, since there is a ".lib" file for both shared and static. But on Linux and Mac you can even give both libraries the same name (e.g.
libMyLib.aandlibMyLib.so):But I don’t recommend giving both the static and dynamic versions of the library the same name. I prefer to use different names because that makes it easier to choose static vs. dynamic linkage on the compile line for tools that link to the library. Usually I choose names like
libMyLib.so(shared) andlibMyLib_static.a(static). (Those would be the names on linux.)