Question about compiled programmatic use of external libraries

I know this can be a very stupid question, but I'm new to compiled languages ​​(my domain is mostly scripting languages ​​like PHP, Python or JavaScript).

I am learning C ++ for one project where this is the only language I can use.

I wrote a program in Ubuntu 10.10 and then compiled it. I can run the generated binary from cmd like this and it works:

sudo ./compiled-program

But, I used some external libraries in the program (OpenCV). Does this mean that all computers on which I will run the program must have OpenCV installed? Or does OpenCV come inside a compiled binary? Will it work on a PC without OpenCV installed?

+3
source share
7 answers

You should read a few things about libraries and, in particular, what distinguishes static and dynamic libraries. To quote the basic definitions so that you understand the gist:

A static library, also known as an archive, consists of a set of routines that are copied to the target application by the compiler, linker, or binder , creating object files and a stand-alone executable.

[...]

( DLL, Windows DSO ( ) Unix- ) .

+2

!

"" - , " " - , , , OpenCV ( , ) .

( -) , , , , .

, , OpenCV , , ".a" ".so".

+2

, OpenCV, , .

, , : http://en.wikipedia.org/wiki/Library_(computing)

:

ldd compiled-program

( ldd python /usr/bin):

birryree@lilun:/usr/bin$ ldd python
        linux-gate.so.1 =>  (0xb7ff7000)
        libpthread.so.0 => /lib/i686/cmov/libpthread.so.0 (0xb7fd5000)
        libdl.so.2 => /lib/i686/cmov/libdl.so.2 (0xb7fd1000)
        libutil.so.1 => /lib/i686/cmov/libutil.so.1 (0xb7fcd000)
        libssl.so.0.9.8 => /usr/lib/i686/cmov/libssl.so.0.9.8 (0xb7f82000)
        libcrypto.so.0.9.8 => /usr/lib/i686/cmov/libcrypto.so.0.9.8 (0xb7e2a000)
        libz.so.1 => /usr/lib/libz.so.1 (0xb7e16000)
        libm.so.6 => /lib/i686/cmov/libm.so.6 (0xb7df0000)
        libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7caa000)
        /lib/ld-linux.so.2 (0x80000000)

Python , libssl ( OpenSSL), GNU C (libc) .

, , , , , - autotools/GNU Build System , , .

+2

" " OpenCV, , . , .

+1

, (Dynamic) ( ). , ... .. .

+1

, . , .

+1

, . , , . , , .

+1

Source: https://habr.com/ru/post/1776322/


All Articles