<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( https://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) INRIA -
 * Copyright (C) DIGITEO - 2011 - Allan CORNET
 *
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml"
          xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
          xmlns:scilab="http://www.scilab.org" xml:id="c_link" xml:lang="en">
    <refnamediv>
        <refname>c_link</refname>
        <refpurpose>check if symbol loaded with dynamic link</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>
            c_link(routine_name)
            [test, ilib] = c_link(routine_name)
            test = c_link(routine_name, num)
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>routine_name</term>
                <listitem>
                    <para>a character string</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>num</term>
                <listitem>
                    <para>number of the shared library where routine_name is searched
                        (-1: default, last used)
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>test</term>
                <listitem>
                    <para>boolean, indicates if there is a shared library which contains
                        <literal>routine_name</literal>.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>ilib</term>
                <listitem>
                    <para>a scalar, the number of the shared library which contains
                        <literal>routine_name</literal>
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            <literal>c_link</literal> is a boolean function which checks if the
            routine <literal>routine_name</literal> is currently linked. This function
            returns a boolean value true or false. When used with two return values,
            the function <literal>c_link</literal> returns a boolean value in
            <literal>test</literal> and the number of the shared library which
            contains <literal>routine_name</literal> in <literal>ilib</literal> (when
            <literal>test</literal> is true).
        </para>
    </refsection>
    <refsection>
        <title>Examples (C code)</title>
        <programlisting role="example"><![CDATA[
if haveacompiler() then
    chdir(TMPDIR)
    f1 = ['int ext1c(int *n, double *a, double *b, double *c)'
    '{int k;'
    '  for (k = 0; k < *n; ++k) '
    '      c[k] = a[k] + b[k];'
    '  return(0);}'];

    mputl(f1, TMPDIR + '/fun1.c');
    // creating the shared library: A gateway, a Makefile and a loader are generated.
    ilib_for_link('ext1c','fun1.c',[],"c");

    // load the shared library
    exec loader.sce;
    // show link
    link('show')

    [test, ilib] = c_link('ext1c') // check if 'ext1c' symbol is linked in scilab (it returns %T, ilib equals to 0)
    c_link('ext1c', -1) // check if 'ext1c' linked in scilab in current library (last used) (it returns %T)
    c_link('ext1c', 0)  // check in library (id eqs 0) if 'ext1c' is linked (it returns %T)
    c_link('ext1c', 1)  // 'ext1c' not in library with id = 1 (it returns %F)
    c_link('toto')      // returns %F  'toto' not linked to scilab (it returns %F)
end
     ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="link">link</link>
            </member>
        </simplelist>
    </refsection>
</refentry>
