Cmake and linked shared objects

Hello, I would like to ask about cmake and it's lining of shared objects.
I compiled and installed 'https://github.com/jocover/jetson-ffmpeg' in my jetson TX2. It works OK. It add new library nvmpi. Now I am want to compile Zoneminder with use of a ffmpeg, but I get this error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
cd "/home/administrator/ZM/zoneminder_1.35.16~20201211203052.orig/dbuild/src" 
&& /usr/bin/cmake -E cmake_link_script CMakeFiles/zmc.dir/link.txt --verbose=1
/usr/bin/c++  -g -O2 -fdebug-prefix-map=/home/administrator/ZM/zoneminder_1.35.16~20201211203052.orig=. 
-fstack-protector-strong
 -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -std=c++11 -Wall -D__STDC_CONSTANT_MACROS -O2  -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,
--as-needed -rdynamic CMakeFiles/zmc.dir/zmc.cpp.o  -o zmc  -
L"/home/administrator/ZM/zoneminder_1.35.16~20201211203052.orig/src/libbcrypt" 
-Wl,-rpath,"/home/administrator/ZM/zoneminder_1.35.16~20201211203052.orig/src/libbcrypt:" 
libzm.a -lrt -lz -ljpeg -lssl -lcrypto -lpthread -lpcre -lgcrypt -lmysqlclient -lx264 
-lmp4v2 /usr/local/lib/libavformat.a /usr/local/lib/libavcodec.a /usr/local/lib/libavdevice.a 
/usr/local/lib/libavutil.a /usr/local/lib/libswscale.a /usr/local/lib/libswresample.a -ldl 
/usr/local/lib/libavutil.a(mathematics.o): In function `av_rescale_delta':
/home/administrator/ffmpeg/ffmpeg/libavutil/mathematics.c:168: multiple definition of `av_rescale_delta'
libzm.a(zm_ffmpeg.cpp.o):./dbuild/src/./src/zm_ffmpeg.cpp:199: first defined here
/usr/local/lib/libavcodec.a(nvmpi_enc.o): In function `nvmpi_encode_frame':
/home/administrator/ffmpeg/ffmpeg/libavcodec/nvmpi_enc.c:152: undefined reference to `nvmpi_encoder_put_frame'
/home/administrator/ffmpeg/ffmpeg/libavcodec/nvmpi_enc.c:159: undefined reference to `nvmpi_encoder_get_packet'
/usr/local/lib/libavcodec.a(nvmpi_enc.o): In function `nvmpi_encode_close':
/home/administrator/ffmpeg/ffmpeg/libavcodec/nvmpi_enc.c:180: undefined reference to `nvmpi_encoder_close'
/usr/local/lib/libavcodec.a(nvmpi_enc.o): In function `nvmpi_encode_init':
/home/administrator/ffmpeg/ffmpeg/libavcodec/nvmpi_enc.c:79: undefined reference to `nvmpi_create_encoder'
/home/administrator/ffmpeg/ffmpeg/libavcodec/nvmpi_enc.c:91: undefined reference to `nvmpi_encoder_put_frame'
/home/administrator/ffmpeg/ffmpeg/libavcodec/nvmpi_enc.c:93: undefined reference to `nvmpi_encoder_get_packet'
/home/administrator/ffmpeg/ffmpeg/libavcodec/nvmpi_enc.c:113: undefined reference to `nvmpi_encoder_close'
/home/administrator/ffmpeg/ffmpeg/libavcodec/nvmpi_enc.c:119: undefined reference to `nvmpi_create_encoder'
/home/administrator/ffmpeg/ffmpeg/libavcodec/nvmpi_enc.c:121: undefined reference to `nvmpi_create_encoder'
/usr/local/lib/libavcodec.a(nvmpi_dec.o): In function `nvmpi_close':
/home/administrator/ffmpeg/ffmpeg/libavcodec/nvmpi_dec.c:71: undefined reference to `nvmpi_decoder_close'
/usr/local/lib/libavcodec.a(nvmpi_dec.o): In function `nvmpi_decode':
/home/administrator/ffmpeg/ffmpeg/libavcodec/nvmpi_dec.c:94: undefined reference to `nvmpi_decoder_get_frame'
/home/administrator/ffmpeg/ffmpeg/libavcodec/nvmpi_dec.c:91: undefined reference to `nvmpi_decoder_put_packet'
/usr/local/lib/libavcodec.a(nvmpi_dec.o): In function `nvmpi_init_decoder':
/home/administrator/ffmpeg/ffmpeg/libavcodec/nvmpi_dec.c:54: undefined reference to `nvmpi_create_decoder'
collect2: error: ld returned 1 exit status
src/CMakeFiles/zmc.dir/build.make:114: recipe for target 'src/zmc' failed 


For error 'multiple definition of `av_rescale_delta' I just commented out definition inside 'zm_ffmpeg.cpp'

But for 'undefined reference's I cannot find a way to get rid of them.
Cpp for '/usr/local/lib/libavcodec.a' have in first line #include <nvmpi.h> which contain these definitions.

Do I have to specify somewhere in cmake location to nvmpi library (shouldn't 'libavcodec.a' know its position?)

Thank You in advance for any hint
Last edited on
> cd "/home/administrator
The first thing I would suggest you do is stop doing your software development in your admin account.
Are you busy surfing the web in a browser run from the admin account as well?

This is your linker command line (I think), it was horribly formatted.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/usr/bin/c++  -g -O2 
-fdebug-prefix-map=/home/administrator/ZM/zoneminder_1.35.16~20201211203052.orig=. 
-fstack-protector-strong
-Wformat 
-Werror=format-security 
-Wdate-time 
-D_FORTIFY_SOURCE=2 
-std=c++11 
-Wall 
-D__STDC_CONSTANT_MACROS 
-O2  
-Wl,-Bsymbolic-functions 
-Wl,-z,relro 
-Wl,-z,now 
-Wl,--as-needed 
-rdynamic 
CMakeFiles/zmc.dir/zmc.cpp.o  
-o zmc  
-L"/home/administrator/ZM/zoneminder_1.35.16~20201211203052.orig/src/libbcrypt" 
-Wl,-rpath,"/home/administrator/ZM/zoneminder_1.35.16~20201211203052.orig/src/libbcrypt:" 
libzm.a 
-lrt 
-lz 
-ljpeg 
-lssl 
-lcrypto 
-lpthread 
-lpcre 
-lgcrypt 
-lmysqlclient 
-lx264 
-lmp4v2 
/usr/local/lib/libavformat.a 
/usr/local/lib/libavcodec.a 
/usr/local/lib/libavdevice.a 
/usr/local/lib/libavutil.a 
/usr/local/lib/libswscale.a 
/usr/local/lib/libswresample.a 
-ldl 

All those absolute paths to libav... are wrong.
You're saying you want the whole lib, lock stock and barrel.

Change them all to be of the form
-lavformat
so the linker can do what it's supposed to, which is search the library for the symbols it need.


> But for 'undefined reference's I cannot find a way to get rid of them.
> Cpp for '/usr/local/lib/libavcodec.a' have in first line #include <nvmpi.h> which contain these definitions.
> Do I have to specify somewhere in cmake location to nvmpi library (shouldn't 'libavcodec.a' know its position?)
The header files just tell the compiler what to expect.
You also have to tell the linker (via -lfoo) the name of the library associated with that header file so it can actually reference the implementation you told the compiler (via the .h file) would exist.

> For error 'multiple definition of `av_rescale_delta' I just commented out definition inside 'zm_ffmpeg.cpp'
Yeah, you shouldn't need to do that either, if the libraries are properly specified.
Topic archived. No new replies allowed.