Skip to content

Latest commit

 

History

History
155 lines (116 loc) · 5.39 KB

LINKAGE.mkd

File metadata and controls

155 lines (116 loc) · 5.39 KB

#DYNAMIC LINKAGE

##RECOMMENDED: DYNAMIC LINKAGE

First, build and install the libraries using make install in the source tree root. You also may distribute the binary libraries libsocket.so, libsocket++.so with your program (the license allows this) and then install them to the library directory (e.g. /usr/lib).

Then, compile your programs using the -lsocket (for C libsocket) respectively -lsocket++ (for C++ libsocket) switch. libsocket++ contains also all libsocket functions, so you may link your C application against libsocket++, if you want to install only one library.

To use libsocket, you also have to include headerfiles. It depends on what your program does which headers you may want to include.

The header names are quite self-explaining:

C:

  • libinetsocket.h (all inet-related stuff)
  • libunixsocket.h (all UNIX-related stuff)

C++:

  • inetclientstream.hpp (TCP client)
  • inetserverstream.hpp (TCP server)
  • inetclientdgram.hpp (UDP client)
  • inetserverdgram.hpp (UDP server)
  • unixclientstream.hpp (UNIX STREAM client)
  • unixserverstream.hpp (UNIX STREAM server)
  • unixclientdgram.hpp (UNIX DGRAM client)
  • unixserverdgram.hpp (UNIX DGRAM server)
  • exception.hpp (always needed when using libsocket::socket_exception)

Include them using a directive like this (if you use the default location /usr/include/libsocket):

# include <libsocket/inetclientstream.hpp>
//	(if you want to create a C++ TCP client)

# include <libsocket/libinetsocket.h>
//	(if you want to create a C internet socket application

The other header files which are used in the internal class hierarchy are included correctly so you only have to include the right "leaf" header file. You also may take a look at the class diagram in doc/libsocket++/classes.svg.

Then link your program against the library:

$ gcc -o ~~~ -lsocket $OBJECTS
$ g++ -o ~~~ -lsocket++ $OBJECTS

Some more information about building etc. can be found in README.md.

##STATIC LINKAGE

C

If you're using the C interface, you only have to compile your programs together with C/libinetsocket.c respectively C/libunixsocket.c.

C++

The following specifications can be used to determine which files must be specified on the compiler's command line to enable correct linkage. It's a great help because libsocket++ uses very much classes (more than 15) and for every class an own file. You may practice this using the files in examples++/.

Note: To understand the dependencies between the files, take a look at doc/libsocket++/classes.svg The descriptions of the classes are placed under the license at the beginning of every C++ source file.

If you compile C files with a C compiler and C++ files with a C++ compiler, you have to invoke the C++ compiler with the option -D_MIXED to enable correct linkage!

Note II: Dynamic linkage is way easier!

Legend: file.type (implemented class) file.type [commentary]

All files ending with .cpp are located in C++/, all files ending with .c may be found in C/.

** SPECIAL CASES **

If you program makes use of the selectset class, it must be linked against select.cpp.

** GENERAL SCHEMES ** Of course, some schemes may be combined, e.g. if you have a program acting as both UDP server and client.

For...

  • TCP Internet Server Programs:

    • libinetsocket.c [socket functionality]
    • socket.cpp (socket)
    • exception.cpp (socket_exception)
    • inetbase.cpp (inet_socket)
    • inetserverstream.cpp (inet_stream_server)
    • streamclient.cpp (stream_client_socket)
    • inetclientstream.cpp (inet_stream) // inet_stream_server::accept() returns an inet_stream object
  • TCP Internet Client Programs:

    • libinetsocket.c [socket functionality]
    • socket.cpp (socket)
    • exception.cpp (socket_exception)
    • inetbase.cpp (inet_socket)
    • streamclient.cpp (stream_client_socket)
    • inetclientstream.cpp (inet_stream)
  • UDP Internet Server Programs:

    • libinetsocket.c [socket functionality]
    • socket.cpp (socket)
    • exception.cpp (socket_exception)
    • inetbase.cpp (inet_socket)
    • inetdgram.cpp (inet_dgram)
    • inetserverdgram.cpp (inet_dgram_client)
  • UDP Internet Client Programs:

    • libinetsocket.c [socket functionality]
    • socket.cpp (socket)
    • exception.cpp (socket_exception)
    • inetbase.cpp (inet_socket)
    • inetdgram.cpp (inet_dgram)
    • clientdgram.cpp (dgram_client_socket)
    • inetclientdgram.cpp (inet_dgram_client)

==================================================================================================

  • UNIX Stream Client Programs:

    • libunixsocket.c [socket functionality]
    • socket.cpp (socket)
    • exception.cpp (socket_exception)
    • unixbase.cpp (unix_socket)
    • streamclient.cpp (stream_client_socket)
    • unixclientstream.cpp (unix_stream_client)
  • UNIX Stream Server Programs:

    • libunixsocket.c [socket functionality]
    • socket.cpp (socket)
    • exception.cpp (socket_exception)
    • streamclient.cpp (stream_client_socket)
    • unixbase.cpp (unix_socket)
    • unixclientstream.cpp (unix_stream_client)
    • unixserverstream.cpp
  • UNIX Dgram Client Programs:

    • libunixsocket.c [socket functionality]
    • socket.cpp (socket)
    • exception.cpp (socket_exception)
    • dgramclient.cpp (dgram_client_socket)
    • unixdgram.cpp (unix_dgram)
    • unixdgramclient.cpp (unix_dgram_client)
  • UNIX Dgram Server Programs:

    • libunixsocket.c [socket functionality]
    • socket.cpp (socket)
    • exception.cpp (socket_exception)
    • dgramclient.cpp (dgram_client_socket)
    • unixdgram.cpp (unix_dgram)
    • unixdgramclient.cpp (unix_dgram_client)
    • unixdgramserver.cpp (unix_dgram_server)