Hey everyone, I'm relatively new to programming in C, and I've been struggling with using libraries that aren't built-in. I'm particularly interested in using GLFW for graphics development on Linux, but I find CMake extremely confusing. I've tried following several tutorials and digging through the documentation multiple times, but I still feel lost. I don't know how to get CMake to recognize the libraries on my system or where I should even place them. In Windows, the process seems straightforward with .lib and .dll files, but Linux approaches it differently, and I'm not sure how that works. It feels like importing libraries in Python is a breeze compared to this! Can anyone point me toward good resources or explain the correct process for managing libraries, both for Linux and for MSVC?
1 Answer
Instead of worrying about precompiled libraries, consider building GLFW from source directly within your project. You can add the following lines to your CMake file, and it should take care of everything for you:
```cmake
include(FetchContent)
FetchContent_Declare(glfw GIT_REPOSITORY https://github.com/glfw/glfw.git GIT_TAG master)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(glfw)
target_link_libraries(${PROJECT_NAME} PRIVATE glfw)
```
This way, CMake handles the library for you without needing to figure out complicated paths.

But why avoid precompiled libraries? I'd love to know the reasoning behind it. I appreciate the help, but I also want to understand the concepts better.