How to get CMake to actually find includes??

Completed

So I have my project and it has underneath it "External Libraries" with some include directories.

I've referenced a .h file from one of these directories, specifically libusb. It looks like the IDE has found it - everything is recognised, no design-time errors...

But when I build it, CMake says none of these things (libusb_device, libusb_context, libusb_init, etc, etc) exist.

Firstly, why would this be the case? Surely if the IDE can find it, it should be "telling" CMake where they are? Otherwise it's not an Integrated Development Environment...

Secondly, how do I fix this? I added include_directories to CMakeLists.txt and that doesn't seem to have done anything. I tried adding "find_library" with a "hint" that points directly at the libusb-1.0 folder. Nothing seems to change the build messages.

0
4 comments
Avatar
Permanently deleted user

This appears to be a link time error, fix it by adding target_link_libraries() after you've made your target.  https://cmake.org/cmake/help/v3.12/command/target_link_libraries.html 

 

3

Fantastic, that worked. Thank you so much.

 

To the person who down-voted without explanation... Sorry you feel that way. I'm a coder. I code. I want to spend my time coding, not finding workarounds for buggy tooling. I can code a C# app, build it, run it, and it just works right away. I can write some C Code, upload it to an ATMEGA AVR or similar, and it just works right away. Why should C++ be inaccessible? Why should anyone be shamed for asking for help?

0

Just in case: we have a quick CMake tutorial in our web help - https://www.jetbrains.com/help/clion/quick-cmake-tutorial.html, it might be useful.

0

Thanks Anna, I'll be sure to check it out.

0

Please sign in to leave a comment.