Moros1138/pge-template-project

Linker fails to find GLUT

symbolix opened this issue · 2 comments

When running make, I get the following error:

ld: library not found for -lglut
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Glut is installed with brew and the actual cmake . command does not return an error.

So, I have solved the issue in the following way, in case others experience similar issues, here is the solution.

First of all, my problem was stemming from the fact that I had a pretty crowded dev environment, so CMake was picking up crap while resolving libs and includes.

  1. The solution to GLUT:
    Ended up using my native OSX GLUT, the CMake was naturally picking up a GLUT I have installed through brew (Freeglut).

Changing the GLUT section of the template with the following and enforcing the system-wide GLUT solved that problem.
target_link_libraries(${OutputExecutable} "-framework GLUT")

  1. The solution to my PNG problem:
    And 'Yes' it is not in the initial issue, but that problem eventually emerged. CMake was picking up some garbage old PNG lib from some of the OSX folders, and was picking up the headers from somewhere else. This was resulting in the following error:
libpng warning: Application built with libpng-1.4.12 but running with 1.6.39
AssetManager: attempted to load sprite <assets/gfx/space.png>, and something went wrong, is it a valid PNG file?

I ended up implementing a solution that probably worked for my case only, I'm assuming you are going to have a cleaner dev environment and you will not be running into this issue, but if you do, you need to enforce CMake to pickup the fresh PNG resources installed through brew.

I already had the pkg-config pipeline working, so that was my approach to force that specific version through the following lines:

    # LIBPNG
    find_package(PkgConfig REQUIRED)
    pkg_check_modules(PNG REQUIRED IMPORTED_TARGET libpng)
    target_link_libraries(${OutputExecutable} PkgConfig::PNG)

Here is the solution that inspired my own solution: What is the proper way to use pkg-config from cmake?

It is always a good idea to verbose these things, this is how the above looked in my terminal with some extra MESSAGE() lines:

-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2")
-- Checking for module 'libpng'
--   Found libpng, version 1.6.39
-- <TestApp> (DEBUG) PNG_INCLUDE_DIRS: /usr/local/Cellar/libpng/1.6.39/include/libpng16
-- <TestApp> (DEBUG) PNG_LIBRARY_DIRS: /usr/local/Cellar/libpng/1.6.39/lib
-- <TestApp> (DEBUG) PNG_LIBRARIES: png16
-- <TestApp> (DEBUG) PNG_FOUND: 1
-- <TestApp> (DEBUG) PNG_VERSION_STRING:

Hope this works, and extreme gratitude to the guys in the One Lone Coder Discord: @Moros1138, dandistine, fluff and everyone else who helped me to get this building on OSX.

Cheers.

Thanks for sharing this information. As this seems to be an issue with your build environment, I'm going to mark this as wontfix, however I want to leave the issue here so others can see the solutions you came up with.

I'll revisit this if/when it appears to be a problem for more people.

I'm glad you got it working for you, in the end!