1

I have a Linux project in VS 2017 Community Edition. The project includes a dynamic .so file. That works so far. I now want to statically link this library as a .a file. How can I achieve this in the project settings? I have found nothing. For g ++, a -static or -Bstatic should be in front of -llibname on the command line. In the project settings under Linker-> All Options-> Additional Options I have "-(B)static -llibname". But it does not work, that -(B)static is not in the generated command line. Does anyone know how it works?

Robert
  • 97
  • 6
  • To statically link the FOO library with your project, you just need to link the static FOO.a archive library to the project. FOO.so is a shared object library, which is not a static library. If you cannot compile FOO source into FOO.a, then you may have some luck doing an `objdump -d` to disassemble and then to recompile into .o files, then create the static archive library (FOO.a) from those .o files. But that sounds difficult. – Eljay Mar 16 '18 at 17:40

1 Answers1

3

You need to build you library as a static library Then simply specify the library name (without the lib prefix or .a extension) as you did for the dynamic library.

Static libraries are simply an archive of all the object files (ar command). If you're using an MSBuild project, specify Static Library as the Configuration Type in project properties / General / Project Defaults.

GCC will search for dynamic libraries (.so) on the lib path(s) first, then static libraries (.a). If you have both and want to force static linking there is some very helpful information here.

stanthomas
  • 1,141
  • 10
  • 9