Unable to load dynamic library(DYLIB) in MacOS
I am trying to load a library(say ArithmeticOprn.dylib) dynamically and call the methods presented within that library. Please refer to the sample code snippet from below,
[DllImport("libdl.dylib")]
public static extern IntPtr dlopen(String fileName, int flags);
[DllImport("ArithmeticOprn.dylib")]
public static extern double Add(double a, double b);
static void Main(string args)
{
dlopen("path/to/ArithmeticOprn.dylib", 2);
double result = Add(1, 2);
}
While running the above sample in MacOS, I got the following exception:
Unable to load DLL "ArithmeticOprn.dylib": The specified module or one of its dependencies could not be found.
But, when I provide full path in the DllImport the method call works and I can get the expected results. For your reference, please refer below for the code snippet.
[DllImport("path/to/ArithmeticOprn.dylib")]
public static extern double Add(double a, double b);
Could you please let me know what I am missing ? Thanks in advance :)
c# macos dllimport dylib dlopen
|
show 2 more comments
I am trying to load a library(say ArithmeticOprn.dylib) dynamically and call the methods presented within that library. Please refer to the sample code snippet from below,
[DllImport("libdl.dylib")]
public static extern IntPtr dlopen(String fileName, int flags);
[DllImport("ArithmeticOprn.dylib")]
public static extern double Add(double a, double b);
static void Main(string args)
{
dlopen("path/to/ArithmeticOprn.dylib", 2);
double result = Add(1, 2);
}
While running the above sample in MacOS, I got the following exception:
Unable to load DLL "ArithmeticOprn.dylib": The specified module or one of its dependencies could not be found.
But, when I provide full path in the DllImport the method call works and I can get the expected results. For your reference, please refer below for the code snippet.
[DllImport("path/to/ArithmeticOprn.dylib")]
public static extern double Add(double a, double b);
Could you please let me know what I am missing ? Thanks in advance :)
c# macos dllimport dylib dlopen
1
Similar questions found stackoverflow.com/questions/12036457/… stackoverflow.com/questions/21577127/…
– Kumar
Nov 23 '18 at 12:03
1
@Kumar There's no answer found in it.
– Ramkumar
Nov 23 '18 at 12:04
Yes. That's why added +1
– Kumar
Nov 23 '18 at 12:04
2
@Kumar - yes he is right no answer is found.
– Suresh Ram
Nov 23 '18 at 12:05
1
What language is this? C#?
– Siguza
Nov 23 '18 at 14:17
|
show 2 more comments
I am trying to load a library(say ArithmeticOprn.dylib) dynamically and call the methods presented within that library. Please refer to the sample code snippet from below,
[DllImport("libdl.dylib")]
public static extern IntPtr dlopen(String fileName, int flags);
[DllImport("ArithmeticOprn.dylib")]
public static extern double Add(double a, double b);
static void Main(string args)
{
dlopen("path/to/ArithmeticOprn.dylib", 2);
double result = Add(1, 2);
}
While running the above sample in MacOS, I got the following exception:
Unable to load DLL "ArithmeticOprn.dylib": The specified module or one of its dependencies could not be found.
But, when I provide full path in the DllImport the method call works and I can get the expected results. For your reference, please refer below for the code snippet.
[DllImport("path/to/ArithmeticOprn.dylib")]
public static extern double Add(double a, double b);
Could you please let me know what I am missing ? Thanks in advance :)
c# macos dllimport dylib dlopen
I am trying to load a library(say ArithmeticOprn.dylib) dynamically and call the methods presented within that library. Please refer to the sample code snippet from below,
[DllImport("libdl.dylib")]
public static extern IntPtr dlopen(String fileName, int flags);
[DllImport("ArithmeticOprn.dylib")]
public static extern double Add(double a, double b);
static void Main(string args)
{
dlopen("path/to/ArithmeticOprn.dylib", 2);
double result = Add(1, 2);
}
While running the above sample in MacOS, I got the following exception:
Unable to load DLL "ArithmeticOprn.dylib": The specified module or one of its dependencies could not be found.
But, when I provide full path in the DllImport the method call works and I can get the expected results. For your reference, please refer below for the code snippet.
[DllImport("path/to/ArithmeticOprn.dylib")]
public static extern double Add(double a, double b);
Could you please let me know what I am missing ? Thanks in advance :)
c# macos dllimport dylib dlopen
c# macos dllimport dylib dlopen
edited Nov 26 '18 at 15:00
Siguza
12.2k63351
12.2k63351
asked Nov 23 '18 at 11:54
RamkumarRamkumar
1961217
1961217
1
Similar questions found stackoverflow.com/questions/12036457/… stackoverflow.com/questions/21577127/…
– Kumar
Nov 23 '18 at 12:03
1
@Kumar There's no answer found in it.
– Ramkumar
Nov 23 '18 at 12:04
Yes. That's why added +1
– Kumar
Nov 23 '18 at 12:04
2
@Kumar - yes he is right no answer is found.
– Suresh Ram
Nov 23 '18 at 12:05
1
What language is this? C#?
– Siguza
Nov 23 '18 at 14:17
|
show 2 more comments
1
Similar questions found stackoverflow.com/questions/12036457/… stackoverflow.com/questions/21577127/…
– Kumar
Nov 23 '18 at 12:03
1
@Kumar There's no answer found in it.
– Ramkumar
Nov 23 '18 at 12:04
Yes. That's why added +1
– Kumar
Nov 23 '18 at 12:04
2
@Kumar - yes he is right no answer is found.
– Suresh Ram
Nov 23 '18 at 12:05
1
What language is this? C#?
– Siguza
Nov 23 '18 at 14:17
1
1
Similar questions found stackoverflow.com/questions/12036457/… stackoverflow.com/questions/21577127/…
– Kumar
Nov 23 '18 at 12:03
Similar questions found stackoverflow.com/questions/12036457/… stackoverflow.com/questions/21577127/…
– Kumar
Nov 23 '18 at 12:03
1
1
@Kumar There's no answer found in it.
– Ramkumar
Nov 23 '18 at 12:04
@Kumar There's no answer found in it.
– Ramkumar
Nov 23 '18 at 12:04
Yes. That's why added +1
– Kumar
Nov 23 '18 at 12:04
Yes. That's why added +1
– Kumar
Nov 23 '18 at 12:04
2
2
@Kumar - yes he is right no answer is found.
– Suresh Ram
Nov 23 '18 at 12:05
@Kumar - yes he is right no answer is found.
– Suresh Ram
Nov 23 '18 at 12:05
1
1
What language is this? C#?
– Siguza
Nov 23 '18 at 14:17
What language is this? C#?
– Siguza
Nov 23 '18 at 14:17
|
show 2 more comments
1 Answer
1
active
oldest
votes
You're trying to short-cut the DllImport
behaviour through an explicit dlopen
- i.e. using the dlopen
to specify the path that's supposed to be used by the DllImport
. The problem is that the DllImport
link-up is done internally to the C#
run-time before the dlopen
gets called.
the dlopen
never gets a look in.
In order to use DllImport
without a path, you need to rely on the default search behaviour, which is locations as specified by the environment variables $LD_LIBRARY_PATH
, $DYLD_LIBRARY_PATH
, current working directory, $DYLD_FALLBACK_LIBRARY_PATH
.
So, for example:
env DYLD_LIBRARY_PATH=path/to/ mono test.exe
which runs the mono interpreter with the path pre-loaded with path/to
, allowing it to find the dylib
in that location.
Other solutions include moving the library into the directory with the executable, making a symlink to the library in the current working directory.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446244%2funable-to-load-dynamic-librarydylib-in-macos%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You're trying to short-cut the DllImport
behaviour through an explicit dlopen
- i.e. using the dlopen
to specify the path that's supposed to be used by the DllImport
. The problem is that the DllImport
link-up is done internally to the C#
run-time before the dlopen
gets called.
the dlopen
never gets a look in.
In order to use DllImport
without a path, you need to rely on the default search behaviour, which is locations as specified by the environment variables $LD_LIBRARY_PATH
, $DYLD_LIBRARY_PATH
, current working directory, $DYLD_FALLBACK_LIBRARY_PATH
.
So, for example:
env DYLD_LIBRARY_PATH=path/to/ mono test.exe
which runs the mono interpreter with the path pre-loaded with path/to
, allowing it to find the dylib
in that location.
Other solutions include moving the library into the directory with the executable, making a symlink to the library in the current working directory.
add a comment |
You're trying to short-cut the DllImport
behaviour through an explicit dlopen
- i.e. using the dlopen
to specify the path that's supposed to be used by the DllImport
. The problem is that the DllImport
link-up is done internally to the C#
run-time before the dlopen
gets called.
the dlopen
never gets a look in.
In order to use DllImport
without a path, you need to rely on the default search behaviour, which is locations as specified by the environment variables $LD_LIBRARY_PATH
, $DYLD_LIBRARY_PATH
, current working directory, $DYLD_FALLBACK_LIBRARY_PATH
.
So, for example:
env DYLD_LIBRARY_PATH=path/to/ mono test.exe
which runs the mono interpreter with the path pre-loaded with path/to
, allowing it to find the dylib
in that location.
Other solutions include moving the library into the directory with the executable, making a symlink to the library in the current working directory.
add a comment |
You're trying to short-cut the DllImport
behaviour through an explicit dlopen
- i.e. using the dlopen
to specify the path that's supposed to be used by the DllImport
. The problem is that the DllImport
link-up is done internally to the C#
run-time before the dlopen
gets called.
the dlopen
never gets a look in.
In order to use DllImport
without a path, you need to rely on the default search behaviour, which is locations as specified by the environment variables $LD_LIBRARY_PATH
, $DYLD_LIBRARY_PATH
, current working directory, $DYLD_FALLBACK_LIBRARY_PATH
.
So, for example:
env DYLD_LIBRARY_PATH=path/to/ mono test.exe
which runs the mono interpreter with the path pre-loaded with path/to
, allowing it to find the dylib
in that location.
Other solutions include moving the library into the directory with the executable, making a symlink to the library in the current working directory.
You're trying to short-cut the DllImport
behaviour through an explicit dlopen
- i.e. using the dlopen
to specify the path that's supposed to be used by the DllImport
. The problem is that the DllImport
link-up is done internally to the C#
run-time before the dlopen
gets called.
the dlopen
never gets a look in.
In order to use DllImport
without a path, you need to rely on the default search behaviour, which is locations as specified by the environment variables $LD_LIBRARY_PATH
, $DYLD_LIBRARY_PATH
, current working directory, $DYLD_FALLBACK_LIBRARY_PATH
.
So, for example:
env DYLD_LIBRARY_PATH=path/to/ mono test.exe
which runs the mono interpreter with the path pre-loaded with path/to
, allowing it to find the dylib
in that location.
Other solutions include moving the library into the directory with the executable, making a symlink to the library in the current working directory.
answered Nov 26 '18 at 16:54
PeteshPetesh
68.8k37296
68.8k37296
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446244%2funable-to-load-dynamic-librarydylib-in-macos%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Similar questions found stackoverflow.com/questions/12036457/… stackoverflow.com/questions/21577127/…
– Kumar
Nov 23 '18 at 12:03
1
@Kumar There's no answer found in it.
– Ramkumar
Nov 23 '18 at 12:04
Yes. That's why added +1
– Kumar
Nov 23 '18 at 12:04
2
@Kumar - yes he is right no answer is found.
– Suresh Ram
Nov 23 '18 at 12:05
1
What language is this? C#?
– Siguza
Nov 23 '18 at 14:17