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:

Qt Code:
  1. #include <qobject.h>
  2. #include <vector>
  3.  
  4. extern "C"
  5. {
  6. #include "extApi.h"
  7. #include "extApi.c"
  8. #include "extApiPlatform.h"
  9. #include "extApiPlatform.c"
  10. }
  11.  
  12. class VrepClient: public QObject
  13. {
  14. Q_OBJECT
  15.  
  16. public:
  17. VrepClient();
  18. ~VrepClient(){};
  19. void setJoints(std::vector<float> jntValues);
  20. bool connected() {return clientID != -1 ? true : false;}
  21.  
  22. public slots:
  23. void simulate();
  24.  
  25. private:
  26. int port;
  27. const simxChar* address;
  28. int clientID;
  29. std::vector<int> jointHandles;
  30. std::vector<float> jointValues;
  31.  
  32. bool stopSim;
  33. };
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:

Qt Code:
  1. 1>vrepClient.obj : error LNK2005: _simxGetObjectChild already defined in moc_vrepClient.obj
  2. 1>vrepClient.obj : error LNK2005: _simxTransferFile already defined in moc_vrepClient.obj
  3. 1>vrepClient.obj : error LNK2005: _simxEraseFile already defined in moc_vrepClient.obj
  4. 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