[jamming] How to specify libraries on link line?

Turner David dturner at cptechno.com
Mon May 10 01:37:11 PDT 2004


> -----Original Message-----
> From: jamming-admin at perforce.com [mailto:jamming-admin at perforce.com]On
> Behalf Of Andrew Marlow
> Sent: Friday, May 07, 2004 5:24 PM
> To: jamming at perforce.com
> Subject: [jamming] How to specify libraries on link line?
> 
> 
> I am trying to use jam but am struggling.
> I have a socket program which needs to be
> linked with "-lsocket -lnsl" on Solaris
> and with winsock on Windoze. How do I add
> the appropriate options to the linker
> command line please?
> 
> I cannot use LinkLibraries because the libraries
> are system libraries so they should not take part
> in the dependency calculations, neither should full
> pathnames be given.
> 

You should use the LINKLIBS variable, since it is used to
list the default system libraries to be used durink link.

if $(UNIX)
{
  LINKLIBS += -lsocket -lnsl ;
}
else if $(NT)
{
  LINKLIBS += path\to\winsock.lib ;
}

Note that LINLIBS is normally only used as a global variable in
the Jambase. I.e. it is not per-target and is evaluated _once_
for all actions in your project.

If you need to set it on a given target only, you could use
something like the following:


# OnTargetVar: used to return the value of a per-target variable
#
# $(1) : target name
# $(2) : variable name
#
  rule _TargetVar
  {
    return $($(1)) ;
  }

rule OnTargetVar
{
  return [ on $(1) _TargetVar $(2) ] ;
}

# LinkSystemLibraries: used to specify additionnal libraries
#                      at link time, without adding dependencies
#
# $(1) : executable name
# $(2) : required system libraries
#
rule LinkSystemLibraries
{
  local _p _t ;

  for _p in $(<)
  {
    local _t = [ FAppendSuffix $(_p) : $(SUFEXE) ] ;

    if ! [ OnTargetVar $(_t) LINKLIBS ]
    {
      # the following sets the per-target variable LINKLIBS
      # to the _current_ value of the global LINKLIBS
      #
      LINKLIBS on $(_t) = $(LINKLIBS) ;
    }
    LINKLIBS on $(_t) += $(>) ;
  }
}


if $(UNIX)
{
  LinkSystemLibraries myprogram : -lsocket -lnsl ;
}
else if $(NT)
{
  LinkSystemLibraries myprogram : path\to\winsock.lib ;
}



Pity these are not available in the default Jambase.

Hope this helps,

- David Turner


--
This message and any attachments (the "message") is intended solely for the
addressees and is confidential. If you receive this message in error, please
delete it and immediately notify the sender.
Any use not in accordance with its purpose, any dissemination or disclosure,
either whole or partial, is prohibited except formal approval.
The E-Mail transmission can not guarantee the integrity of this message.
NDS TECHNOLOGIES FRANCE will not therefore be liable for the message if modified.






More information about the jamming mailing list