Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linker fails to find GLUT #11

Closed
symbolix opened this issue Apr 23, 2023 · 2 comments
Closed

Linker fails to find GLUT #11

symbolix opened this issue Apr 23, 2023 · 2 comments
Assignees
Labels
wontfix This will not be worked on

Comments

@symbolix
Copy link

symbolix commented Apr 23, 2023

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.

@symbolix symbolix added the bug Something isn't working label Apr 23, 2023
@symbolix
Copy link
Author

symbolix commented Apr 24, 2023

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.

@Moros1138
Copy link
Owner

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!

@Moros1138 Moros1138 added wontfix This will not be worked on and removed bug Something isn't working labels Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants