1
qtGUI.o:(.bss+0x0): multiple definition of `R'
rWidgetPlots.o:(.bss+0x0): first defined here
qtGUI.o:(.rodata+0x0): multiple definition of `qtToR'
rWidgetPlots.o:(.rodata+0x0): first defined here
main.o:(.bss+0x0): multiple definition of `R'
rWidgetPlots.o:(.bss+0x0): first defined here
main.o:(.rodata+0x0): multiple definition of `qtToR'
rWidgetPlots.o:(.rodata+0x0): first defined here
moc_qtGUI.o:(.bss+0x0): multiple definition of `R'
rWidgetPlots.o:(.bss+0x0): first defined here
moc_qtGUI.o:(.rodata+0x40): multiple definition of `qtToR'
rWidgetPlots.o:(.rodata+0x0): first defined here

rWidgetPlots.h

#ifndef RWIDGETPLOTSH
#define RWIDGETPLOTSH

#include <iostream>
#include <RInside.h>
#include <Rcpp.h>
#include <vector>
#include <limits>
#include <QRect>
#include <fstream>
#include "zoomAndCornerDatabaseParser.h"

RInside R (0, NULL);
RInside & qtToR (R);

typedef struct
{
        double       latitude;
        double       longitude;
        unsigned int vehicleId;
} vehicle;

extern std :: vector <vehicle> vehicleInfo;

typedef struct
{
    float latitude;
    float longitude;
} coordinate;

extern std :: vector <coordinate> previousPoints;

class rdaTilesOnR
{
    public:
        static std :: string returnCenterPoint    (std :: string fileName);
        static std :: string findPanningDirection (float newLatitude, float newLongitude,
                        std :: string topLeftLat, std :: string topLeftLng, 
                        std :: string northEastLat, std :: string northEastLng, 
                    std :: string bottomRightLat, std :: string bottomRightLng, 
                    std :: string southWestLat, std :: string southWestLng);

        static void storeVehicleInfo  (float latitude, float longitude, unsigned int vehicleId);

        static void loadNewTileAndPlotPointsOnRWidget (unsigned short option, float newLongitude, float newLatitude);

        static std :: string doesPointLieInBoundaries  (unsigned short option, float newLatitude, float newLongitude, float currentCenterLatitude, float currentCenterLongitude);
};

#endif

qtGUI.h

#ifndef QTGUIH
#define QTGUIH

#include <QApplication>
#include <QMainWindow>
#include <QtCore>
#include <QtGui>
#include <QPushButton>
#include <unistd.h>
#include <iostream>
#include <string.h>

#include "rWidgetPlots.h"

class controlRThroughQt : public QWidget
{
    Q_OBJECT  

    QTextEdit  *textEdit;

    public:
        void qtInterface ();

    public slots:
        void slotPanLeft     ();
        void slotPanRight   ();
        void slotPanTop      ();
        void slotPanBottom ();
        void slotZoomIn      ();
        void slotZoomOut    ();
        void slotRefresh      ();
        void findInfoByClicking ();
};

#endif

qtToR这是一个参考。它必须在当时和那里进行定义。如何解决此错误?使用extern没有帮助。

4

1 回答 1

6

它必须在当时和那里进行定义。

那么,它不能完成。如果您愿意将其留在标题中:

extern RInside R;
extern RInside & qtToR;

并将定义移动到单个实现文件中:

//somecpp.cpp
RInside R (0, NULL);
RInside & qtToR (R);

就可以了。

于 2012-09-24T07:55:53.070 回答