Reputation: 11
I'm currently working on a school project with Visual Studio 2019, and we face a problem:
LINK : fatal error LNK1104: cannot open file 'Irrlicht.lib'
The error only came when we already have compiled our CMake file, the first time it's working.
My 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)
Here is my FindIrrlicht.cmake
file:
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)
Here are my CMake GUI variables:
Upvotes: 1
Views: 293
Reputation: 18376
If you are using a CMake Find Module, such as a FindIrrlicht.cmake
file, the find_package(Irrlicht)
command should populate some Irrlicht_*
CMake variables for 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.
Something like the following CMake file should work:
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})
Upvotes: 0