Multiple development enviroments with GLFW

Essentially, I switch between linux and windows a lot. But I want to learn opengl using one github repo. In the compiling section it says “CMake only generates project files or makefiles. It does not compile the actual GLFW library. To compile GLFW, first generate these files for your chosen development environment and then use them to compile the actual GLFW library.” which I get but I don’t know how to allow this to not create them for my one development environment. Do I compile it for each environment separately and put it in a lib/ directory then include that in .gitignore? will that work? Is that they best way to go about this? Thanks for help! I am new to C++ and OpenGL.

If it helps my directory structure is as follows:


The documentation is right in a sense that CMake doesn’t compile the libraries. It prepares the project files for your toolchain on your platform (like VS on windows or clang or gcc on linux or mac). CMake makes this complete platform agnostic.

EDIT: I see you use make. I suggest you switch to CMake. It will generate the make files automatically if your toolchain requires make files.

I use GLFW in a multi-platform environment as well along with CMake.

I use the following procedrue:

  • clone GLFW git repo as a submodule (for this example, I assume you clone it into the ./glfw folder).
  • in your root CMakeFiles.txt, you add:
    add_subdirectory( glfw )
  • in your CMakeFiles.txt where your add_executable statement resides, you simply do:
    target_link_libraries( <proj_name> glfw )

And you’re done!
Now each time you build, GLFW is built along with your project as a dependency.

Let me know if you require more input.

1 Like

Hey thanks for the reply! I will definitely do this! I just wish there was a easier way!