find_library results in linker error

Hi,

as a first step to use my external project I tried to do it manually like this:

find_library(LIB_LC  linuxcnc REQUIRED PATHS ${LinuxCNC_DIR}/lib )

cmake-gui shows that the library was found (the expected absolute filename).
So I added that variable to target_link_libraries, but it results in a
linker error:

make[2]: *** No rule exists to create the target ".../linuxcnc", 
  required by "myTarget".

Well, the real name of that library is “liblinuxcnc.a” - which cmake-gui shows
as content of LIB_LC. Don’t know, why the linker tries to link the wrong name.

What am I missing?

Hello !
I think I’m facing the same issue : have you checked the command line generated by CMake ?
If you run it manually, does it works ?
If you change …/linuxcnc by -L… -llinuxcnc, does it works ?

Thank you !
Olivier.

Hi Olivier,

thank you for your attention!

I’m new to cmake, so naturally I’m doing stupid things. But I’m working on
that item.

I have several shared libs and whatever I tried, I got the same error. It took
me a while, then I knew that the errors where not related to the error
messages.

I removed anything that was related to that name form that subproject, deleted
the cache but the error message stayed the same.
So I thought, may be, some other subprojects create cache definitions, that
break the plugin I was working on.

So I removed every definition related to that external project from every
subproject and started writing new rules for each of them.
Now the subprojects link successfully using the variable name from find_library
statement.

So stumbling to my next bug.

How did you do this? Can you show your code?

Hi,

So I added that variable to target_link_libraries, but it results in a
linker error:

How did you do this? Can you show your code?

You find my project at github

I had written the right code to add the library to plugins target libs. Only
because I mistakenly duplicated the library search in every cmake-file, I got
an error message that led me astray.

There’s too much of cmake I don’t understand.

Meanwhile I reduced duplicate code, so that the find_ statements are in
toplevel CMakeLists.txt only.

find library works like this:

set(LinuxCNC_DIR      "/usr/local/src/linuxcnc-deb11" CACHE PATH "LinuxCNC")

find_library(LC_LibLC    linuxcnc REQUIRED PATHS ${LinuxCNC_DIR}/lib )

usage in plugin is like this:

target_link_libraries(myPlugin
                      PRIVATE ${LC_LibLC}
                      )