0

I have installed an API for my Linux 18.04. After doing it I have the headers gclib.h and gclibo.h in the include and lib folders:

root@ubuntuadmin-Vostro-3559:/# locate gclib
/usr/include/gclib.h
/usr/include/gclib_errors.h
/usr/include/gclib_record.h
/usr/include/gclibo.h
/usr/lib/libgclib.so
/usr/lib/libgclib.so.0
/usr/lib/libgclib.so.0.478
/usr/lib/libgclibo.so
/usr/lib/libgclibo.so.0
/usr/lib/libgclibo.so.0.0
/usr/share/doc/gclib
/usr/share/doc/gclib/changelog.Debian.gz
/usr/share/doc/gclib/changelog.gz
/usr/share/doc/gclib/copyright
/usr/share/doc/gclib/gclib_doc.tar.gz
/usr/share/doc/gclib/src
/usr/share/doc/gclib/src/gclib_examples.tar.gz
/usr/share/doc/gclib/src/gclib_gcl.tar.gz
/usr/share/doc/gclib/src/gclib_pci.tar.gz
/usr/share/doc/gclib/src/gclib_python.tar.gz
/usr/share/doc/gclib/src/gclib_python_examples.tar.gz
/usr/share/doc/gclib/src/gclibo_src.tar.gz
/var/cache/apt/archives/gclib_478-1_amd64.deb
/var/lib/dpkg/info/gclib.list
/var/lib/dpkg/info/gclib.md5sums
/var/lib/dpkg/info/gclib.postinst
/var/lib/dpkg/info/gclib.postrm

I have written a simple code which includes the libraries gclib.h and gclibo.h and call the function GOpen() which is declared in the header gclib.h.

/home/ubuntuadmin/Desktop/Galilprogram/test.c

#include<gclib.h>
#include<gclibo.h>
#include<stdio.h>

GCon* g=0;//handle to Galil

int main (int argc, char* argv[]){
        if (argc != 2){
                printf("Error");
                return -1;
        }
        else{
                printf("\nA sample C program \n\n");
                GOpen(argv[1], g);
        return 0;
        }
}

These is the gclib.h header:

    /** @defgroup cpp_api API
  *         Language Support          | C++   | C#    | VB.NET | Java | Python
  *  ---------------------------------|:-----:|:-----:|:------:|:----:|:----------------:
  *  gclib Functions                  | Yes   | Yes   | Yes    | Yes  | Yes
  *  Data Records and Data Structures | Yes   | Yes   | Yes    | No   | No
  *  gclib Macros                     | Yes   | No    | No     | No   | No
  *  gclib Typedefs                   | Yes   | No    | No     | No   | No
*/

/** @addtogroup cpp_api
  * 
  * @{
  */

/*! \file gclib.h
*
* Defines the interface for the Galil C Library (GCLIB).
*
*/
#ifndef I_D48432D9_1FA3_4C7D_B44C_05F8B9000ADF
#define I_D48432D9_1FA3_4C7D_B44C_05F8B9000ADF

//set library visibility for gcc and msvc
#if BUILDING_GCLIB && HAVE_VISIBILITY
#define GCLIB_DLL_EXPORTED __attribute__((__visibility__("default")))
#elif BUILDING_GCLIB && defined _MSC_VER
#define GCLIB_DLL_EXPORTED __declspec(dllexport)
#elif defined _MSC_VER
#define GCLIB_DLL_EXPORTED __declspec(dllimport)
#else
#define GCLIB_DLL_EXPORTED
#endif

#include "gclib_record.h" // Galil data record structs and unions.
#include "gclib_errors.h" // GReturn error code values and strings.

#ifdef _WIN32
#define GCALL __stdcall //!< Specify calling convention for Windows.
#else
#define GCALL
#endif

//#define G_USE_GCOMPOUND //!< GCompound() is not part of the standard gclib release. Contact Galil Applications for a special build, http://galil.com/contact.

#ifdef __cplusplus
extern "C" {
#endif

    //Constants for function arguments
#define G_DR 1 //!< Value for GRecord() `method` variable for acquiring a data record via DR mode.
#define G_QR 0 //!< Value for GRecord() `method` variable for acquiring a data record via QR mode.
#define G_BOUNDS -1 //!< For functions that take range options, e.g. GArrayUpload(), use this value for full range.
#define G_CR 0 //!< For GArrayUpload(), use this value in the delim field to delimit with carriage returns.
#define G_COMMA 1 //!< For GArrayUpload(), use this value in the delim field to delimit with commas.

    //Constants for GUtility()
#define G_UTIL_TIMEOUT 1 //!< GUtility(), Access to timeout.
#define G_UTIL_TIMEOUT_OVERRIDE 2 //!< GUtility(), read/write access to timeout override.
#define G_USE_INITIAL_TIMEOUT -1 //!< GUtility(), for timeout override. Set `G_UTIL_TIMEOUT_OVERRIDE` to this value to use initial GOpen() timeout (`--timeout`).
#define G_UTIL_VERSION 128 //!< GUtility(), get a library version string.
#define G_UTIL_INFO 129 //!< GUtility(), get a connection info string.
#define G_UTIL_SLEEP 130 //!< GUtility(), specify an interval to sleep.
#define G_UTIL_ADDRESSES 131 //!< GUtility(), get a list of available connections.
#define G_UTIL_IPREQUEST 132 //!< GUtility(), get a list of hardware requesting IPs.
#define G_UTIL_ASSIGN 133 //!< GUtility(), assign IP addresses via Boot-P reply.
#define G_UTIL_DEVICE_INITIALIZE 134  //!< GUtility(), sends CF, CW, EO etc. to initialize the connection. Useful after RS or other reset.  
#define G_UTIL_PING 135 //!< GUtility(), uses ICMP ping to determine if an IP address is reachable and assigned.
#define G_UTIL_ERROR_CONTEXT 136 //!< GUtility(), provides additional error context, where available.

#define G_UTIL_GCAPS_HOST 256
#define G_UTIL_GCAPS_VERSION 257 //!< GUtility(), get the version of the @ref gcaps server.
#define G_UTIL_GCAPS_KEEPALIVE 258 //!< GUtility(), @ref gcaps server keepalive.
#define G_UTIL_GCAPS_ADDRESSES 259 //!< GUtility(), get a list of available connections from the @ref gcaps server.
#define G_UTIL_GCAPS_IPREQUEST 260 //!< GUtility(), get a list of hardware requesting IPs from the @ref gcaps server.
#define G_UTIL_GCAPS_ASSIGN 261 //!< GUtility(), assign IP addresses via Boot-P reply from the @ref gcaps server.
#define G_UTIL_GCAPS_PING 262 //!< GUtility(), uses ICMP ping to determine if an IP address is reachable and assigned. Ping sent from the @ref gcaps server.


    //Convenience constants
#define G_SMALL_BUFFER 1024 //!< Most reads from Galil are small. This value will easily hold most, e.g. TH, TZ, etc.
#define G_HUGE_BUFFER 524288 //!< Most reads from Galil hardware are small. This value will hold the largest array or program upload/download possible.
#define G_LINE_BUFFER 80 //!< For writes, via command interpreter, to the Galil.

    typedef int GReturn; //!< Every function returns a value of type GReturn. See gclib_errors.h for possible values.
    typedef void* GCon; //!< Connection handle. Unique for each connection in process. Assigned a non-zero value in GOpen().
    typedef unsigned int GSize; //!< Size of buffers, etc.
    typedef int GOption; //!< Option integer for various formatting, etc.
    typedef char* GCStringOut; //!< C-string output from the library. Implies null-termination.
    typedef const char* GCStringIn; //!< C-string input to the library.  Implies null-termination.
    typedef char* GBufOut; //!< Data output from the library. No null-termination implied. Returned values may be null-terminated, see function documentation for details.
    typedef const char* GBufIn; //!< Data input to the library. No null-termination, function will have a GSize to indicate bytes to write .
    typedef unsigned char GStatus; //!< Interrupt status byte.
    typedef void* GMemory; //!< Pointer to untyped memory for use in GUtility().

    //! Open a connection to a Galil Controller.
    GCLIB_DLL_EXPORTED GReturn GCALL GOpen(GCStringIn address, GCon* g);
    /*!<
    *  \param address Null-terminated address string. See table below.
    *  \param g Pointer to user's `GCon` variable. On success, the library will fill the user's variable with the handle to use for the rest of the connection. A valid `g` value is nonzero.
    *
    *  \return The success status or error code of the function. See gclib_errors.h for possible values.
    *
    *  `address` switch     | Meaning                                                         | Arguments `(default), other options`  | %Examples
    *  ---------------------|-----------------------------------------------------------------|---------------------------------------|-----------------
    *  `--address`          | **Simple address to hardware**                                  | *IP address*, *PCI*, *COM port*       | `--address COM1`
    *  `-a`                 | shorthand for `--address`                                       |  See *Address Ranges* below           | `-a GALILPCI1`
    *  {no switch}          | `--address` is implicit for any lone token                      |                                       | `192.168.0.42`
    *  `--baud`             | **Baud rate**                                                   | (`115200`), *valid baud...*           | `COM2 --baud 19200`
    *  `-b`                 | shorthand for `--baud`                                          |                                       | `COM3 -b 38400`
    *  `--command`          | **Command-and-response socket protocol**                        |  (`TCP`), `UDP`                       | `192.168.0.42 --command TCP`
    *  `-c`                 | shorthand for `--command`                                       |                                       | `192.168.0.42 -c UDP`
    *  `--direct`           | **Connect directly to hardware instead of via** @ref gcaps      |                                       | `-a GALILPCI2 --direct`
    *  `-d`                 | shorthand for `--direct`                                        |                                       | `GALILPCI2 -d`
    *  `--subscribe`        | **Subscribe to messages, data records, and/or interrupts**      | (`NONE`), `MG`, `DR`, `EI`, `ALL`     | `192.168.0.42 --subscribe MG`
    *  `-s`                 | shorthand for `--subscribe`                                     |                                       | `192.168.0.42 -s DR -s EI`
    *  `--timeout`          | **timeout in ms**                                               | (`5000`), *0-65535*                   | `192.168.0.42 --timeout 5000`
    *  `-t`                 | shorthand for `--timeout`                                       |                                       | `GALILPCI2 -t 500`
    *  `--unsolicited`      | **Unsolicited socket protocol**                                 | (`UDP`), `NONE`                       | `192.168.0.42 --unsolicited NONE`
    *  `-u`                 | shorthand for `--unsolicited`                                   |                                       | `192.168.1.42 -u UDP`
    *  |**The following `address` switches are deprecated and will be unavailable starting July 1st, 2020.**||||
    *  `--p1`               | **Primary port for command-and-response traffic**               | (`23`), *valid port number*           | `192.168.0.42 --p1 5000`
    *  `--p2`               | **Secondary port for unsolicited traffic**                      | (`60007`), *valid port number*        | `192.168.0.42 --p2 5000`
    *
    * <br>
    *
    *  Operating System     |  Address Range                     | Notes
    *  ---------------------|------------------------------------|------------------------------
    *  Windows              | `COM1` - `COM256`                  | RS232 and USB-to-serial
    *  Linux                | `/dev/ttyS0` - `/dev/ttyS255`      | RS232
    *  Linux                | `/dev/ttyUSB0` - `/dev/ttyUSB255`  | USB-to-serial, e.g. DMC-4103
    *  Windows              | `GALILPCI1` - `GALILPCI8`          | PCI 
    *  Linux                | `/dev/galilpci0` - `/dev/galilpci7`| PCI 
    *
    *  See x_examples.cpp for an example.
    *
    *  When connecting to a network device, if the command-and-response socket is opened successfully but the unsolicited socket fails, GOpen() will still
    *  complete successfully. This allows connection to a Galil controller when only one Ethernet handle is available. Unsolicited traffic will not be accessible
    *  in this case.
    */


    //! Closes a connection to a Galil Controller.
    GCLIB_DLL_EXPORTED GReturn GCALL GClose(GCon g);
    /*!<
    * \attention
    *  *gclib* requires that `GClose()` be called whenever a program is finished with a controller.
    *  This includes when a program closes. A rule of thumb is that for every `GOpen()` call on a given connection,
    *  a `GClose()` call should be found on every code path. Failing to call GClose() may cause controller resources
    *  to not be released or can hang the process if there are outstanding asynchronous operations. The latter can
    *  occur, for example, if a call to GRead() times out and the process exits without calling GClose(). In this case, 
    *  GRead() still has an outstanding asynchronous read pending. GClose() will terminate this operation allowing the process 
    *  to exit correctly.
    *
    *  \param g Connection's handle.
    *
    *  \return The success status or error code of the function. See gclib_errors.h for possible values.
    *
    *  See x_examples.cpp for an example.
    */


    //! Performs a read on the connection.
    GCLIB_DLL_EXPORTED GReturn GCALL GRead(GCon g, GBufOut buffer, GSize buffer_len, GSize* bytes_read);
    /*!<
    *  \param g Connection's handle.
    *  \param buffer The user's read buffer.
    *  \param buffer_len The length of the user's read buffer.
    *  \param bytes_read Pointer to a GSize which will be filled with the number of bytes read upon return.
    *
    *  \return The success status or error code of the function. See gclib_errors.h for possible values.
    *
    *  \warning This function is deprecated and will be removed in a future gclib version. Please contact Galil
    *  for needs not covered by the other gclib functions.
    *
    *  Unsolicited messages may be returned in the read data. 
    *  The high bit of each message byte will be set unless the user changes the CW setting.
    *  Interrupts and Data Records are always filtered from a read.
    *
    *  See x_gread_gwrite.cpp for an example.
    */

I apologize but I cut off the rest of the code.

When I compile the code with gcc with gcc I get the error:

ubuntuadmin@ubuntuadmin-Vostro-3559:~/Desktop/Galilprogram$ gcc test.c -o test
/tmp/ccTRCzo0.o: In function `main':
test.c:(.text+0x52): undefined reference to `GOpen'
collect2: error: ld returned 1 exit status

Since it seems to locate the header I thought that it has problem to find the dynamic library, so I also tried to use the option -L:

gcc -L/usr/lib test.c -o ciao

I am not an expert I hope someone can redirect toward the right path.

acefrrag
  • 41
  • 6
  • With `-L` you're telling the linker a path to check for libraries. But you never tell it *which* library to link to. `-l gclib` should do the trick. – DevSolar Mar 04 '20 at 08:43
  • Thanks DevSolar, it worked. I need to learn how to use gcc. – acefrrag Mar 04 '20 at 09:00

0 Answers0