How to convert a C++ program that uses CUDA into MEX - c++

For work, I am converting the Image Denoising program that comes with the CUDA SDK into a MATLAB program. As far as I know, I have made all the necessary changes required by MATLAB, but when I try to call mex on it, MATLAB returns a bunch of linkage errors that I have no idea how to fix. If anyone has any suggestions on what I might be doing wrong, I would greatly appreciate it.
The command I am giving MATLAB is:
mex imageDenoisingGL.cpp -I..\..\common\inc -IC:\CUDA\include -L..\..\common\lib -lglut32
And the output from MATLAB is a bunch of these:
imageDenoisingGL.obj : error LNK2019: unresolved external symbol __imp__cutCheckCmdLineFlag#12 referenced in function "void __cdecl __cutilExit(int,char * *)" (?__cutilExit##YAXHPAPAD#Z)
I am running:
Windows XP x32
Visual Studio 2005
MATLAB 2007a

You need to link the CUDA libraries to your MEX file. It looks like you're also using some of the "cutil.h" stuff from the CUDA SDK (such as cutCheckCmdLineFlag), so you'll need to link against not only the cudart library, but also cutil. I.e. you probably need to add something like
-Lc:\CUDA\lib -lcudart -lcuda -L<path-to-cutil.lib> -lcutil
to your MEX command-line.

If you are converting from CUDA to MATLAB, then why are you still calling the CUDA functions?
unresolved external symbol
__imp__cutCheckCmdLineFlag#12

High Performance Mark is suggesting, in his comment, to compile mexfiles using CUDA directly under Visual Studio. At the page
Compiling CUDA mex files with Visual Studio
it is described how the compile mexfiles using CUDA under Visual Studio. There is also a downloadable Visual Studio sample project.
The procedure has been tested for CUDA 5.0, Visual Studio 2010 and Matlab 2010a/2012b, but perhaps it could be of interest also to people using other versions of the above products.

Related

Unresolved external symbol error while trying to run PARDISO on windows 10

I downloaded the PARDISO libraries from https://www.pardiso-project.org and obtained the license too. As per the user manual, I have installed Microsoft Visual Studio 2019 as well as Intel Parallel XE 2020 for the cl and Intel compilers. I have placed the .dll file, the .lib file and the .exp file along with the license (.lic file) in c:\users\hp. Microsoft Visual Studio has been installed and the source and repository folders are placed in c:\users\hp\Source.
I tried to run the sample code on Visual Studio : https://pardiso-project.org/manual/pardiso_unsym.f (equivalent C++ code is https://pardiso-project.org/manual/pardiso_unsym.cpp)
I got the following errors:
For the C++ code:
unresolved external symbol pardisoinit referenced in function main Trial4 C:\Users\hp\source\repos\Trial4\Trial4\tryout1.obj 1
For the Fortran code:
error LNK2019: unresolved external symbol _PARDISOINIT referenced in function _MAIN__ Tryout2.obj
I know that all this has something to do with the libraries being placed in the correct place but I am unable to figure it out correctly. Could someone tell me how I can solve this problem? I am using Microsoft Visual Studio 2019.

link MinGW gcc c++ application against mvsc c++ .lib

I need to integrate the Intel RealSense C++ library (legacy 2016 R3 not the current 2.0 SDK) to an already existing application built with Qt MinGW g++ 32-bit (installed by Qt5.11 offline installer)
basically, they provide the headers and some .lib files to compile and link applications
when I try to compile the Segmentation example in Visual Studio, they work, (they provide a .props file that I can add to the Visual Studio Solution's Project's Property Manager, btw, I am using Visual Studio Community 2017 on Windows 10 Home 64-bit), but, the application I am developing was made using QtCreator so I need to be able to compile with QtCreator, and migrating the build to Visual Studio might not be a viable solution
if I try to compile the Segmentation example with MinGW (32-bit) in QtCreator (installed by Qt5.11 offline installer) I get error messages like this one
C:\src\Debug\app\main.cpp:34: error: undefined reference to `UtilCmdLine::UtilCmdLine(Intel::RealSense::Session*, int)'
and even if I try to use MSVC (64-bit) in QtCreator (installed by Qt5.11 offline installer) (which is not really a great option)
I get error messages like this one
C:\src\Debug\app\main.cpp.obj:-1: error: LNK2019: unresolved external symbol PXCSession_CreateFromPath referenced in function "public: static class Intel::RealSense::SenseManager * __cdecl Intel::RealSense::SenseManager::CreateInstance(wchar_t const *)" (?CreateInstance#SenseManager#RealSense#Intel##SAPEAV123#PEB_W#Z)
for several symbols
has anyone solved a similar problem?
MinGW I think I understand not working, because of MSVC symbol mangling and a general different ABI, and because the tools to work with .lib files in MinGW are no longer being available (at least not in the official website), but why is MSVC not working? am I missing something that Visual Studio has that QtCreator does not?
would there be a way to make something like a wrapper library in visual studio so that I can use in MinGW? I saw some people who had similar problems with .lib files being told to use a COM style interface if they could
I saw that being the
just to clarify, I'm not sure if it's a problem introduced by the Qt libraries but there is some of the application's code just doesn't compile correctly with MSVC, so for now, I'd prefer a way to compile with MinGW in QtCreator, though we might eventually get it to work with both compilers (or at least try to)

Invalid MEX-file - Compiled with VisualStudio 2013

I have a .mexw32-file which is compiled in VisualStudio 2013 and i try to call that function in Matlab 2013. The mex-file use a libary ("plug_feedfwd.lib") to control a mirror.
I can compile the project in VS2013 without failures and warnigns, so it seems that all libarys and header-files are included correctly.
But if i try to call the mex-file in Matlab, it trows the following exception:
"Invalid MEX-file -pathOfTheMexFile-: The specified module could not be found."
If I comment all lines where methodes call the libary, the mex-file works in matlab. So it seems that Matlab got a problem with this library, but VisualStudio can deal with it.
I have found this link but it didnt help much:
http://de.mathworks.com/help/matlab/matlab_external/invalid-mex-file-error.html
The matlab-version must be compatible cause i can call the mex-function if i dont use methodes from the library.
The dependencywalker show always missing librarys, also if the mex-function works - and if i use my invalid mexfile the missing librarys are the same as before
I also tryied to copy all librarys in the same folder as the mex-file
My System:
Windows 8.1 x64,
Matlab 2013 x32,
Visual Studio: 2013,
Mex-function: x32,
has anyone a idear what can i try next?
gereetings, Stefan

Compiling FFTW 3.3.4 With Visual Studio 2013

Has anyone managed to compile the latest release of FFTW 3.3.4 using the Visual C++ compiler? I'm aware that the project maintainers offer pre-compiled dll's that were built with MinGW, but I'm looking to compile them myself.
So far, I've downloaded the source (of course), and I am trying to use one of the pre-made VS solutions that was reported to work for Visual Studio 2010 and FFTW 3.3, but when I'm building, I'm getting a few "unresolved external" errors like the following:
Error 1259 error LNK2019: unresolved external symbol _fftwf_mkprinter_str referenced in function _fftwf_export_wisdom_to_string C:\Users\bryan\Downloads\fftw-3.3.4\fftw-3.3.4\fftw-3.3-libs\libfftwf-3.3\export-wisdom-to-string.obj libfftwf-3.3
I know this is a bit of a stretch, but has anyone built FFTW 3.3.4 using Visual Studion 2013?
I have had the same problem.
Take a look on
http://wiki.panotools.org/Hugin_SDK_%28MSVC_2013%29
There is explained how you can build libfftw-3.3
In the same way you can build libfftwf-3.3
To build bench and benchf you have to remove '....\libbench2\aligned-main.c'
That is explained here (commentar 6)
Compiling FFTW source in Visual studio

Linking zlib in Visual Studio 2012

I have a C++ program that compiled and ran fine on Linux that I am now trying to compile on a Windows machine in Visual Studio. The main problem I'm facing is the following error message:
error LNK2019: unresolved external symbol _gzread referenced in function
I have downloaded the zlib library and attempted to link it to my project, but apparently unsuccessfully. I'd appreciate clear instructions on how to link this to my project. The less you assume in your instructions, the better, as I'm relatively new to Visual Studio.
Found the solution. Even though I'm working on a 64-bit machine, VS was compiling in 32-bit mode. I just used the 32-bit version of zlibwapi instead of the 64-bit version and it worked.