Creating a project, from Makefile to static/dynamic libraries in UNIX

前端 未结 6 1082
予麋鹿
予麋鹿 2021-02-05 10:16

Guys, would you describe a few things about c++ building blocks, on unix.

I want to create an application that links against static libs and dynamic libs (.so).

<
6条回答
  •  不要未来只要你来
    2021-02-05 10:46

    Static libraries are usually archived with the ar command. Once you build all of the object files (preferably with the -fPIC switch on GCC), you can run ar like so:

    ar -rs archivename.a list.o of.o objects.o
    

    The man page describes the options.

    Dynamic libraries are built usually with the -shared switch to gcc or ld and the output file name with a .so extension.

    Autotools handles this with the libtool program. I'm not familiar with its use.

    Linking against these libraries can be done either by listing the libraries with the -l (ell) switch (such as -lX to link to libX.so) or by specifying them directly with absolute paths (such as adding /usr/lib/libX.so to your command). Static libraries are linked by specifying -static before -l or the appropriate absolute path to the .a archive.

提交回复
热议问题