Load 64-Bit .dll Library from Sub-Folder
4 次查看(过去 30 天)
显示 更早的评论
I have a 64-bit shared library that loads fine when the *.h, *.lib, and *.dll's are in the current folder along with the main application script. When I try to move the library files to a sub-directory the loadlibrary function fails linking to the library. I've tried both "addpath" to the subdirectory and adding the "includepath" input argument to the loadlibrary call. Is there another way to make the linker in the compiler aware of additional file paths? Error message is below:
Error using loadlibrary
Building BTICARD_thunk_pcwin64 failed. Compiler output is:
cl -I"C:\matlab\R2017a\extern\include" /W3 /nologo -I"C:\matlab\R2017a\extern\include"
-I"C:\matlab\R2017a\simulink\include" /DTARGET_API_VERSION=700 /D_CRT_SECURE_NO_DEPRECATE
/D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0
-I"\\subdirectory\Matlab\Tools\64bit"
-I"\\subdirectory\Matlab\Tools\64bit\USB429" "BTICARD_thunk_pcwin64.c" -LD
-Fe"BTICARD_thunk_pcwin64.dll"
BTICARD_thunk_pcwin64.c
LINK : fatal error LNK1104: cannot open file 'bticard64.lib'
0 个评论
回答(2 个)
Jatin Waghela
2017-10-2
One possible reason for this error could be that the function is trying to access the temp directory on your machine but the path has spaces which is why it is not read correctly. For example, if the path to your temp directory is similar to the one below, it will throw the above error:
“C:\Users\userName\DOCUMENTS\Local Settings\temp”
This path will incorrectly be read as
“C:\Users\userName\DOCUMENTS\Local”
And hence would fail to read a file that is actually stored in the temp directory.
To fix this please change your environment variable (TEMP/TMP) to reflect a path that does not have spaces like the one below (only an example):
“C:\Users\userName\DOCUMENTS\LocalSettings\temp”
Please follow the instructions to change the environment variable:
a) From inside MATLAB you can use the following commands:
newPath = 'new\path'; setenv('TEMP', newPath); setenv('TMP', newPath);
b) From Windows follow the instructions below:
1) Right-click My Computer, and then click Properties. 2) Click the Advanced tab. 3) Click Environment variables.
Click on the following options, for either a user or a system variable: a) Click New to add a new variable name and value. b) Click an existing variable, and then click Edit to change its name or value. c) Click an existing variable, and then click Delete to remove it.
Please note that by changing the environment variable, you are not only changing it for MATLAB but for all applications that refer to the variable.
Mike Arms
2023-2-25
编辑:Mike Arms
2023-2-25
I ran into this same issue in R2019b with a 64-bit library. The workaround I used was to wrap the library within a C# .NET Framework DLL, then add the wrapped DLL with NET.addAssembly. I was then able to make calls to all the original shared library methods. Fortunately, the C# API code was already available for the library, so I wasn't bogged down with writing all that.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 C Shared Library Integration 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!