문제

I am writing a program using Qt Creator, on Linux. It uses a library, for which I have both the .so and the .a equivalents in the /usr/lib directory, for example:

/usr/lib/libuseme.a

/usr/lib/libuseme.so

From what I understand, if I link to the .so, it will be linked dynamically, but if I link to the .a it will be linked statically.

In this case, I want to link statically, to give me a better chance of distributing my program in a self-contained way.

But the -l option to the linker only allows the library name, not including the lib or the extension to be specified - e.g.

-luseme

So how do I indicate that I want it to link (statically) to the .a, not dynamically to the .so?

도움이 되었습니까?

해결책

So how do I indicate that I want it to link (statically) to the .a, not dynamically to the .so?

Two ways:

  • Link using the full library path /usr/lib/libuseme.a instead of -luseme
  • Tell the linker that you want archive copy: -Wl,-Bstatic -luseme -Wl,-Bdynamic

다른 팁

You may use -static to force static linking.

However, if you don't want to statically link with every library, you can add the paths to the .a files of the libraries for static linking to the command with the rest of the files.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top