Shared library mysteriously doesn't get linked to application
tl;dr version: Add -Wl,--no-as-needed
to the link command.
After a series of experimentation and conversations with the OP, I've figured out what's going on.
In the latest version of Ubuntu, ld
uses --as-needed
by default. What that does is to remove references to libraries that are not explicitly required.
The way Hoard works is as an LD_PRELOAD
library. i.e., you are not supposed to need to use functions in libhoard.so
directly. Of course, you could link in libhoard
directly if you wanted to...unless --as-needed
is used, of course.
After discovering this, the solution is simple. Just add -Wl,--no-as-needed
to the gcc
linking command.
Error while loading shared libraries: libcudart.so
Okay, finally I figured it out and solved the problem. In the end, your comments lead me to the solution. I simply forgot to specify the CUDA library explicitly, which I didn't know I have to do.
I changed
target_link_libraries( Server ${OpenCV_LIBS} ${Boost_LIBRARIES} Spinnaker )
to
target_link_libraries( Server ${OpenCV_LIBS} ${Boost_LIBRARIES} Spinnaker ${CUDA_LIBRARIES} )
It is now, as noted in the comments, by default linked statically.
how to block a signal before shared library creates a thread?
Doesn't seem to be possible -- shared library should block all signals in created threads if it really needs to create a thread so early.
Using shared libraries vs a single executable
I'd say that splitting code into shared libraries to improve without having any immediate goal in mind is a sign of a buzzwords-infested development environment. It is better to write code that can easily be split at some point.
But why would you need to wrap C++ classes into C-function interfaces, except for, maybe, for object creation?
Also, splitting into shared libraries here sounds like an interpreted language mindset. In compiled languages you try not to postpone till runtime what you can do at compile-time. Unnecessary dynamic linking is exactly the case.
ld: library not found for -lPods only when run in real device
Assigning the target in Podfile has resolved the problem.
target :TechMoviePlus do
pod "AFNetworking", "~> 2.0"
pod "LBGIFImage"
end
Statically linked libraries and JNI?
You are correct: the JVM can load dll
s (you normally have some startup code in the Java source code that contains native
functions to load them). It cannot load lib
s.
So you will need to create a dll
that statically links to the lib
s.
The normal way to do this is to run the program javah
which will generate the stubs for the dll
functions that you need to implement.
gcc linking with static libraries
sqrt (2.0);
Modern GCC is well capable to determine that you are trying to find square root of a constant and thus it is able to calculate that in compile time. Your object code does not contain an actual call to sqrt
.
If you use a variable which is input via scanf
at run then it won't link without libm
.
int main() {
double x;
scanf("%lf", &x);
printf("%lf\n", sqrt(x));
return 0;
}
Without libm
gcc 4.8.4 on Ubuntu 14.04 this results:
/tmp/ccVO2fRY.o: In function `main':
sqrt.c:(.text+0x2c): undefined reference to `sqrt'
collect2: error: ld returned 1 exit status
But if I put a constant instead of x
like your example then it links fine without libm
.
P.S: I don't know the exact version since when GCC is able to do this. Hopefully someone else can point to that.
Related Topics
Difference Between "Cpu/Mem-Loads/Pp" and "Cpu/Mem-Loads/"
How to Handle Sigsegv Signal in Userspace Using Rust
How to Check If a UId Exists in an Acl in Linux
Qemu Simple Backend Tracing Dosen'T Print Anything
How to Include Debug Information with Nasm
How to Limit CPU and Ram Resources for Mongodump
Linux: Triggering Shell Command on File Save
How Does Linux Handles The I/O Permission Bitmap in The Tss Structure
How to Set Umask Default for an User
Kernel Oops Page Fault Error Codes for Arm
Mod_Perl Can't See Files in /Tmp
Modemmanager: Mmcli Get Signal Strength
Why Do Es and Ds Zero Out Eventually on 64 Bit Kernel When Set to Tls Selectors
Setting Path to Shared Library Inside a Makefile for Compile
Detect If Something Is Modified in Directory, and If So, Backup - Otherwise Do Nothing
How to Launch a Background Process Through a Wrapper That'Ll Undo The Sigint Ignore
How to Include Cutil.H in Linux
Questions About Embedded Linux Device Driver by Linux Newbie