无法使用CMake和Makefiles找到OIS

时间:2014-11-28 11:49:14

标签: makefile cmake ogre

所以我试图编译一个简单的Ogre3D项目:

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".

我检查过,在OgreSDK / bin文件夹中我可以看到一个OIS(_d).dll。如果我尝试设置一个var OIS_HOME,它指向ois.dll中包含dll文件夹的文件夹,它也不起作用。

修改 这是列出https://gist.github.com/vinz243/0eea7dd96db785d6a4e3

所有env vars的要点

编辑2

经过一些尝试后,我编辑了这样的findOIS.cmake:

#-------------------------------------------------------------------
# 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")

这就是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

编辑3

我编辑了这样的CMakeCache:

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

当我运行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

编辑4:好的,我设法运行cmake。但这是我在构建VS 2013和v100编译器时得到的结果:

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é ==========

编辑5

我正在建造带有VS 2013和Boost的Ogre。成功构建了OgreDeps和Ogre本身,但是在运行SampleDemo.exe时,它说D3DCOMPILER_47.dll丢失,但终于在Steam文件夹中找到它。现在我试图重新编译我的项目

编辑#6

我编译了boost并生成了项目。我在VS 2013中打开它并成功构建了 ALL_BUILD !但是我该怎么办呢?按钮 Debug 命名为 Attach ... ,当我构建 INSTALL 任务时,它在调试和发布中都给了我

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. 

编辑#7

确定VS 2013正在dist中生成OgreApp.exe(或OgreApp_d)。复制此文件夹中的每个Ogre DLL文件并运行exe,它工作:)谢谢你们所有的帮助。 总而言之,解决方案是使用我想要使用的VS版本重建Ogre

1 个答案:

答案 0 :(得分:1)

  1. 为什么不希望先安装pkg-config for Windows?它可以帮助您避免手动入侵CMakefile.txt-s。
  2. 您遇到的最后一个错误是由于缺少(正确的)链接Boost.System库的链接器标志。可能,链接的一个或多个库也需要Boost.System,并且这种依赖关系不会自动解决。通常pkg-config用于处理依赖项,但由于您自己动手,因此应使用imported library target手动添加库依赖项。请参阅this tutorial以了解如何将外部预先存在的库正确包含到项目的构建链中。
  3. 实际上,在CMakeLists.txt中定义所需的Boost依赖关系的标准方法如下所示:

    find_package(Boost 1.50 COMPONENTS program_options locale REQUIRED)
    

    随后的

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

    请注意,至少一些链接器(例如GNU ld)无法重新排序给定的库列表,因此如果您的应用程序需要LibA和LibB,而LibB依赖于LibA,那么LibB应该先行在链接库列表中(如果LibA和LibB彼此依赖,则应该包括其中一个库两次)。我不确定问题是否适用于Microsoft VC ++ Linker,但值得一提。

    更新:@ Vinz243必须重建OGRE库才能使其与测试应用程序正确链接。