[英]Build error LNK1104 for CMake project using Irrlicht
我目前正在使用 Visual Studio 2019 进行学校项目,我们面临一个问题:
LINK : fatal error LNK1104: cannot open file 'Irrlicht.lib'
仅当我们已经编译了 CMake 文件时才出现错误,这是第一次工作。
我的 CMakeLists.txt:
cmake_minimum_required(VERSION 3.9)
project(IndieCMAKE)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 11)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
find_package(Irrlicht)
link_libraries(Irrlicht)
INCLUDE_DIRECTORIES(
"/usr/include/irrlicht"
"./include"
${PROJECT_SOURCE_DIR}/include
)
include_directories(inc)
add_executable(IndieCMAKE
./main.cpp)
这是我的FindIrrlicht.cmake
文件:
IF (NOT Irrlicht_INCLUDE_DIRS OR NOT Irrlicht_LIBRARIES)
FIND_PATH(Irrlicht_INCLUDE_DIRS
NAMES
irrlicht.h
PATHS
/usr/include/irrlicht/ # Default Fedora28 system include path
/usr/local/include/irrlicht/ # Default Fedora28 local include path
${CMAKE_MODULE_PATH}/include/ # Expected to contain the path to this file for Windows10
${Irrlicht_DIR}/include/ # Irrlicht root directory (if provided)
)
IF (MSVC) # Windows
SET(CMAKE_FIND_LIBRARY_PREFIXES "")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".lib")
ELSE (MSVC) # Linux
SET(CMAKE_FIND_LIBRARY_PREFIXES "lib")
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".so")
ENDIF(MSVC)
FIND_LIBRARY(Irrlicht_LIBRARIES
NAMES
Irrlicht
PATHS
/usr/lib64 # Default Fedora28 library path
/usr/lib/ # Some more Linux library path
/usr/lib/x86_64-linux-gnu/ # Some more Linux library path
/usr/local/lib/ # Some more Linux library path
/usr/local/lib64/ # Some more Linux library path
${CMAKE_MODULE_PATH}/ # Expected to contain the path to this file for Windows10
${Irrlicht_DIR}/ # Irrlicht root directory (if provided)
)
ENDIF (NOT Irrlicht_INCLUDE_DIRS OR NOT Irrlicht_LIBRARIES)
IF (Irrlicht_INCLUDE_DIRS AND Irrlicht_LIBRARIES)
SET(Irrlicht_FOUND TRUE)
ELSE (Irrlicht_INCLUDE_DIRS AND Irrlicht_LIBRARIES)
SET(Irrlicht_FOUND FALSE)
ENDIF (Irrlicht_INCLUDE_DIRS AND Irrlicht_LIBRARIES)
IF (Irrlicht_FIND_REQUIRED AND NOT Irrlicht_FOUND)
MESSAGE(FATAL_ERROR
" Irrlicht not found.\n"
" Windows: Fill CMake variable CMAKE_MODULE_PATH to the provided directory.\n"
" Linux: Install Irrlicht using your package manager ($> sudo dnf install irrlicht-devel).\n"
)
ENDIF (Irrlicht_FIND_REQUIRED AND NOT Irrlicht_FOUND)
这是我的 CMake GUI 变量:
如果您使用的是 CMake 查找模块,例如FindIrrlicht.cmake
文件,则Irrlicht_*
find_package(Irrlicht)
命令应该为 you. Assuming find_package()
actually found the package components correctly, you can use these Irrlicht_*
variables in your CMake file to specify where CMake should look for Irrlicht package headers and libraries.
类似下面的 CMake 文件应该可以工作:
cmake_minimum_required(VERSION 3.9)
project(IndieCMAKE)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 11)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# Use REQUIRED here, to ensure CMake finds the package before continuing.
find_package(Irrlicht REQUIRED)
# Don't use this command. It's old, and the syntax didn't work, in your case.
#link_libraries(Irrlicht)
# Specify your directories that contain headers, including the Irrlicht headers.
include_directories(
${Irrlicht_INCLUDE_DIRS}
)
# Define your executable target.
add_executable(IndieCMAKE
main.cpp
)
# Link the Irrlicht library to your executable target.
target_link_libraries(IndieCMAKE PRIVATE ${Irrlicht_LIBRARIES})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.