$LIBRARY directive

Purpose:

The library named as a parameter in a $LIBRARY directive will be linked to the program without the need, at link time, to specify the library, explicitly, on the command line or in a makefile.

$LIBRARY is an alias to the C compiler "#pragma lib" feature. $LIBRARY operates on the same level as #INCLUDE and will emit the appropriate library statements within the header section of the emitted C source code.

👉 The $LIBRARY directive can be used with the Pelles C, and Microsoft libraries that BCX loads by default. $LIBRARY does not work with the MinGW derived compilers because they lack "#pragma lib" type functionality.

Syntax 1:

$LIBRARY "c:\bcx\lib\mylib.lib"

Parameters:

  • Data type: STRING
    "c:\bcx\lib\mylib.lib" will search in the directory specified for the library.

Syntax 2:

$LIBRARY "mylib.lib"

Parameters:

  • Data type: STRING
    "mylib.lib" will search in the current working directory for the library.

Syntax 3:

$LIBRARY <mylib.lib>

Parameters:

  • Data type: STRING
    <mylib.lib> will search in the C compiler's default LIB directory for the library.

Example:

$HEADER
 #if defined(__LCC__)
  #include <WINSOCK2.H>
 #endif
$HEADER

$LIBRARY <WSOCK32.LIB>          ' LINK WITH WSOCK32.LIB 

GLOBAL  wVersionRequested
GLOBAL  wsaData AS WSADATA
GLOBAL  rc

wVersionRequested = MAKEWORD(1,1)

rc = WSAStartup(wVersionRequested, &wsaData)

IF NOT rc THEN
 PrintWSAData(&wsaData)
ELSE
 PRINT "Winsock error"
END IF

WSACleanup()

SUB PrintWSAData (pWSAData AS LPWSADATA)

 DIM  Lo
 DIM  Hi
 DIM  I
 DIM  A$

 '------------------------------------- 
 PRINT "Winsock Version Information"
 '------------------------------------- 
 Lo = LOBYTE(pWSAData->wVersion)
 Hi = HIBYTE(pWSAData->wVersion)
 A$ = LTRIM$(STR$(Lo)) & "." & LTRIM$(STR$(Hi))
 PRINT "Version: ", A$
 '------------------------------------- 
 Lo = LOBYTE(pWSAData->wHighVersion)
 Hi = HIBYTE(pWSAData->wHighVersion)
 A$ = LTRIM$(STR$(Lo)) & "." & LTRIM$(STR$(Hi))
 PRINT "HighVersion: ", A$
 '------------------------------------- 
 A$ = pWSAData->szDescription$
 PRINT "Description: ", A$
 '------------------------------------- 
 A$ = pWSAData->szSystemStatus$
 PRINT "System status: ", A$
 '------------------------------------- 
 I = pWSAData->iMaxSockets
 PRINT "Max number of sockets: ", I
 '------------------------------------- 
 I = pWSAData->iMaxUdpDg
 PRINT "MAX UDP datagram size: ", I
 '------------------------------------- 
END SUB

BCX Console Sample Programs using the $LIBRARY directive.

$NOLIBRARY directive

Purpose:

The library named as a parameter with a $NOLIBRARY directive will not be linked to the program. The $NOLIBRARY directive can be used with the BCX linked by default Pelles C, and Microsoft libraries.

👉 $NOLIBRARY does not work with the MinGW derived compilers because they lack "#pragma lib" type functionality.

Syntax:

$NOLIBRARY "LibraryName.lib"

Parameters:

  • Data type: STRING
    "LibraryName.lib" The name of library not to link.

Remarks:

Here is the list of libraries that BCX loads, by default, into the C language translation.