Could not locate OIS using CMake and Makefiles

1.6k views Asked by At

So I'm trying to compile a simple Ogre3D project:

C:\OgreSDK\Projects\Physics> cmake -G "MinGW Makefiles" ./
-- Looking for OGRE...
-- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE)
-- Found Ogre Ghadamon (1.9.0)
-- Found OGRE: optimized;C:/OgreSDK/lib/Release/OgreMain.lib;debug;C:/OgreSDK/lib/Debug/OgreMain_d.lib
-- Looking for OGRE_Paging...
-- Found OGRE_Paging: optimized;C:/OgreSDK/lib/Release/OgrePaging.lib;debug;C:/OgreSDK/lib/debug/OgrePaging_d.lib
-- Looking for OGRE_Terrain...
-- Found OGRE_Terrain: optimized;C:/OgreSDK/lib/Release/OgreTerrain.lib;debug;C:/OgreSDK/lib/debug/OgreTerrain_d.lib
-- Looking for OGRE_Property...
-- Found OGRE_Property: optimized;C:/OgreSDK/lib/Release/OgreProperty.lib;debug;C:/OgreSDK/lib/debug/OgreProperty_d.lib
-- Looking for OGRE_RTShaderSystem...
-- Found OGRE_RTShaderSystem: optimized;C:/OgreSDK/lib/Release/OgreRTShaderSystem.lib;debug;C:/OgreSDK/lib/debug/OgreRTShaderSystem_d.lib
-- Looking for OGRE_Volume...
-- Found OGRE_Volume: optimized;C:/OgreSDK/lib/Release/OgreVolume.lib;debug;C:/OgreSDK/lib/debug/OgreVolume_d.lib
-- Looking for OGRE_Overlay...
-- Found OGRE_Overlay: optimized;C:/OgreSDK/lib/Release/OgreOverlay.lib;debug;C:/OgreSDK/lib/debug/OgreOverlay_d.lib
-- Looking for OIS...
-- Could NOT find PkgConfig (missing:  PKG_CONFIG_EXECUTABLE)
-- Could not locate OIS
CMake Error at C:/OgreSDK/CMake/FindPkgMacros.cmake:120 (message):
  Required library OIS not found! Install the library (including dev
  packages) and try again.  If the library is already installed, set the
  missing variables manually in cmake.
Call Stack (most recent call first):
  C:/OgreSDK/CMake/FindOIS.cmake:82 (findpkg_finish)
  CMakeLists.txt:60 (find_package)


-- Configuring incomplete, errors occurred!
See also "C:/OgreSDK/Projects/Physics/CMakeFiles/CMakeOutput.log".

I checked, in the OgreSDK/bin folder I can see a OIS(_d).dll. If I try to setup a var OIS_HOME which point to a folder with dll folder within the ois.dll, it doesn't work either.

EDIT Here is a gist with all env vars listed https://gist.github.com/vinz243/0eea7dd96db785d6a4e3

EDIT 2

After some attempts I edited the findOIS.cmake like this:

#-------------------------------------------------------------------
# This file is part of the CMake build system for OGRE
#     (Object-oriented Graphics Rendering Engine)
# For the latest info, see http://www.ogre3d.org/
#
# The contents of this file are placed in the public domain. Feel
# free to make use of it in any way you like.
#-------------------------------------------------------------------

# - Try to find OIS
# Once done, this will define
#
#  OIS_FOUND - system has OIS
#  OIS_INCLUDE_DIRS - the OIS include directories 
#  OIS_LIBRARIES - link these to use OIS
#  OIS_BINARY_REL / OIS_BINARY_DBG - DLL names (windows only)

include(FindPkgMacros)
findpkg_begin(OIS)

# Get path, convert backslashes as ${ENV_${var}}
getenv_path(OIS_HOME)
getenv_path(OGRE_SDK)
getenv_path(OGRE_HOME)
getenv_path(OGRE_SOURCE)
getenv_path(OGRE_DEPENDENCIES_DIR)

# construct search paths
# set(OIS_PREFIX_PATH "C:\\OgreSDK\\bin")
# create_search_paths(OIS)
# redo search if prefix path changed
message(STATUS OIS_PREFIX_PATH ":  " ${OIS_PREFIX_PATH})
clear_if_changed(OIS_PREFIX_PATH
  OIS_LIBRARY_FWK
  OIS_LIBRARY_REL
  OIS_LIBRARY_DBG
  OIS_INCLUDE_DIR
)

set(OIS_LIBRARY_NAMES OIS)
get_debug_names(OIS_LIBRARY_NAMES)

use_pkgconfig(OIS_PKGC OIS)

# For OIS, prefer static library over framework (important when referencing OIS source build)
set(CMAKE_FIND_FRAMEWORK "LAST")

findpkg_framework(OIS)
if (OIS_HOME)
  # OIS uses the 'includes' path for its headers in the source release, not 'include'
  set(OIS_INC_SEARCH_PATH ${OIS_INC_SEARCH_PATH} ${OIS_HOME}/includes)
endif()
if (APPLE AND OIS_HOME)
  # OIS source build on Mac stores libs in a different location
  # Also this is for static build
  set(OIS_LIB_SEARCH_PATH ${OIS_LIB_SEARCH_PATH} ${OIS_HOME}/Mac/XCode-2.2/build)
endif()
find_path(OIS_INCLUDE_DIR NAMES OIS.h HINTS "C:\\OgreSDK\\include\\OIS" PATH_SUFFIXES OIS)
find_library(OIS_LIBRARY_REL NAMES ${OIS_LIBRARY_NAMES} HINTS "C:\\OgreSDK\\lib\\Release" PATH_SUFFIXES Release RelWithDebInfo MinSizeRel)
find_library(OIS_LIBRARY_DBG NAMES ${OIS_LIBRARY_NAMES_DBG} HINTS "C:\\OgreSDK\\lib\\debug" PATH_SUFFIXES Debug)

make_library_set(OIS_LIBRARY)
if (WIN32)
   set(OIS_BIN_SEARCH_PATH "C:\\OgreSDK\\bin")
   find_file(OIS_BINARY_REL NAMES "OIS.dll" HINTS ${OIS_BIN_SEARCH_PATH}
     PATH_SUFFIXES "" Release RelWithDebInfo MinSizeRel)
   find_file(OIS_BINARY_DBG NAMES "OIS_d.dll" HINTS ${OIS_BIN_SEARCH_PATH}
     PATH_SUFFIXES "" Debug )
endif()
mark_as_advanced(OIS_BINARY_REL OIS_BINARY_DBG)


findpkg_finish(OIS)

# add parent of OIS folder to support OIS/OIS.h
add_parent_dir(OIS_INCLUDE_DIRS OIS_INCLUDE_DIR)

# Reset framework finding
set(CMAKE_FIND_FRAMEWORK "FIRST")

And this is what is defined in CMakeCache.txt:

//Path to a file.
OIS_BINARY_DBG:FILEPATH=C:/OgreSDK/bin/Debug/OIS_d.dll

//Path to a file.
OIS_BINARY_REL:FILEPATH=C:/OgreSDK/bin/Release/OIS.dll

//x
OIS_INCLUDE_DIR:PATH=C:/OgreSDK/include/OIS

//x
OIS_LIBRARY_DBG:FILEPATH=OIS_LIBRARY_DBG-NOTFOUND

//x

EDIT 3

I edited the CMakeCache like this:

OIS_BINARY_DBG:FILEPATH=C:/OgreSDK/bin/Debug/OIS_d.dll

//Path to a file.
OIS_BINARY_REL:FILEPATH=C:/OgreSDK/bin/Release/OIS.dll

//x
OIS_INCLUDE_DIR:PATH=C:/OgreSDK/include/OIS

//x
OIS_LIBRARY_DBG:FILEPATH=C:/OgreSDK/lib/Debug/OIS_d.lib

//x
OIS_LIBRARY_FWK:STRING=NOTFOUND

//x
OIS_LIBRARY_REL:FILEPATH=C:/OgreSDK/lib/Debug/OIS.lib

And when I run make:

λ make
Scanning dependencies of target OgreApp
[ 50%] Building CXX object CMakeFiles/OgreApp.dir/BaseApplication.cpp.obj
[100%] Building CXX object CMakeFiles/OgreApp.dir/TutorialApplication.cpp.obj
make[2]: *** No rule to make target « C:/OgreSDK/lib/Debug/OIS.lib »,required for « dist/bin/OgreApp.exe ». Stop.
make[1]: *** [CMakeFiles/OgreApp.dir/all] Error 2
make: *** [all] Error2

EDIT 4: OK, i managed to run cmake. But this is what I get when bulding VS 2013 and v100 compiler:

2>  TutorialApplication.cpp
2>  Génération de code en cours...
2>BaseApplication.obj : error LNK2019: external symbol unresolved "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAABVerror_category@12@XZ) référencé dans la fonction "void __cdecl boost::system::`dynamic initializer for 'posix_category''(void)" (??__Eposix_category@system@boost@@YAXXZ)
2>TutorialApplication.obj : error LNK2001: external symbol unresolved "class boost::system::error_category const & __cdecl boost::system::generic_category(void)" (?generic_category@system@boost@@YAABVerror_category@12@XZ)
2>Bas**eApplication.obj : error LNK2019: external symbol unresolved "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAABVerror_category@12@XZ) référencé dans la fonction "void __cdecl boost::system::`dynamic initializer for 'native_ecat''(void)" (??__Enative_ecat@system@boost@@YAXXZ)
2>TutorialApplication.obj : error LNK2001: external symbol unresolved "class boost::system::error_category const & __cdecl boost::system::system_category(void)" (?system_category@system@boost@@YAABVerror_category@12@XZ)
2>C:\OgreSDK\Projects\Physics\build_win32\Debug\OgreApp_d.exe : fatal error LNK1120: 2 unresolved externals
========== Régénération globale : 1 a réussi, 1 a échoué, 0 a été ignoré ==========

EDIT 5

I'm building Ogre w/ VS 2013 and Boost. Successfully built OgreDeps and Ogre itself, but when running the SampleDemo.exe, it said that D3DCOMPILER_47.dll was missing, but finally found it in Steam folder. now I'm trying to recompile my project

EDIT #6

I compiled boost and generated the project. I opened it in VS 2013 and built ALL_BUILD successfully!!!! But how do I run it? The button Debug is named Attach... and when I build INSTALL task it gives me this in both debug and release

4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: The command "setlocal
4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: "C:\Program Files (x86)\CMake\bin\cmake.exe" -DBUILD_TYPE=Debug -P cmake_install.cmake
4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: :cmEnd
4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: :cmErrorLevel
4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: exit /b %1
4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: :cmDone
4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd
4>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: :VCEnd" stopped with code 1. 

EDIT #7

OK VS 2013 was generating the OgreApp.exe (or OgreApp_d) in dist. Copied every Ogre dll file in this folder and ran the exe and it worked :) Thank you guys for all your help. To conclude, the solution was rebuilding Ogre with the VS version I wanted to use

1

There are 1 answers

10
user3159253 On BEST ANSWER
  1. Why don't you wish to install pkg-config for Windows first? It would save you from a manual hacking of the CMakefile.txt-s.
  2. The last error you've got is due to missing (proper) linker flags for linking Boost.System library. Likely, one or several of the libraries being linked in also require Boost.System, and this dependency isn't resolved automatically. Typically pkg-config is used to handle the dependecies, but since you're doing-it-yourself, you should manually add the library dependency using imported library target. See this tutorial to get the idea how to properly include external pre-existing libraries to the build chain of your project.

Actually the standard way to define required Boost dependencies in CMakeLists.txt looks like this:

find_package(Boost 1.50 COMPONENTS program_options locale REQUIRED)

with the subsequent

include_directories(${Boost_INCLUDE_DIRS})
add_executable(an_executable ${AN_EXE_SOURCES})
target_link_libraries(an_executable
  ...
  ${Boost_LIBRARIES}
)

please note that at least some linkers (e.g. GNU ld) can't re-order a given library list, so if your application demand LibA and LibB, and LibB in turn depends on LibA, than LibB should go first in the linkers library list (if both LibA and LibB depend on each other, than one of these libraries should be included twice). I'm not sure that the problem is actual for Microsoft VC++ Linker, but it's worth mentioning.

Upd: @Vinz243 had to rebuild the OGRE library to get it properly linked against the test application.