ld cannot find shared library
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
Note: I visited many topics with questions similar to this one, although solutions chosen as accepted were all things I've already tried, so please, consider this before marking as duplicate.
Also, I'm new to Linux in general, so feel free to correct me if I say something fundamentally incorrect.
The problem:
I'm trying to create and use a c++ shared library and while the "create" part seems to be done, while trying to link against it, ld cannot see it.
Here's what I've already managed to do:
- Compiled all .cpp files with -fPIC explicitly stated
Created the library with
g++ -shared -fPIC -Wl,-soname,libcustom_program_options.so.1 -o
libcustom_program_options.so.1.0.1 *.o
Ran ldconfig to update the loader cache like this:
sudo ldconfig -n /usr/local/lib
And when I try to link the library against my test program:
g++ main.cpp -o main -L /usr/local/lib -l libcustom_program_options
Here's what happens:
/usr/bin/ld: cannot find -llibcustom_program_options
collect2: error: ld returned 1 exit status
Note: I wasn't sure if ld was looking for the library's full-name or soname or maybe the "name between lib- and .so.{version}", so I tried each one of those. Didn't help either.
shared-library g++ ld
add a comment |
Note: I visited many topics with questions similar to this one, although solutions chosen as accepted were all things I've already tried, so please, consider this before marking as duplicate.
Also, I'm new to Linux in general, so feel free to correct me if I say something fundamentally incorrect.
The problem:
I'm trying to create and use a c++ shared library and while the "create" part seems to be done, while trying to link against it, ld cannot see it.
Here's what I've already managed to do:
- Compiled all .cpp files with -fPIC explicitly stated
Created the library with
g++ -shared -fPIC -Wl,-soname,libcustom_program_options.so.1 -o
libcustom_program_options.so.1.0.1 *.o
Ran ldconfig to update the loader cache like this:
sudo ldconfig -n /usr/local/lib
And when I try to link the library against my test program:
g++ main.cpp -o main -L /usr/local/lib -l libcustom_program_options
Here's what happens:
/usr/bin/ld: cannot find -llibcustom_program_options
collect2: error: ld returned 1 exit status
Note: I wasn't sure if ld was looking for the library's full-name or soname or maybe the "name between lib- and .so.{version}", so I tried each one of those. Didn't help either.
shared-library g++ ld
Did you try-lcustom_program_options
? thel
is usually expanded tolib
(so for example-lm
linkslibm.so
and so on)
– steeldriver
Mar 23 at 20:43
Yes, I did. By saying "name between lib- and .so.{version}" I meant exactly that: -lcustom_program_options. I think I tried all the possible combinations of syntaxes, to be honest.
– TuRtoise
Mar 25 at 10:45
add a comment |
Note: I visited many topics with questions similar to this one, although solutions chosen as accepted were all things I've already tried, so please, consider this before marking as duplicate.
Also, I'm new to Linux in general, so feel free to correct me if I say something fundamentally incorrect.
The problem:
I'm trying to create and use a c++ shared library and while the "create" part seems to be done, while trying to link against it, ld cannot see it.
Here's what I've already managed to do:
- Compiled all .cpp files with -fPIC explicitly stated
Created the library with
g++ -shared -fPIC -Wl,-soname,libcustom_program_options.so.1 -o
libcustom_program_options.so.1.0.1 *.o
Ran ldconfig to update the loader cache like this:
sudo ldconfig -n /usr/local/lib
And when I try to link the library against my test program:
g++ main.cpp -o main -L /usr/local/lib -l libcustom_program_options
Here's what happens:
/usr/bin/ld: cannot find -llibcustom_program_options
collect2: error: ld returned 1 exit status
Note: I wasn't sure if ld was looking for the library's full-name or soname or maybe the "name between lib- and .so.{version}", so I tried each one of those. Didn't help either.
shared-library g++ ld
Note: I visited many topics with questions similar to this one, although solutions chosen as accepted were all things I've already tried, so please, consider this before marking as duplicate.
Also, I'm new to Linux in general, so feel free to correct me if I say something fundamentally incorrect.
The problem:
I'm trying to create and use a c++ shared library and while the "create" part seems to be done, while trying to link against it, ld cannot see it.
Here's what I've already managed to do:
- Compiled all .cpp files with -fPIC explicitly stated
Created the library with
g++ -shared -fPIC -Wl,-soname,libcustom_program_options.so.1 -o
libcustom_program_options.so.1.0.1 *.o
Ran ldconfig to update the loader cache like this:
sudo ldconfig -n /usr/local/lib
And when I try to link the library against my test program:
g++ main.cpp -o main -L /usr/local/lib -l libcustom_program_options
Here's what happens:
/usr/bin/ld: cannot find -llibcustom_program_options
collect2: error: ld returned 1 exit status
Note: I wasn't sure if ld was looking for the library's full-name or soname or maybe the "name between lib- and .so.{version}", so I tried each one of those. Didn't help either.
shared-library g++ ld
shared-library g++ ld
asked Mar 23 at 18:40
TuRtoiseTuRtoise
11
11
Did you try-lcustom_program_options
? thel
is usually expanded tolib
(so for example-lm
linkslibm.so
and so on)
– steeldriver
Mar 23 at 20:43
Yes, I did. By saying "name between lib- and .so.{version}" I meant exactly that: -lcustom_program_options. I think I tried all the possible combinations of syntaxes, to be honest.
– TuRtoise
Mar 25 at 10:45
add a comment |
Did you try-lcustom_program_options
? thel
is usually expanded tolib
(so for example-lm
linkslibm.so
and so on)
– steeldriver
Mar 23 at 20:43
Yes, I did. By saying "name between lib- and .so.{version}" I meant exactly that: -lcustom_program_options. I think I tried all the possible combinations of syntaxes, to be honest.
– TuRtoise
Mar 25 at 10:45
Did you try
-lcustom_program_options
? the l
is usually expanded to lib
(so for example -lm
links libm.so
and so on)– steeldriver
Mar 23 at 20:43
Did you try
-lcustom_program_options
? the l
is usually expanded to lib
(so for example -lm
links libm.so
and so on)– steeldriver
Mar 23 at 20:43
Yes, I did. By saying "name between lib- and .so.{version}" I meant exactly that: -lcustom_program_options. I think I tried all the possible combinations of syntaxes, to be honest.
– TuRtoise
Mar 25 at 10:45
Yes, I did. By saying "name between lib- and .so.{version}" I meant exactly that: -lcustom_program_options. I think I tried all the possible combinations of syntaxes, to be honest.
– TuRtoise
Mar 25 at 10:45
add a comment |
1 Answer
1
active
oldest
votes
Ok, I finally managed to solve it.
Once I checked what file the linker is actually expecting to find, I knew what to do next.
I did it by calling:
ld -L/usr/local/lib -lcustom_program_options --verbose
Where /usr/local/lib is the directory I put the library in, and custom_program_options is the name of the library stripped of the lib- prefix and all prefixes (i.e. extension and version).
As it printed a list of all considered directories along with the exact expected file name, I knew that it was looking for libcustom_program_options.so, whilst calling ldconfig (mentioned in the OP) set a link only between libcustom_program_options.so.1 and libcustom_program_options.so.1.0.1 (note the version number).
The file ld was trying to find indeed never existed.
The solution was to create the link manually:
sudo ln -s /usr/local/lib/libcustom_program_options.so.1 /usr/local/lib/libcustom_program_options.so
So this pretty much solved it. The culprit was me not knowing what was the exact filename sought by the linker.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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%2faskubuntu.com%2fquestions%2f1128112%2fld-cannot-find-shared-library%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
Ok, I finally managed to solve it.
Once I checked what file the linker is actually expecting to find, I knew what to do next.
I did it by calling:
ld -L/usr/local/lib -lcustom_program_options --verbose
Where /usr/local/lib is the directory I put the library in, and custom_program_options is the name of the library stripped of the lib- prefix and all prefixes (i.e. extension and version).
As it printed a list of all considered directories along with the exact expected file name, I knew that it was looking for libcustom_program_options.so, whilst calling ldconfig (mentioned in the OP) set a link only between libcustom_program_options.so.1 and libcustom_program_options.so.1.0.1 (note the version number).
The file ld was trying to find indeed never existed.
The solution was to create the link manually:
sudo ln -s /usr/local/lib/libcustom_program_options.so.1 /usr/local/lib/libcustom_program_options.so
So this pretty much solved it. The culprit was me not knowing what was the exact filename sought by the linker.
add a comment |
Ok, I finally managed to solve it.
Once I checked what file the linker is actually expecting to find, I knew what to do next.
I did it by calling:
ld -L/usr/local/lib -lcustom_program_options --verbose
Where /usr/local/lib is the directory I put the library in, and custom_program_options is the name of the library stripped of the lib- prefix and all prefixes (i.e. extension and version).
As it printed a list of all considered directories along with the exact expected file name, I knew that it was looking for libcustom_program_options.so, whilst calling ldconfig (mentioned in the OP) set a link only between libcustom_program_options.so.1 and libcustom_program_options.so.1.0.1 (note the version number).
The file ld was trying to find indeed never existed.
The solution was to create the link manually:
sudo ln -s /usr/local/lib/libcustom_program_options.so.1 /usr/local/lib/libcustom_program_options.so
So this pretty much solved it. The culprit was me not knowing what was the exact filename sought by the linker.
add a comment |
Ok, I finally managed to solve it.
Once I checked what file the linker is actually expecting to find, I knew what to do next.
I did it by calling:
ld -L/usr/local/lib -lcustom_program_options --verbose
Where /usr/local/lib is the directory I put the library in, and custom_program_options is the name of the library stripped of the lib- prefix and all prefixes (i.e. extension and version).
As it printed a list of all considered directories along with the exact expected file name, I knew that it was looking for libcustom_program_options.so, whilst calling ldconfig (mentioned in the OP) set a link only between libcustom_program_options.so.1 and libcustom_program_options.so.1.0.1 (note the version number).
The file ld was trying to find indeed never existed.
The solution was to create the link manually:
sudo ln -s /usr/local/lib/libcustom_program_options.so.1 /usr/local/lib/libcustom_program_options.so
So this pretty much solved it. The culprit was me not knowing what was the exact filename sought by the linker.
Ok, I finally managed to solve it.
Once I checked what file the linker is actually expecting to find, I knew what to do next.
I did it by calling:
ld -L/usr/local/lib -lcustom_program_options --verbose
Where /usr/local/lib is the directory I put the library in, and custom_program_options is the name of the library stripped of the lib- prefix and all prefixes (i.e. extension and version).
As it printed a list of all considered directories along with the exact expected file name, I knew that it was looking for libcustom_program_options.so, whilst calling ldconfig (mentioned in the OP) set a link only between libcustom_program_options.so.1 and libcustom_program_options.so.1.0.1 (note the version number).
The file ld was trying to find indeed never existed.
The solution was to create the link manually:
sudo ln -s /usr/local/lib/libcustom_program_options.so.1 /usr/local/lib/libcustom_program_options.so
So this pretty much solved it. The culprit was me not knowing what was the exact filename sought by the linker.
answered Mar 25 at 13:11
TuRtoiseTuRtoise
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f1128112%2fld-cannot-find-shared-library%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
Did you try
-lcustom_program_options
? thel
is usually expanded tolib
(so for example-lm
linkslibm.so
and so on)– steeldriver
Mar 23 at 20:43
Yes, I did. By saying "name between lib- and .so.{version}" I meant exactly that: -lcustom_program_options. I think I tried all the possible combinations of syntaxes, to be honest.
– TuRtoise
Mar 25 at 10:45