Wednesday, February 2, 2022

[SOLVED] GPS App compile errors

Issue

I am working on a GPS application on the Raspberry pi. I have just installed GPSD by running sudo apt-get install gpsd gpsd-clients. I do get data from my GPS module when I run sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock. My issue resides when I try to make my own GPS app. I have installed libgps-dev

When I try to compile my app I get two errors : undefined reference to gpsmm::~gpsmm() and undefined reference to gpsmm::gps_inner_open(char const*, char const*)

My Main Method:

#include <libgpsmm.h>
int main(int argc, char *argv[])
{         
    gpsmm gps_rec("localhost", DEFAULT_GPSD_PORT);
    return 0;    
}

libgpsmm.h:

#ifndef _GPSD_GPSMM_H_
#define _GPSD_GPSMM_H_

/*
 * Copyright (C) 2005 Alfredo Pironti
 *
 * This software is distributed under a BSD-style license. See the
 * file "COPYING" in the toop-level directory of the distribution for details.
 *
 */
#include <sys/types.h>
#include "gps.h" //the C library we are going to wrap

#ifndef USE_QT
class gpsmm {
#else

#include <QtCore/qglobal.h>

#if defined(LIBQGPSMM_LIBRARY)
#  define LIBQGPSMMSHARED_EXPORT Q_DECL_EXPORT
#else
#  define LIBQGPSMMSHARED_EXPORT Q_DECL_IMPORT
#endif

class LIBQGPSMMSHARED_EXPORT gpsmm {
#endif
    public:
        // cppcheck-suppress uninitVar
        gpsmm(const char *host, const char *port) : to_user(0) {
            gps_inner_open(host, port);
        }
#ifdef __UNUSED__
        // cppcheck-suppress uninitVar
        gpsmm(void) : to_user(0) 
        {
                gps_inner_open("localhost", DEFAULT_GPSD_PORT);
        }
#endif
        virtual ~gpsmm();
        struct gps_data_t* send(const char *request); //put a command to gpsd and return the updated struct
        struct gps_data_t* stream(int); //set watcher and policy flags
        struct gps_data_t* read(void); //block until gpsd returns new data, then return the updated struct
        const char *data(void); // return the client data buffer
        bool waiting(int);  // blocking check for data waiting
        void clear_fix(void);
        void enable_debug(int, FILE*);  
private:
    struct gps_data_t *to_user; //we return the user a copy of the internal structure. This way she can modify it without
    //integrity loss for the entire class
    struct gps_data_t* gps_inner_open(const char *host, const char *port);
    struct gps_data_t _gps_state;
    struct gps_data_t * gps_state() { return &_gps_state; }
    struct gps_data_t* backup(void) { *to_user = *gps_state(); return to_user; }; //return the backup copy
};
#endif // _GPSD_GPSMM_H_

If anyone can help me figure out my problem, I would be grateful.


Solution

The problem is that you are most likely not linking your source code with the library.



Answered By - Pradheep
Answer Checked By - Robin (WPSolving Admin)