Victor Akhlynin
Victor Akhlynin

Reputation: 51

function is in one of object files but linker doesn't link them

friends, I have a question about linking. I have a problem with linking the project. I have tree of files:

ffmpeg4.1_custom
    fftools 
         ffmpeg.o  
    libavfilter
         libavfilter.so.

make has only one command to finish - this:

$ make -n
printf "LD\t%s\n" ffmpeg_g; gcc -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L/usr/local/lib  -Wl,--as-needed -Wl,-z,noexecstack -Wl,--warn-common -Wl,-rpath-link=libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil:libavresample   -o ffmpeg_g fftools/ffmpeg_opt.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o fftools/cmdutils.o fftools/ffmpeg.o  -lavdevice -lavfilter -lavformat -lavcodec -lavresample -lpostproc -lswresample -lswscale -lavutil  -lm -lxcb -lxcb-shape -lxcb-xfixes -lasound -lSDL2 -lsndio -lXv -lX11 -lXext -pthread -lm -lva -lm -lz -lssl -lcrypto -lvpx -lm -lvpx -lm -lvpx -lm -lvpx -lm -pthread -lm -llzma -lz -lfdk-aac -lopenjp2 -lx264 -lva -lm -lm -lm -lm -pthread -lva-drm -lva -lva-x11 -lva -lm -lva -lXv -lX11 -lXext -ldl  
printf "STRIP\t%s\n" ffmpeg; strip -o ffmpeg ffmpeg_g

I check my function in ffmpeg.o:

$ nm fftools/ffmpeg.o | grep my_func
                 U my_func

I check the same in libavfilter.so:

$ nm libavfilter/libavfilter.so | grep my_func
00000000000b2f8e t my_func

I run full command that links these 2 files:

$ gcc -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L/usr/local/lib  -Wl,--as-needed -Wl,-z,noexecstack -Wl,--warn-common -Wl,-rpath-link=libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil:libavresample   -o ffmpeg_g fftools/ffmpeg_opt.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o fftools/cmdutils.o fftools/ffmpeg.o  -lavdevice -lavfilter -lavformat -lavcodec -lavresample -lpostproc -lswresample -lswscale -lavutil  -lm -lxcb -lxcb-shape -lxcb-xfixes -lasound -lSDL2 -lsndio -lXv -lX11 -lXext -pthread -lm -lva -lm -lz -lssl -lcrypto -lvpx -lm -lvpx -lm -lvpx -lm -lvpx -lm -pthread -lm -llzma -lz -lfdk-aac -lopenjp2 -lx264 -lva -lm -lm -lm -lm -pthread -lva-drm -lva -lva-x11 -lva -lm -lva -lXv -lX11 -lXext -ldl
fftools/ffmpeg.o: In function `configure_filtergraph':
ffmpeg.c:(.text+0x6892): undefined reference to `my_func'
collect2: error: ld returned 1 exit status

If it plays any role, my function's prototype is in avfilter.h, code is in avfilter.c and it is used in ffmpeg.c What am I doing wrong?

Linux Mint 19 gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)

Upvotes: 0

Views: 124

Answers (1)

dash-o
dash-o

Reputation: 14442

The 'nm' output indicate my_func is "local" to libavfilter.so - it is marked with 't'. You can only refer to "global" functions - those will be marked with 'T'

From nm man page:

The symbol type. At least the following types are used; others are, as well, depending on the object file format. If lowercase, the symbol is usually local; if uppercase, the symbol is global (external). There are however a few lowercase symbols that are shown for special global symbols ("u", "v" and "w").

Access to local symbols is limited to the same module.

Upvotes: 2

Related Questions