DoNiFF
@DoNiFF
C++ Developer

Как исправить ошибку cannot find -llibpng: No such file or directory?

CMake собирает проект без ошибок, но ошибка происходит именно при компиляции проекта
Вот `CMakeLists.txt`
Открыть

cmake_minimum_required(VERSION 3.29)   # Minimum CMake version required
project(Minecraft)                    # Project name
include(FetchContent)                 # Include FetchContent module for dependencies

set(CMAKE_CXX_STANDARD 20)            # Set C++ standard to C++20

# Paths to libraries
set(LIBS_DIR ${CMAKE_SOURCE_DIR}/external)
set(GLFW_DIR ${LIBS_DIR}/glfw)
set(ZLIB_DIR ${LIBS_DIR}/zlib)
set(PNG_DIR ${LIBS_DIR}/libpng)
set(GLEW_DIR ${LIBS_DIR}/glew)

# Paths to GLEW additional libraries and headers
set(GLEW_INCLUDE_DIR ${GLEW_DIR}/include)
set(GLEW_LIB_DIR ${GLEW_DIR}/lib/Release/x64)
set(GLEW_BIN_DIR ${GLEW_DIR}/bin/Release/x64)
set(GLEW_LIB ${GLEW_LIB_DIR}/glew32.lib)

# Load GLFW
FetchContent_Declare(
        glfw
        GIT_REPOSITORY https://github.com/glfw/glfw.git
        GIT_TAG latest
)
FetchContent_MakeAvailable(glfw)

# Load GLM
FetchContent_Declare(
        glm
        GIT_REPOSITORY https://github.com/g-truc/glm.git
        GIT_TAG bf71a834948186f4097caa076cd2663c69a10e1e
)
FetchContent_MakeAvailable(glm)

# Find and load OpenGL
find_package(OpenGL REQUIRED)

# Settings for zlib
set(ZLIB_ROOT ${ZLIB_DIR})
set(ZLIB_LIBRARY zlib)
set(ZLIB_INCLUDE_DIR ${ZLIB_SOURCE_DIR} ${ZLIB_BINARY_DIR})

# Find and load Zlib (For dependency libpng)
find_package(ZLIB REQUIRED)

# Load GLEW
find_library(GLEW_LIB NAMES glew32s PATHS "${GLEW_LIB_DIR}" REQUIRED)

# Load Threads
if(UNIX)
    find_package(Threads REQUIRED)
endif ()

# Load libpng
add_subdirectory(${PNG_DIR})

# ========================================

# Add project files
add_subdirectory(source)

# Properties
if(PRODUCTION_BUILD)
    # setup the RESOURCES_PATH macro to be in the root folder of your exe
    target_compile_definitions("${PROJECT_NAME}" PUBLIC RESOURCES_PATH="./resources/")
    # remove the option to debug asserts.
    target_compile_definitions("${PROJECT_NAME}" PUBLIC PRODUCTION_BUILD=1)
else()
    # This is useful to get an RESOURCES_PATH in your IDE during development
    target_compile_definitions("${PROJECT_NAME}" PUBLIC RESOURCES_PATH="${CMAKE_CURRENT_SOURCE_DIR}/resources/")
    # add the option to debug asserts.
    target_compile_definitions("${PROJECT_NAME}" PUBLIC PRODUCTION_BUILD=0)
endif()


# Include GLEW libraries
link_directories(${GLEW_LIB_DIR})

target_include_directories(${PROJECT_NAME} PRIVATE ${GLEW_INCLUDE_DIR})
include_directories(${GLEW_INCLUDE_DIR})
include_directories(${ZLIB_INCLUDE_DIR})

# Link libraries
target_link_libraries(${PROJECT_NAME} PRIVATE glfw)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenGL::GL)
target_link_libraries(${PROJECT_NAME} PRIVATE ${GLEW_LIB})
target_link_libraries(${PROJECT_NAME} PRIVATE zlib)
target_link_libraries(${PROJECT_NAME} PRIVATE libpng)
target_link_libraries(${PROJECT_NAME} PRIVATE glm::glm)


Вот логи сборки
Открыть

-- The C compiler identification is GNU 13.1.0
-- The CXX compiler identification is GNU 13.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/JetBrains/CLion_2024.1.4/bin/mingw/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/JetBrains/CLion_2024.1.4/bin/mingw/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Including Win32 support
-- Looking for dinput.h
-- Looking for dinput.h - found
-- Looking for xinput.h
-- Looking for xinput.h - found
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
-- Documentation generation requires Doxygen 1.9.8 or later
CMake Deprecation Warning at cmake-build-debug/_deps/glm-src/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


CMake Deprecation Warning at cmake-build-debug/_deps/glm-src/CMakeLists.txt:2 (cmake_policy):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


-- Found OpenGL: opengl32
-- Found ZLIB: zlib (found version "1.3.1")
-- The ASM compiler identification is GNU
-- Found assembler: C:/JetBrains/CLion_2024.1.4/bin/mingw/bin/gcc.exe
-- Building for target architecture: amd64
-- Performing Test HAVE_LD_VERSION_SCRIPT
-- Performing Test HAVE_LD_VERSION_SCRIPT - Failed
-- Performing Test HAVE_SOLARIS_LD_VERSION_SCRIPT
-- Performing Test HAVE_SOLARIS_LD_VERSION_SCRIPT - Failed
-- Could not find an AWK-compatible program
-- Configuring done (82.6s)
-- Generating done (0.0s)
-- Build files have been written to: D:/Programming Projects/CPP Projects/Minecraft/cmake-build-debug

[Finished]


Вот логи компиляции
Открыть

[1/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/vulkan.c.obj
[2/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/platform.c.obj
[3/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/init.c.obj
[4/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/context.c.obj
[5/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/monitor.c.obj
[6/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/osmesa_context.c.obj
[7/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/null_init.c.obj
[8/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/egl_context.c.obj
[9/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/input.c.obj
[10/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/window.c.obj
[11/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/null_joystick.c.obj
[12/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/null_monitor.c.obj
[13/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/win32_time.c.obj
[14/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/win32_module.c.obj
[15/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/win32_thread.c.obj
[16/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/null_window.c.obj
[17/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/win32_init.c.obj
[18/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/win32_joystick.c.obj
[19/29] Building CXX object source/CMakeFiles/Minecraft.dir/window/Event.cpp.obj
[20/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/win32_monitor.c.obj
[21/29] Building CXX object source/CMakeFiles/Minecraft.dir/graphic/Texture.cpp.obj
[22/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/win32_window.c.obj
[23/29] Building CXX object source/CMakeFiles/Minecraft.dir/loader/PngLoader.cpp.obj
[24/29] Building CXX object source/CMakeFiles/Minecraft.dir/window/Window.cpp.obj
D:/Programming Projects/CPP Projects/Minecraft/source/window/Window.cpp:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
[25/29] Building CXX object source/CMakeFiles/Minecraft.dir/main.cpp.obj
D:/Programming Projects/CPP Projects/Minecraft/source/main.cpp:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
[26/29] Building CXX object source/CMakeFiles/Minecraft.dir/graphic/Shader.cpp.obj
[27/29] Building C object _deps/glfw-build/src/CMakeFiles/glfw.dir/wgl_context.c.obj
[28/29] Linking C static library _deps\glfw-build\src\libglfw3.a
[29/29] Linking CXX executable source\Minecraft.exe
FAILED: source/Minecraft.exe 
C:\WINDOWS\system32\cmd.exe /C "cd . && C:\JetBrains\CLion_2024.1.4\bin\mingw\bin\g++.exe -g  source/CMakeFiles/Minecraft.dir/main.cpp.obj source/CMakeFiles/Minecraft.dir/window/Window.cpp.obj source/CMakeFiles/Minecraft.dir/window/Event.cpp.obj source/CMakeFiles/Minecraft.dir/graphic/Shader.cpp.obj source/CMakeFiles/Minecraft.dir/graphic/Texture.cpp.obj source/CMakeFiles/Minecraft.dir/loader/PngLoader.cpp.obj -o source\Minecraft.exe -Wl,--out-implib,source\libMinecraft.dll.a -Wl,--major-image-version,0,--minor-image-version,0  _deps/glfw-build/src/libglfw3.a  -lopengl32  "D:/Programming Projects/CPP Projects/Minecraft/external/glew/lib/Release/x64/glew32.lib"  -lzlib  -llibpng  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && C:\WINDOWS\system32\cmd.exe /C "cd /D "D:\Programming Projects\CPP Projects\Minecraft\cmake-build-debug\source" && C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy Bypass -file C:/Users/doniff/.vcpkg-clion/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary "D:/Programming Projects/CPP Projects/Minecraft/cmake-build-debug/source/Minecraft.exe" -installedDir C:/Users/doniff/.vcpkg-clion/vcpkg/installed/x64-windows/debug/bin -OutVariable out""
C:\JetBrains\CLion_2024.1.4\bin\mingw\bin/ld.exe: cannot find -lzlib: No such file or directory
C:\JetBrains\CLion_2024.1.4\bin\mingw\bin/ld.exe: cannot find -llibpng: No such file or directory
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.



Вот исходные файлы проекта https://github.com/D0NIFF/Minecraft
  • Вопрос задан
  • 83 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы