Stepan Yakovenko
Stepan Yakovenko

Reputation: 9206

Can not find object file with cmake link_directories

I want to add several .o files to the link process. If I do it like this:

TARGET_LINK_LIBRARIES(FFMPEGTest stdc++fs -pthread /home/stiv2/jsoft/nv-ffmpeg/ffmpeg/libswresample/audioconvert.o ...some more stuff... )

then it finds the file. All of these files are in the same directory, so I want to add them semultaneously:

link_directories(/home/stiv2/jsoft/nv-ffmpeg/ffmpeg/libswresample/)
TARGET_LINK_LIBRARIES(FFMPEGTest stdc++fs -pthread audioconvert.o ...some more stuff... )

but this doesn't work:

/usr/bin/ld: cannot find -laudioconvert.o

how do I fix this?

Upvotes: 1

Views: 871

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 65928

Documentation for target_link_libraries doesn't allow a relative path (audioconvert.o) to be a parameter to that command. It should be either absolute path (/home/stiv2/jsoft/nv-ffmpeg/ffmpeg/libswresample/audioconvert.o) or a plain library name (like z for libz.a library).

Because the object file audioconvert.o is not a library, it cannot be specified with a plain library name. You have no other choice than specify an absolute path for the object files.

For specify several object files in some directory you may use foreach loop:

foreach(obj audioconvert.o foo.o bar.o)
  target_link_libraries(FFMPEGTest /home/stiv2/jsoft/nv-ffmpeg/ffmpeg/libswresample/${obj})
endforeach()

Actually, every parameter <param> to target_link_libraries, which doesn't look like an absolute path (and doesn't corresponds to a library target), is transformed into -l<param> option for the linker.

The linker interprets this parameter as a plain library name, and searches for a file named lib<param>.a or lib<param>.so in the link directories.

So, with parameter -laudioconvert.o the linker searches a file with a name libaudioconvert.o.a - obviously, this is not what do you want.

Upvotes: 2

Related Questions