"No functions found" warning importing external dll file - c++

Good afternoon,
I'm trying to work with some C++ dll files with Matlab, and I'm trying to implement a simple test case to understand the procedure. The dll file I'm using is copied verbatim from here:
https://msdn.microsoft.com/en-us/library/ms235636.aspx
I only implement up to step 5, since my hope is to call the dll file through Matlab. After completing step 5, I copy MathLibrary.h and MathLibrary.dll to the directory I'm using for my Matlab code, and then run
[notfound,warnings]=loadlibrary('MathLibrary.dll','MathLibrary.h');
Upon running this I get the warning
>Warning: No functions found in library.
>
>In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 431
The cell array notfound is empty and warnings is an array with warnings = MathLibrary.h
If I try using one of the functions from the dll, I execute the following code:
calllib('MathLibrary','Add',5,3)
which throws the following error
>Error using calllib
>
>Method was not found.
I've tried Googling solutions to similar problems, but have not found solutions where I've looked (at least ones I've understood). My C++ is weak, which may be hindering my understanding of the problem and solution. I'm hoping to incorporate dll files from a much larger project soon, so understanding this would be a great help. Thanks so much!

Related

How can I compile a mex function in Windows with Eclipse (4.20.0 version) and Matlab (R2021a)

I'm trying to compile a c++ mex function that I created according to the specifications given by mathworks here (Create a C++ MEX Source File). However, after following the steps of the answer in this thread to link Eclipse 4.4.2 and Matlab R2015a in a linux enviroment (old but the only one I've found about it), I get the following error:
undefined reference to `get_function_ptr' mpi_pevd_mex_f line 79, external location: C:\Program Files\MATLAB\R2021a\extern\include\MatlabDataArray\detail\ExceptionHelpers.hpp C/C++ Problem
I don't know what else is missing. I've been trying to find a solution, but nothing useful so far.
Thank you for your help.
I have found the problem. Apparently, I needed to add additional libraries to those detailed in most of the posts related to MEX files, i.e. libmex/ libmat/libmx.
Making use of the verbose mode in Matlab (mex -v MexFunction.cpp), I realized that these libraries were missing: libmwlapack, m, libmwblas, libMatlabEngine, libMatlabDataArray. After adding them, the error disappeared.

Train net using caffe DLL in C++

The most recent Windows Branch of caffe (https://github.com/BVLC/caffe/tree/windows) provides the option to compile caffe as a DLL.
I found it hard to find example code how to use the DLL in another C++ project as most people use the python interface, which is not a preferred option in my case. Looking at the implementation of the train() method in caffe.cpp, I tried the following to train a net:
caffe::SolverParameter solver_param;
caffe::ReadSolverParamsFromTextFileOrDie("C:\\path\\to\\solver.prototxt", &solver_param);
Caffe::set_mode(Caffe::GPU);
shared_ptr<caffe::Solver<float>>
solver(caffe::SolverRegistry<float>::CreateSolver(solver_param));
solver->Solve();
Unfortunately, the first line throws a linker error, although I added caffe.lib and specified the path to caffe.lib and caffe.dll in my project properties in VS. Accessing other caffe functions (such as set_mode) works fine.
Apart from the linker error (suggestions to solve it are appreciated!), does the code look plausible to you? Did anyone manage to use caffe functionalities in C++ and is willing to share a code snippet?
You need to link to caffeproto.lib and to libprotobuf.lib to solve dependencies error for this piece of code.
Just diving into caffe so I can't really judge your code. I am looking at this:https://medium.com/#shiyan/caffe-c-helloworld-example-with-memorydata-input-20c692a82a22 and so far found it helpful.

Build error referring to yvals.h in a cantata++ test project

I am testing c++ source codes using the tool cantata++. I created a project, built it and encounter the following error message.
error I9282: the global scope has no "_invalid_parameter" C:\LegacyApp\VisualStudio2005\VC\include\yvals.h 167
I find this error wierd, because yvals.h is not really a file in my source codes. What does this error message imply?
You'll find that yvals.h is probably included by one of the many system header files the Microsoft compiler includes, and you are only seeing it in the error message because the Cantata++ instrumenter is finding a problem with it. My guess would be that there is some problem with the settings in either Cantata++, your Visual Studio project or a mismatch between the two meaning they are not using the same settings.
In order to help diagnose the problem it would help to know a few things about the setup you have, and the code you are building when you get the error.
As Joachim Wuttke said, I would suggest you contact the Cantata Technical Support team directly if you are still having problems with this issue. They will be able to provide you with further information to help solve the problem.

using NtCreateSection from ntdll.lib

I was just trying to use NtCreateSection in my code and the information at this link states the requirement as ntdll.lib. As Im using VS2010, I went to Projects > Properties > Linker > Input > Additional Dependencies and added ntdll.lib.
However, on building the solution I get an error error C3861: 'NtCreateSection': identifier not found. I'm curious about why this happens.
A workaround I'm considering is getting a handle to ntdll using LoadLibrary and getting a handle to NtCreateSection using GetProcAddress; however Im just curious about why the earlier method did not work out.
Thanks!
Perhaps of interest is the actual documentation of the function: http://msdn.microsoft.com/en-us/library/windows/hardware/ff556473(v=vs.85).aspx
This points you to a ZwCreateSection function, which notes that NtCreateSection is the name to be used for user-mode calls to this function: http://msdn.microsoft.com/en-us/library/windows/hardware/ff566428(vr85).aspx
In the standard header/library reference in the actual documentation, it says Wdm.h is the header to be included. I would recommend checking that file for the function(s), and proceeding from there. The docs for both functions, and the guide pages linked from them, also seem to have some info on things.

Basic example code compiling help required - I can't get any SDK examples to work

I'm very new to C++; I've worked with several SDKs now on various applications and every time come across the problem that I can't get the 'example code' to compile. This is a very broad question basically regarding ANY example code that is given over the net - what is the standard procedure to make things compile? I know how to compile code that I've written myself but when given a large project containing several CPP and H files, what do I start with? My first port of call, to open 'main.cpp' in Dev-C++ and hit the 'compile' button generally throws up errors about header files not being available and so on.
I won't give a specific example as this has happened several times. I feel as someone getting to grips with C++ that I would learn a lot quicker if I could start with code that works and tweak it myself rather than having to fumble around building things up piece by piece.
The most recent example is a set of example code provided by a company which 10 files:
-Arial.ttf
-demo_resources.rc
-icon.ico
-main.c
-simple.dsp
-simple.dsw
-simple.exe
-simple.h
-trial.c
-trials.c
Running the .exe file works absolutely fine; however if I open main.c and press compile, I receive many error messages. As an example, the first two lines of code in main.c are:
#include "simple.h"
#include <sdl_text_support.h>
This alone spews the error messages:
1: expected unqualified-id before "public"
1: expected `,' or `;' before "public"
2: In file included from trial.c
Clearly I am doing something very wrong as this code must have compiled for someone else in the past to have generated the .exe file. Again this is not an isolated issue, I have this problem all the time.
Since Dev-C++ is perfectly equipped to deal with plain old C files, I can't see that that is the issue. Secondly, simple.h is definitely included in the correct directory. The second include though, sdl_text_support.h is obviously not in my file list above. I have searched the rest of the SDK and found the file lurking elsewhere. How do I explicitly reference the location of the header file using Dev-C++?
Any general tutorial to how to compile pre-made projects or help of any kind would be greatly appreciated.
I like this page:
http://www.cprogramming.com/tutorial.html
I am not familiar with DevC++, but you cannot assume that if you can open main.c and press a button, then everything will work out. No build system is that smart.
If you write your own code (and you understand compiling and linking) then you can keep your files in order and know exactly how to build everything; someone else's codebase may come with a makefile or some other guide to it's organization, but you'll have to learn how to use a good build system, and the one you're using sounds inadequate.
open the project by simple.dsw instead of main.cpp and it should work .