Hi,
I am having a problem with trying to include c headers and c files using extern C in a c++ header file which contains a class that inherits QOBJECT and contains the QOBJECT macro. For example:
#include <qobject.h>
#include <vector>
extern "C"
{
#include "extApi.h"
#include "extApi.c"
#include "extApiPlatform.h"
#include "extApiPlatform.c"
}
{
Q_OBJECT
public:
VrepClient();
~VrepClient(){};
void setJoints(std::vector<float> jntValues);
bool connected() {return clientID != -1 ? true : false;}
public slots:
void simulate();
private:
int port;
const simxChar* address;
int clientID;
std::vector<int> jointHandles;
std::vector<float> jointValues;
bool stopSim;
};
#include <qobject.h>
#include <vector>
extern "C"
{
#include "extApi.h"
#include "extApi.c"
#include "extApiPlatform.h"
#include "extApiPlatform.c"
}
class VrepClient: public QObject
{
Q_OBJECT
public:
VrepClient();
~VrepClient(){};
void setJoints(std::vector<float> jntValues);
bool connected() {return clientID != -1 ? true : false;}
public slots:
void simulate();
private:
int port;
const simxChar* address;
int clientID;
std::vector<int> jointHandles;
std::vector<float> jointValues;
bool stopSim;
};
To copy to clipboard, switch view to plain text mode
The program does not compile and generates linkage errors for all the methods in the .c files. Some examples:
1>vrepClient.obj : error LNK2005: _simxGetObjectChild already defined in moc_vrepClient.obj
1>vrepClient.obj : error LNK2005: _simxTransferFile already defined in moc_vrepClient.obj
1>vrepClient.obj : error LNK2005: _simxEraseFile already defined in moc_vrepClient.obj
1>vrepClient.obj : error LNK2005: _simxLoadModel already defined in moc_vrepClient.obj
1>vrepClient.obj : error LNK2005: _simxGetObjectChild already defined in moc_vrepClient.obj
1>vrepClient.obj : error LNK2005: _simxTransferFile already defined in moc_vrepClient.obj
1>vrepClient.obj : error LNK2005: _simxEraseFile already defined in moc_vrepClient.obj
1>vrepClient.obj : error LNK2005: _simxLoadModel already defined in moc_vrepClient.obj
To copy to clipboard, switch view to plain text mode
My guess is that during generation of the moc file the c files are included first and then again for the .cpp file generating the error. Moving the extern C bracket to the .cpp solves the problem but then I can't use the c code in the .h file. Any help is appreciated.
Should add I'm using win 7 x64, qt 4.8, vs2010 with qt plugin.
Thanks,
Talha
Bookmarks