2

I'm writing a custom video player for Raspberry Pi that uses ffmpeg for decoding the video and OpenGL on top of GDB and DRM to render it.

To decode video on Raspberry Pi, ffmpeg has to be compiled with MMAL enabled as that's the recommended API for HW accelerated video decoding.

The problem:

Almost all libraries are located in standard path, except MMAL, which is located in /opt/vc/lib/libmmal.so.

Sure, the first thing that everybody thinks of is, just add -L/opt/vc/lib, but it's not that simple:

  • I'm also using /usr/lib/libEGL.so in my program, provided by Mesa.
  • There's also /opt/vc/lib/libEGL.so which I don't want to use because it's the legacy implementation that doesn't work for my case.

If I add -L/opt/vc/lib, it will prioritize that path and pick up the wrong library /opt/vc/lib/libEGL.so.

Is there a way to do something like -L/opt/vc/lib but only for one specific library, while for other libraries it keeps using the standard path? Or is there any other way to solve this problem?

I tried stuff like -l/opt/vc/lib/libmmal.so and that didn't work and I wasn't able find much help, since this is a very specific problem.

Bonus points to anyone, who also knows how to do the same thing in CMake.

Michal Artazov
  • 4,368
  • 8
  • 25
  • 38
  • Did you see this? https://stackoverflow.com/questions/2726993/how-to-specify-preference-of-library-path – Devolus Feb 23 '21 at 16:16
  • @Devolus that's not what I'm dealing with. I know how to deal with libraries in other locations. In that case, that person wants to specify a custom path to a library but once he does, there's no other library, that will suddenly start getting linked from that same new location. That's my issue. I can link one library from a custom location, but then more libraries start getting linked from that new location and I don't want that. – Michal Artazov Feb 23 '21 at 16:25
  • Cant you split the build process into two separate subprojects where the one gets the one path and the other the normal libraries? – Devolus Feb 23 '21 at 16:56
  • @Devolus I'm not exactly sure how I can do that. My project consists of a few .c files and they are linked into a single executable. The problem arises during the linking part, after the executable is compiled. How would you do it? – Michal Artazov Feb 23 '21 at 17:08
  • When using absolute path like `/opt/vc/lib/libmmal.so` don't prefix it with `-l`. – user58697 Feb 23 '21 at 19:17

1 Answers1

0
src
   Library
       CMakeLists.txt
       lib_main.cpp
   MainProject
       main.cpp
   CMakeLists.txt
CMakeLists.txt

src:CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(test)

add_subdirectory(MainProject)
add_subdirectory(Library)

src/Library:CMakeLists.txt

project(MyLibrary)

set(TARGET ${PROJECT_NAME})

set(SOURCES
    lib_main.cpp
)

# additional library paths
link_directories( /usr/local/lib64 )

add_library(${TARGET} SHARED ${SOURCES})

src/MainProject:CMakeLists.txt project(MainProject)

set(TARGET ${PROJECT_NAME})

set(SOURCES
    main.cpp
)

# Target to build
add_executable(${TARGET} ${SOURCES})

### Library linking
target_link_libraries(${TARGET}
    MyLibrary
)
Devolus
  • 21,661
  • 13
  • 66
  • 113
  • but this only applies in a situation when I'm the creator of both the library and the executable that links that library. But that's not my case. I'm linking multiple third-party shared libraries and one of them is located in a custom location. – Michal Artazov Feb 24 '21 at 15:30
  • You can not link an executable with two different libraries, exporting the same symbols. If you need that library, then you must put that into a seperate binary (i.E. sahred library, where it can use that functions) and link against it. If you link the object file in the executable, then I don't see how you could tell the linker that you want to use the symbols for that one instance only. – Devolus Feb 24 '21 at 15:33
  • I'm not trying to link 2 different libraries with the same symbols. Please, read my original question again. – Michal Artazov Feb 24 '21 at 20:47