I followed your suggestion to find out why compilation fails. The compilation first compiles the library and then compiles the examples. When compiling the first example, I see the following error:
[ 42%] Building CXX object CMakeFiles/servoj_example.dir/examples/cpp/servoj_example.cpp.obj
In file included from C:\CodingXP\cetoni_libraries\ur_rtde\examples\cpp\servoj_example.cpp:3:0:
C:/CodingXP/cetoni_libraries/ur_rtde/include/ur_rtde/rtde_control_interface.h:717:15: error: function 'ur_rtde::PathEntry::PathEntry(ur_rtde::PathEntry::eMoveType, ur_rtde::PathEntry::ePositionType, std::vector<double>)' definition is marked dllimport
RTDE_EXPORT PathEntry(eMoveType move_type, ePositionType position_type, const std::vector<double> parameters)
^~~~~~~~~
make[2]: *** [CMakeFiles\servoj_example.dir\build.make:82: CMakeFiles/servoj_example.dir/examples/cpp/servoj_example.cpp.obj] Error 1
make[1]: *** [CMakeFiles\Makefile2:137: CMakeFiles/servoj_example.dir/all] Error 2
make: *** [Makefile:148: all] Error 2
The example consumes the library, so it is perfectly right that the library functions are marked as dllimport
- like written in the generated export header:
# ifndef RTDE_EXPORT
# ifdef rtde_EXPORTS
/* We are building this library */
# define RTDE_EXPORT __declspec(dllexport)
# else
/* We are using this library */
# define RTDE_EXPORT __declspec(dllimport)
# endif
# endif
So that means, we are using the library and dllimport
should be defined - and it is defined, like the error message tells us. I noticed, that both mentioned functions in the error message are constructors. When reading the source code of the header, I noticed, that the classes do not use a dllexport
for the whole class but for each single member function separately:
class RTDE
{
public:
RTDE_EXPORT explicit RTDE(const std::string hostname, int port = 30004, bool verbose = false);
RTDE_EXPORT virtual ~RTDE();
...
As soon, as I remove the RTDE_EXPORT statement from both constructors the compilation succeeds.
So, that indicates, that either dllexport
macro is only allowed for class member functions but not for costructors or that MinGW has a problem, if a constructor is marked dllexport
.
I have not found a valid information so far, if class constructors should be marked as dllexport
but this seems to be the problem here.