0

Is there any way i can set a priority at linking some libs/classes in cmake?

I have a library BFciLib that i use in my class, and have added it in cmake like this

  target_link_libraries(Main PRIVATE BFciLib GL ${GTKMM_LIBRARIES})

I had to overwrite some of the method of that lib so that i am able to develop on my pc (without having to connect my device for which the mentioned lib is used etc). So i have C wrapped those methods, and basically now i have 2 definitions of the same method.

I need to link my newly created methods to be used in MyClass, instead of the original ones(the ones of the lib) without modifying the class. But still use the library since are more other methods used. So i believe that is to be done in the cmake file.

For that i have added another executable, but i fail to see what more should i do:

 #new exe

  add_executable(
    NewMain
    src/main.cpp
    src/MyClass.hpp
    src/MyClass.cpp
    src/ClassWithCWrappers.hpp
    src/ClassWithCWrappers.cpp
    )
    target_link_libraries(NewMain PRIVATE BFciLib GL ${GTKMM_LIBRARIES})

This still returns "duplicate definition" error.

How am i supposed to do?

user3253067
  • 113
  • 2
  • 11
  • "Is there any way i can set a priority at linking some libs/classes in cmake?" - The order in which you specify libraries in a `target_link_libraries` call becomes the order of libraries passed to the linker. The rest of your problem - overriding the function - is **compiler specific**, and CMake provides no helper for that task. About possible solutions see e.g. [that question](https://stackoverflow.com/questions/617554/override-a-function-call-in-c). – Tsyvarev Dec 06 '22 at 12:53

1 Answers1

0

Don't try to override global functions. Create an interface abstraction that can be implemented with either your device library or your PC alternative. Then have separate device and PC builds where you link in only one implementation each.

John
  • 7,301
  • 2
  • 16
  • 23