GPS App 编译错误
GPS App compile errors
我正在 Raspberry pi 上开发 GPS 应用程序。我刚刚通过 运行ning sudo apt-get install gpsd gpsd-clients
安装了 GPSD。当我 运行 sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock
时,我确实从我的 GPS 模块获取数据。当我尝试制作自己的 GPS 应用程序时,我的问题就出现了。我已经安装了 libgps-dev
当我尝试编译我的应用程序时出现两个错误:undefined reference to gpsmm::~gpsmm()
和 undefined reference to gpsmm::gps_inner_open(char const*, char const*)
我的主要方法:
#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_
如果有人能帮我解决我的问题,我将不胜感激。
问题是您很可能没有将源代码与库链接。
你应该通过
将它传递给你的 g++
g++ -o output sourceFileThatImplementsLibGPS.cpp -lgps
我正在 Raspberry pi 上开发 GPS 应用程序。我刚刚通过 运行ning sudo apt-get install gpsd gpsd-clients
安装了 GPSD。当我 运行 sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock
时,我确实从我的 GPS 模块获取数据。当我尝试制作自己的 GPS 应用程序时,我的问题就出现了。我已经安装了 libgps-dev
当我尝试编译我的应用程序时出现两个错误:undefined reference to gpsmm::~gpsmm()
和 undefined reference to gpsmm::gps_inner_open(char const*, char const*)
我的主要方法:
#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_
如果有人能帮我解决我的问题,我将不胜感激。
问题是您很可能没有将源代码与库链接。
你应该通过
将它传递给你的 g++g++ -o output sourceFileThatImplementsLibGPS.cpp -lgps