Use of MKL libraries in Visual Studio - fortran

I need to use the Fortran function "vsCdfNormInv", contained in the library 'mkl_vml.f90' (C:\Program Files (x86)\Intel\Composer XE 2015\mkl\include). I'm using Visual Studio 2013 Ultimate. How may I include the libraries by a command contained in the code? I solved the problem adding the additional dependencies to the linker: "mkl_intel_c.lib mkl_intel_thread.lib mkl_core.lib libiomp5md.lib", so the following code works.
program Console1
implicit none
REAL , DIMENSION (1:15) :: ESTRAZIONIUNIFORMI,ESTRAZIONIGAUSSIANE
CALL RANDOM_NUMBER (ESTRAZIONIUNIFORMI)
CALL vsCdfNormInv(15,ESTRAZIONIUNIFORMI,ESTRAZIONIGAUSSIANE)
end program Console1
but, using the same command in a subroutine I get a wrong vector of "ESTRAZIONIGAUSSIANE". Can anyone help me?

You could use IntelĀ® Math Kernel Library Link Line Advisor to help you generate the correct linking options required by the compiler. At least what you have linked seems not enough.

Related

Eigen matrix multiply triggers code to link to libomp.dll; it is already linked to libiomp5md.lib/dll. How do I stop this spurious linkage

A short complex piece of code is built with cmake; it links to Lapack(MKL), gmp/mpir, boost,.. and eigen3 (the versions are from vcpckg and the version of eigen is eigen3:x64-windows 3.3.9#1 ). I am currently testing it on Visual Studio 2019.
At first glance all is well and eigen does a fantastic job and commands like Eigen::FullPivLU<MatrixXS> B_lu(B); work perfectly with dynamic eigen matrices (500 dimensional) with boost multi-precision rational coefficients.
However, as soon as my code includes the line B*x;, build is still error free but the executable makes an immediate and inappropriate runtime request for libomp.dll and then crashes as I do not have it available. I cannot have it available as I am linking to the intel libiomp5md.lib and dll. Looking at the cmake cache I see BLAS_libiomp5md_LIBRARY:FILEPATH=C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/Llvm/x64/lib/libiomp5md.lib
Suggestions to get this working would be appreciated.

open cv and c++ compile release without need library for run

first i have simple code with c++ and opencv
its no matter what is the code
now in windows i used visual studio and i add the open cv library to visual stuio and compile it and its work but when i send it to another pc its need open cv library its hard to send all library so i find the program need some files like
opencv_highgui2410.dll
..... .dll
opencv_objdetect2410.dll
that's make my program run without the library
now i turned to ubuntu linux after i compile with codeblocks
this photo will show you how i linker the library
and
and i build the program and run it its work now when i sent the program to another pc its give an error some files not found like
error while loading shared libraries: libopencv_core.so.2.4
i copy this file libopencv_core.so.2.4 and add it beside the program still same error seems not like windows
any solution made me compile opencv program and run program without need full library just some of its file
or any idea to add files (libs) that's project needed to run beside program just like windows
I think this should help you.
But from the comments, i fear you have very little linux experience, I hope this will help, anyway:
https://s1meonov.wordpress.com/2010/12/27/opencv-static-linking-gnulinux-gcc/
(first, be sure to understand what shared and static libraries, how they work and how they impact on software licenses, and also be sure to understand how to install programs in linux. For installing have a look at this link: http://www.makeuseof.com/tag/beginners-guide-installing-software-ubuntu-apt/)

How to use C++ compiler by Matlab Mex compilation tool

I am trying to build a source code bundle containing m files and c++ (cpp) source files in Matlab.
The source folder has a simple Matlab Script to compile all cpp files in one folder:
function compileDir_simple(Cdir)
if nargin<1
Cdir=pwd;
end
files = dir(fullfile(Cdir,'*.cpp'));
oldDir=pwd;
cd(Cdir);
for j=1:length(files)
try
cm = sprintf('mex -largeArrayDims %s',files(j).name);
disp(cm);
eval(cm);
catch
disp(lasterr);
disp('IGNORE if the file is a C++ file which is not a mex file (ie without a mexFunction inside)');
end
end
cd(oldDir);
Inside, it uses "mex -largeArrayDims". However, my problem is, when I evaluate that statement Matlab tries to build the selected files by a C compiler which is contained in MATLAB itself. When I call mex -setup I see:
mex -setup
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler:
[1] Lcc-win32 C 2.4.1 in D:\MATLAB\R2010a\sys\lcc
[0] None
Compiler:
I installed Bloodshed C++ compiler and added its bin folder ( to the Windows Environment variables, but still I cannot see my C++ compiler in the list of installed compilers. Only Lcc-win32 appears. It will be appropriate to state that it is my first experience on compiling mex files.
A mex file on Windows is just a DLL that exports a function named mexFunction. In principle you can compile mex files with any compiler that can create Windows DLLs.
However, to do so using the mex function in MATLAB requires that MATLAB knows about your compiler. And by default MATLAB only has knowledge of a limited number of compilers. Your chosen compiler is not one of them.
Bloodshed is based on mingw. Which means that you should be able to use the Gnumex project to create a mexopts.bat file for use with your compiler.
However, I would be a little sceptical of using Bloodshed here. It is a C++ IDE and I'm not sure you particular need that. I suspect that all you are looking for is a compiler. In which case you would likely be best served by installing plain mingw.
Bloodshed C++ is not a supported compiler. Check http://www.mathworks.co.uk/support/compilers/R2014a/index.html for a list of supported compilers. Older releases are available from the same page.

Compile C++ in VS without requiring MSVCP120D.dll at runtime

I'm trying to make a binary that can be run on any windows machine without the visual c++ stuff installed (I'm assuming that's what MSVCP120D.dll is however my searching was not very fruitful as to what this actually is). I made a game for an assignment and wanted to have other people (non-devs without VS stuff installed), help me test it but they kept getting errors saying that the above dll is missing. I'm not using any Visual C++ stuff and have the /Za flag set to ensure that it's just ANSI C++. Does Visual Studio support compiling ANSI C++ and if so how do I go about making it not use Visual C++ stuff, if it doesn't support this what compiler should I use?
As you can see here, the MSVCP DLL is the platform's implementation of the C++ Standard Library. In short what that means is you cannot distribute your application without needing the "stuff" that these libraries provide. All compilers regardless of platform would need some kind of implementation of the Standard Library. Typically this is distributed in the form of libraries.
However you can distribute your application so that the "stuff" is built in to your program directly, rather than being shipped in a separate DLL. In order to do this, you must statically link your application to the Standard Library.
There are a few ways to accomplish this. One way is in Project Settings. In "Project" > "Configuration Properties" > "C/C++ Code Generation" > "Runtime Library", choose "Multithreaded (/MT)" as opposed to "Mutithreaded (Static)".
By the way, the "D" in "MSVCP120D.dll" you mentioned above means "Debug." This means that you are trying to distribute a debug build of your program. You should (almost) never do this. Distribute release builds instead.
You have three options (in the order I'd recommend):
Don't statically link, instead get people that want to run your game install the visual studio re-distributable package. 32-bit VC 2010 version here: http://www.microsoft.com/en-us/download/details.aspx?id=5555
Statically link the CRT (the dll you don't want to require at runtime) see here for details: How do I make a fully statically linked .exe with Visual Studio Express 2005?
Build an app that doesn't even use the CRT at all. Here you will have to implement your own operator new that calls HeapAlloc(), and operator delete that calls HeapFree(), its an interesting challenge ;). To do this you tell the linker to ignore all default libs.
Build with the static runtime libraries rather than the DLL versions.
Go to Properties, C/C++, Code Generation, Runtime Library and select /MTd or /MT rather than the /MDd and /MD options.
Configure your project to link against the runtime statically rather than dynamically.
First of all the D on the end of the name indicated a debug build. If you make a release build then it will need it without the D. This is important because microsoft do not allow the debug libraries to be distributed without visual studio.
The machine you are trying to run the program on may already have the release runtime installed as lots of programs use it. If not then install http://www.microsoft.com/en-us/download/details.aspx?id=30679 on the machine ( I think that's the right one but can't check at the moment)
You'll want static linking, that 'builds in' the external library calls into your binary. It does have the added affect of larger binary file, but in your case that doesn't sound like that big of a deal.
On a side note, MSVCP120D.dll is the Microsoft Visual C++ 12 debug DLL (dynamic link library) that contains all of debug C++ libaries (i.e. iostream, string, etc). That library is what you would be 'baking in' to your final binary.
Hope that helps.
I encountered this error when I tried to execute my exe on a different machine that had a newer version of Visual Studio on it. You need to change the project properties and re compile in order for this to go away.
To do this:
Open up solution that you are trying to run
Right click on the Project file - > Properties
In Configuration Properties and General, Ensure Platform Toolset is configured to be the correct compiler on your machine. If it is not correct, it should give a message next to it saying that it's not installed.
Build and run the code again and you should no longer get the issue.

Static Runtime Library Linking for Visual C++ Express 2008

How do you tell Visual C++ Express 2008 to statically link runtime libraries instead of dynamically? My exes do not currently run on computers w/o some sort of VS installed and I would love to change that. :)
Sorry, I do not have VC++ Express to test, but in Standard edition I use Project Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library. Dll and Dll Debug are for dynamic linking.
Are you 100% sure that you want to do this? Please consider that if you do and there is a security vulnerability found in the runtime library, Microsoft will not be able to patch your application via Windows Update.
Another solution is to package the Visual C++ Runtime Redistributable with your application. It installs very fast and does not require Visual Studio. It is also important to note that you should not distribute code linked against the debug runtime libraries as those do require Visual Studio. See this blog post for more information on packaging the redistributable.
EDIT: With that said, it's up to you. My point is simply that you should not disregard dynamic linking based solely on the idea that users must have "some sort of VS installed", which is not true.
See the answer to this question: How do I make a fully statically linked .exe with Visual Studio Express 2005 ?. It's for VS2005 Express but the answer still holds.
For the C-runtime go to the project
settings, choose C/C++ then 'Code
Generation'. Change the 'runtime
library' setting to 'multithreaded'
instead of 'multithreaded dll'.
If you are using any other libraries
you may need to tell the linker to
ignore the dynamically linked CRT
explicitly.
You can install the C runtime redist on the target machine and you're executable would run there as well with dynamically linked C runtime.
(Oh sorry, that had already been mentioned).