I am using codegen in MATLAB R2016b to generate a .dll file as follows:
codegen -config:dll ex_fun.m -args {0,0,0,0,0,0}
I have tried to include the dll file as a reference using Visual Studio 2015 but nothing works fine and I couldn't use the .lib file as a linker eitherll.
The strange thing is that I could easily use gcc on Linux by compiling the .c script that calls the C function along with the output .so file (which is equivalent to .dll in windows) as follows:
gcc main.c ex_fun.so -Wl,-rpath=$(pwd)
However, I couldn't find any direct method in Windows. How can I use and call a .dll file output by MATLAB in a C main script program?
It should be noted that a .def file is also generated but I don't how to use it along with the output dll file.
In Visual Studio IDE:
Switch platform to "x64"
In Project properties:
C++>General>Additional include directories = ^add compilation folder.
Linker>General>Additional libraries directories = ^add compilation
folder.
Linker>Input>Additional Dependencies = "ex_fun.lib"
In code: add #include "ex_fun.h"
After compilation, copy the "ex_fun.dll" to output folder and run.
Related
I am trying to run a C compiler with Cython in a 64-bit Windows 7 platform.
After having various problems with the C compilers from Visual studio and MinGW32, I tried to install MinGW_w64. I did the following steps :
-I downloaded and extracted winbuilds from http://mingw-w64.org/doku.php/download/win-builds, and I selected the Base GCC package with C support.
-I added C:\PATH_TO_WINBUILDS and C:\PATH_TO_WINBUILDS\bin in the PATH Windows environment variable.
-I wrote helloworld.c, a very simple C program :
#include<stdio.h>
main()
{
printf("Hello World");
}
-Then in cmd I wrote:
gcc helloworld.c -o helloworld.exe
And a dialog box pops out with the following error message :
Impossible to start program because libiconv.dll is missing on your computer. Reinstall program to correct problem.
The dll file does not appear in the lib folder of MinGW_w64. I tried to copy libiconv.a and libiconv.dll.a from the MinGW32 lib folder to the lib folder of MinGW_64, but still no luck.
Any ideas?
You need the DLL file, not the .a link library files. libiconv.dll should exist somewhere in the bin directory. If it is not there, you’ll need to get it from the internet or compile it yourself. Alternatively you could just link statically to the iconv library.
Once you find the DLL, make sure it is in one of the following locations:
* the %PATH%
* the appropriate C:\Windows\system32 or C:\Windows\SysWOW64 directory
* (preferably) next to your executable
I was able to fix the problem by downloading another version on the package on SourceForge.
Thanks!
I'm trying to compile the source of sqlite3.c and shell.c I downloaded from the SQLite website using Visual Studio 2015. I created DLL project sqlite3 and put the sqlite3.c source into it. Then I created project sqlite3shell and put shell.c source into it. I added include "stdafx.h" into both. When I compiled both projects the DLL did not produce a .lib file, so the compile of sqlite3shell got the error LNK1104 cannot open sqlite3.lib.
I manually created a .lib file using this solution. Then the sqlite3shell program compiled successfully. But when I went to run the program, I got the error The application was unable to start correctly (0xc000007b). Looking into this error is seems one reason it could be caused is by trying to access a 64-bit program from a 32-bit program. But everything was created using the x86 configuration.
Is there some way to have the DLL compile produce the correct .lib file? Or if that won't fix the problem, is there something I can do to prevent the 0xc000007b error?
In case someone else should have this problem, I have found the solution. There were 2 lines that specified the define of SQLITE_API. I added the export to the define like this: # define SQLITE_API __declspec(dllexport). Apparently there were no exports, so that was why the .lib file was never created. With the change, the .lib and .exp files were created and then the program didn't get the 0c000007b error.
I have some C code (having various header files and a make file) compiled as a .so file in Linux(Ubuntu) and a python program which calls the functions of this shared object using Ctypes. Now, I want to use this program on windows. In windows, Ctypes needs a .dll file instead of .so in linux.
So, is there a way in which I can convert the .so files of linux into .dll files to be used with Ctypes in Windows ?
No. You will need to recompile the library for Windows.
I need to use the library libMPSSE.dll in my win32 console application project in MSVC 2010. After writing the code I just copied the dll in the folder where my .cpp file is present. I am able to compile successfully but the issue is I am having linking error:
libMPSSE.dll : fatal error LNK1107: invalid or corrupt file: cannot
read at 0x308
Is it really a problem with the dll itself or is there any problem with the dll path. How do we add dll to projects?
They have not provided any .lib file. The complete code is here
These are the usual steps to link to a DLL:
Include the DLL's header file in any of your source files that need to use functions from the DLL. You'll typically need to make sure that your build environment's include path contains the location of the header file. In the IDE you can do this using the Additional Include Directories configuration setting.
Pass the DLL's .lib file to the linker. In the IDE you do this by adding the .lib file to the Additional Dependencies setting. And you'll typically need to add the path to the .lib file to the Additional Library Directories setting.
Having done that, your program should compile and link. To make it run, you'll need to ensure that the DLL itself can be found at runtime. The simplest way to make that happen is to put it in the same directory as the executable file.
My guess, looking at your error message, is that in step 2 you passed the .dll to the linker rather than passing the .lib file.
As said here earlier you can't link to .dll files with C linker directly.
There're win32 APIs that can load the .dll file and return to you pointers to function.
Usually, .dll file is accompanied with .lib file contains code that does this burden for you and provides the API .dll file exposes. All you need is to link to this .lib file and put .dll file near the .exe file created.
Specifically regarding libMPSSE, it's said in its release notes that you can rename the provided .a file to .lib file to link to it in Visual Studio (Project properties->configuration properties->Linker->Input). I tried it and it works as supposed.
I've recently written a C program which uses the public-domain mpir and mpfr libraries. I've been compiling it on Windows, using the Microsoft Visual C++ 10.0 compiler. To get that to work, I had to do the following:
Download / build the mpir and mpfr libraries from http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php
Move the files mpir.h and mpfr.h into the Include directory for the Microsoft compiler
Move the files mpir.lib, mpir.pdb, mpfr.lib and mpfr.pdb into the lib directory for the Microsoft compiler
#include mpir.h and mpfr.h in the program
Compile using cl <..module names..> /link mpir.lib mpfr.lib
I now want to send the source / header files I've written to someone else, along with a makefile that they can use to compile the code and check that it works. Since that person won't have the mpir / mpfr libraries installed, and might not be using the same compiler, I'm not quite sure how to do this.
Here is what I can do:
Send them the binaries mpir.lib, mpir.pdb, mpfr.lib and mpfr.pdb as well as the source / header files.
Here is what I can't do:
Send them my entire Microsoft Visual C++ 10.0 setup
Ask them to stick files in their Include and lib directories (unless there's no other way)
Ideally, I should be able to send them the source/header files, together with the pertinent mpir/mpfr binaries, and a makefile which they can then run to build the program.
Thanks in advance for your help!
Why on earth are you adding those files to your compiler installation path?? The compiler has command line options for specifying search paths.
For instance,
cl /I"path/to/mpfr/header" <...filenames...> /link /LIBPATH:"path/to/mpfr/lib" mpir.lib mpfr.lib
You should only have to send your source code, mpir.h, mpir.lib, mpfr.h and mpfr.lib. The PDB files contain debugging information, and are not necessary for compilation.
Also, I don't know how to create a makefile, but a simple batch file with the command above should suffice for something so simple.