load vrep.dll from a custom main application

Typically: "How do I... ", "How can I... " questions
Post Reply
stan94111
Posts: 5
Joined: 13 May 2019, 13:18

load vrep.dll from a custom main application

Post by stan94111 » 14 May 2019, 08:20

Hello Coppelia,
I'm trying to realize a customized version of the main client application in c++ using visual studio 2019 on windows. I'have started from the basis trying to load the vrep.dll library.
the code is the following:

Code: Select all

#include <iostream>
#include <vector>
#include "v_repLib.h"
#include <direct.h>
#include "_dirent.h"
#include "v_repConst.h"
#include <Windows.h>
#include <process.h>
#include <shlwapi.h>
#include "luaFunctionData.h"
#pragma comment(lib, "Shlwapi.lib")
#define THREAD_RET_TYPE void
#define THREAD_RET_VAL void()

int main()
{
	char curDirAndFile[1024];

	std::string currentDirAndPath(curDirAndFile);
	std::string temp(currentDirAndPath);
	temp += "v_rep";


	LIBRARY vrepLib;
	std::cout << "Loading the V-REP library...\n";
	vrepLib = loadVrepLibrary(temp.c_str());
	if (vrepLib != NULL)
	{
		std::cout << "Done!\n";
		return(0);
	}
	else
	{
		std::cout << "Error: could not find V-REP library\n";
		return(1);
	};
}
of course, after the compilation, it returns "Error: could not find V-REP library". But the .dll file is in the same directory of the .exe generated by the code. What's wrong ? (Also all others required .dll, according with the user manual, are in the same directory)

fferri
Posts: 304
Joined: 09 Sep 2013, 19:28

Re: load vrep.dll from a custom main application

Post by fferri » 14 May 2019, 08:33

Use a tool such as Dependency Walker to check that you included all dependencies of V-REP's .dll

stan94111
Posts: 5
Joined: 13 May 2019, 13:18

Re: load vrep.dll from a custom main application

Post by stan94111 » 14 May 2019, 09:19

Thanks for the reply.
It seems there are a lot of .dll file missing ( such us IESHIMS.DLL ), but this wasn't specified in the vrep manual and I have no idea of where are located these additional dll's .
Image

fferri
Posts: 304
Joined: 09 Sep 2013, 19:28

Re: load vrep.dll from a custom main application

Post by fferri » 14 May 2019, 12:56

A lot of those DLLs can be standard windows DLLs that are installed in C:\Windows\system32 or similar

stan94111
Posts: 5
Joined: 13 May 2019, 13:18

Re: load vrep.dll from a custom main application

Post by stan94111 » 14 May 2019, 14:25

thanks to that small tool I've fixed the problem. The .dlls use x64 CPU but I was debugging my project with x86.
Now I've succesfully loaded vrep library and I'm currently trying to configure my simulation.
Following vrep manual's indications I've developed the following code:

Code: Select all

#include <iostream>
#include <vector>
#include <direct.h>
#include "v_repLib.h"
#include "v_repConst.h"
#include "_dirent.h"
#include <Windows.h>
#include <process.h>
#include <tchar.h>

simVoid(*simulatorLoop)() = nullptr;
simVoid(*simulatorDeinit)() = nullptr;
simVoid(*simulatorInit)() = nullptr;

int main()
{
	std::cout << "loading the V-REP library..\n";
	LIBRARY vrepLib = loadVrepLibrary("v_rep.dll");
	if (vrepLib != NULL && getVrepProcAddresses(vrepLib) != 0)
	{
		std::cout << "Done!\n";
		int res = simRunSimulator("v-rep", sim_gui_headless, simulatorInit, simulatorLoop, simulatorDeinit);
		std::cout << "Unloading the V-REP library...\n";
		unloadVrepLibrary(vrepLib);
		std::cout << "Done!\n";
		return 0;
	}
	else
	{
		std::cout << "no library found\n";
		return -1;
	}
}
but the result is the following:

Code: Select all

loading the V-REP library..
Done!

V-REP PRO EDU V3.6.1. (rev. 2)
qt.qpa.plugin: Could not find the Qt platform plugin "windows" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Someone can help me to understand what's wrong ?

fferri
Posts: 304
Joined: 09 Sep 2013, 19:28

Re: load vrep.dll from a custom main application

Post by fferri » 15 May 2019, 09:27

Probably related: "could not find or load the Qt platform plugin "windows" in "", on Qt forum.

Did you copy the platforms directory to the target directory?

stan94111
Posts: 5
Joined: 13 May 2019, 13:18

Re: load vrep.dll from a custom main application

Post by stan94111 » 15 May 2019, 13:38

Thank you very much!! I've solved also this issue adding folder platforms to the directory.

Now I've tried to compile the simulatorInit and simulatorDeinit that I've found on the github repository of coppelia robotics. The code is the following (with some trivial rearrangments respect to the original one):

Code: Select all

#include <QtCore/QCoreApplication>
#include <QtWidgets/QApplication>
#include <QLibrary>
#include <QFileInfo>
#include <QDir>
#include <iostream>
#include <vector>
#include <Windows.h>
#include <process.h>
#include <tchar.h>
#include <direct.h>
#include "v_repLib.h"
#include "v_repConst.h"
#include "_dirent.h"
#include <algorithm>
#define THREAD_RET_TYPE void
#define THREAD_RET_VAL void()

int stopDelay;
int options;

simVoid(*simulatorLoop)() = nullptr;

std::vector<int> pluginHandles;

int loadPlugin(const char* theName, const char* theDirAndName)
{
	std::cout << "Plugin '" << theName << "': loading...\n";
	int pluginHandle = simLoadModule(theDirAndName, theName);
	if (pluginHandle == -3)
		std::cout << "Error with plugin '" << theName << "': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.\n";
	if (pluginHandle == -2)
		std::cout << "Error with plugin '" << theName << "': load failed (missing entry points).\n";
	if (pluginHandle == -1)
		std::cout << "Error with plugin '" << theName << "': load failed (failed initialization).\n";
	if (pluginHandle >= 0)
		std::cout << "Plugin '" << theName << "': load succeeded.\n";
	return(pluginHandle);
}

simVoid simulatorInit()
{
	std::cout << "Simulator launched.\n";
	std::vector<std::string> theNames;
	std::vector<std::string> theDirAndNames;
	
	QFileInfo pathInfo(QCoreApplication::applicationFilePath());
	std::string pa = pathInfo.path().toStdString();
	QDir dir(pa.c_str());
	dir.setFilter(QDir::Files | QDir::Hidden);
	dir.setSorting(QDir::Name);
	QStringList filters;
	int bnl = 8;
	std::string tmp("v_repExt*.dll");
	filters << tmp.c_str();
	dir.setNameFilters(filters);
	QFileInfoList list = dir.entryInfoList();
	for (int i = 0; i < list.size(); ++i)
	{
		QFileInfo fileInfo = list.at(i);
		std::string bla(fileInfo.baseName().toLocal8Bit());
		std::string tmp;
		tmp.assign(bla.begin() + bnl, bla.end());
		if (tmp.find('_') == std::string::npos)
		{
			theNames.push_back(tmp);
			theDirAndNames.push_back(fileInfo.absoluteFilePath().toLocal8Bit().data());
		}
	}
	for (size_t i = 0; i < theNames.size(); i++)
	{
		if ((theNames[i].compare("MeshCalc") == 0) || (theNames[i].compare("Dynamics") == 0))
		{
			int pluginHandle = loadPlugin(theNames[i].c_str(), theDirAndNames[i].c_str());
			if (pluginHandle >= 0)
				pluginHandles.push_back(pluginHandle);
			theDirAndNames[i] = ""; 
		}
	}
	simLoadModule("", ""); 
	for (size_t i = 0; i < theNames.size(); i++)
	{
		if (theDirAndNames[i].compare("") != 0)
		{
			int pluginHandle = loadPlugin(theNames[i].c_str(), theDirAndNames[i].c_str());
			if (pluginHandle >= 0)
				pluginHandles.push_back(pluginHandle);
		}
	}
}

void simulatorDeinit()
{
	for (size_t i=0;i<pluginHandles.size();i++)
		simUnloadModule(pluginHandles[i]);
	pluginHandles.clear();
	std::cout << "Simulator ended.\n";
}

int main(int argc, char* argv[])
{   
	std::cout << "loading the V-REP library..\n";
	LIBRARY vrepLib = loadVrepLibrary("v_rep.dll");
	if (vrepLib != NULL && getVrepProcAddresses(vrepLib) != 0)
	{
		std::cout << "Done!\n";
		std::cout << "Simulator Launched!\n";
		simInt res = simRunSimulator("V-REP", sim_gui_headless, simulatorInit, simulatorLoop, simulatorDeinit);
		std::cout << "Unloading the V-REP library...\n";
		unloadVrepLibrary(vrepLib);
		std::cout << "Done!\n";
		return 0;
	}
	else
	{
		std::cout << "no library found\n";
		return -1;
	}

}
But the output on the prompt says "QCoreApplication::applicationFilePath: Please instantiate the QApplication object first",
and then fails to upload all the plugins (mehsclacl , OMPL , dynamics ecc ecc..), altough they are all present in the same directory of the application...

I suppose the problem is related to that initial indication regarding QApplication but I don't know how to fix it.
Can you help me ?

fferri
Posts: 304
Joined: 09 Sep 2013, 19:28

Re: load vrep.dll from a custom main application

Post by fferri » 15 May 2019, 13:49

stan94111 wrote:
15 May 2019, 13:38
But the output on the prompt says "QCoreApplication::applicationFilePath: Please instantiate the QApplication object first",
Do you see any other errors prior to that? Please post complete output.

stan94111
Posts: 5
Joined: 13 May 2019, 13:18

Re: load vrep.dll from a custom main application

Post by stan94111 » 15 May 2019, 13:55

running the code in release mode instead of debug mode, the problem related to QApplication disappears. But I still have the problem of failed uploading of all the plugins.
The Application generates the following results:

Code: Select all

loading the V-REP library..
Done!
Simulator Launched!

V-REP PRO EDU V3.6.1. (rev. 2)
Using the default Lua library.
Simulator launched.
Plugin 'MeshCalc': loading...
Error with plugin 'MeshCalc': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'Assimp': loading...
Error with plugin 'Assimp': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'BlueZero': loading...
Error with plugin 'BlueZero': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'BubbleRob': loading...
Error with plugin 'BubbleRob': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'Bwf': loading...
Error with plugin 'Bwf': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'CHAI3D': loading...
Error with plugin 'CHAI3D': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'Cam': loading...
Error with plugin 'Cam': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'CodeEditor': loading...
Error with plugin 'CodeEditor': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'Collada': loading...
Error with plugin 'Collada': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'ConvexDecompose': loading...
Error with plugin 'ConvexDecompose': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'CustomUI': loading...
Error with plugin 'CustomUI': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'DynamicsBullet-2-78': loading...
Error with plugin 'DynamicsBullet-2-78': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'DynamicsBullet-2-83': loading...
Error with plugin 'DynamicsBullet-2-83': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'DynamicsNewton': loading...
Error with plugin 'DynamicsNewton': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'DynamicsOde': loading...
Error with plugin 'DynamicsOde': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'DynamicsVortex': loading...
Error with plugin 'DynamicsVortex': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'ExternalRenderer': loading...
Error with plugin 'ExternalRenderer': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'ICP': loading...
Error with plugin 'ICP': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'Image': loading...
Error with plugin 'Image': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'Joystick': loading...
Error with plugin 'Joystick': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'K3': loading...
Error with plugin 'K3': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'LuaCommander': loading...
Error with plugin 'LuaCommander': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'LuaRemoteApiClient': loading...
Error with plugin 'LuaRemoteApiClient': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'Mtb': loading...
Error with plugin 'Mtb': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'OMPL': loading...
Error with plugin 'OMPL': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'OpenMesh': loading...
Error with plugin 'OpenMesh': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'PovRay': loading...
Error with plugin 'PovRay': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'Qhull': loading...
Error with plugin 'Qhull': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'RRS1': loading...
Error with plugin 'RRS1': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'ReflexxesTypeII': loading...
Error with plugin 'ReflexxesTypeII': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'RemoteApi': loading...
Error with plugin 'RemoteApi': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'SDF': loading...
Error with plugin 'SDF': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'SurfaceReconstruction': loading...
Error with plugin 'SurfaceReconstruction': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'Urdf': loading...
Error with plugin 'Urdf': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'Vision': loading...
Error with plugin 'Vision': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
Plugin 'Wii': loading...
Error with plugin 'Wii': load failed (could not load). The plugin probably couldn't load dependency libraries. Try rebuilding the plugin.
The 'MeshCalc' plugin could not be initialized.
all the .dll files (such us v_repExtOMPL.dll) are in the same folder of the application .

coppelia
Site Admin
Posts: 7123
Joined: 14 Dec 2012, 00:25

Re: load vrep.dll from a custom main application

Post by coppelia » 17 May 2019, 10:37

Not sure about the compatibility of vs2019 and vs2017 (which is the version used to compile the plugins). Did you install the vs2017 distributables?
Again, use dependency walker to check dependencies of the plugins.

Cheers

Post Reply