在Windows中的Cmake上运行的相同代码找到了库,但是在Mac上却找不到它们。

这是Cmake输出的屏幕


这是目录结构的屏幕


这是CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

project (GameCreatorEngine)

# version can be passed into the application from CMake TODO

set(cmake_test_VERSION_MAJOR 1)
set(cmake_test_VERSION_MINOR 3)

# compiler flags

add_definitions(
    -c
    -W4
)

# SDL LIB INCLUDES

SET( SDL2_SEARCH_PATHS
    ${SDL2_ROOT_DIR}
    ./res/lib/SDL2
)

FIND_PATH( SDL2_INCLUDE_DIRS
    NAMES
        SDL.h SDL2/SDL.h
    PATHS
        ${SDL2_SEARCH_PATHS}
    PATH_SUFFIXES
        include
)

FIND_LIBRARY( SDL2
    NAMES
        SDL2.lib
    PATHS
        ${SDL2_SEARCH_PATHS}
    PATH_SUFFIXES
        lib
)

FIND_LIBRARY( SDL2_MAIN
    NAMES
        SDL2main.lib
    PATHS
        ${SDL2_SEARCH_PATHS}
    PATH_SUFFIXES
        lib
)

IF ( SDL2_INCLUDE_DIRS AND SDL2_MAIN AND SDL2)
    SET( SDL2_FOUND TRUE )
    MESSAGE(STATUS "Looking for SDL2 - found")
ELSE ( SDL2_INCLUDE_DIRS AND SDL2_MAIN AND SDL2 )
    SET( SDL2_FOUND FALSE )
    MESSAGE(STATUS "Looking for SDL2 - not found")
ENDIF ( SDL2_INCLUDE_DIRS AND SDL2_MAIN AND SDL2 )

# GLEW LIB INCLUDES

SET(GLEW_SEARCH_PATHS
    ${GLEW_ROOT_DIR}
    ./res/lib/GLEW
)

FIND_PATH( GLEW_INCLUDE_DIRS
    NAMES
        glew.h
    PATHS
        ${GLEW_SEARCH_PATHS}
    PATH_SUFFIXES
        include
)

FIND_LIBRARY( GLEW_LIBRARIES
    NAMES
        glew32
    PATHS
        ${GLEW_SEARCH_PATHS}
    PATH_SUFFIXES
        lib/Release/Win32
)

IF ( GLEW_INCLUDE_DIRS AND GLEW_LIBRARIES )
    SET( GLEW_FOUND TRUE )
    MESSAGE( STATUS "Looking for GLEW - found" )
ELSE ( GLEW_INCLUDE_DIRS AND GLEW_LIBRARIES )
    SET( GLEW_FOUND FALSE )
    MESSAGE( STATUS "Looking for GLEW - not found" )
ENDIF ( GLEW_INCLUDE_DIRS AND GLEW_LIBRARIES )

# ASSIMP

SET(ASSIMP_SEARCH_PATHS
    ${ASSIMP_ROOT_DIR}
    ./res/lib/assimp
)

FIND_PATH( ASSIMP_INCLUDE_DIRS
    NAMES
        mesh.h
    PATHS
        ${ASSIMP_SEARCH_PATHS}
    PATH_SUFFIXES
        include
)

FIND_LIBRARY( ASSIMP_LIBRARIES
    NAMES
        assimp ASSIMP
    PATHS
        ${ASSIMP_SEARCH_PATHS}
    PATH_SUFFIXES
        lib
        lib/x86
        lib/x64
)

IF ( ASSIMP_INCLUDE_DIRS AND ASSIMP_LIBRARIES )
    SET( ASSIMP_FOUND TRUE )
    MESSAGE(STATUS "Looking for ASSIMP - found")
ELSE ( ASSIMP_INCLUDE_DIRS AND ASSIMP_LIBRARIES )
    SET( ASSIMP_FOUND FALSE )
    MESSAGE(STATUS "Looking for ASSIMP - not found")
ENDIF ( ASSIMP_INCLUDE_DIRS AND ASSIMP_LIBRARIES )

# glm maths lib
SET( GLM_SEARCH_PATHS
    ${GLM_ROOT_DIR}
    ./res/lib/glm
)

FIND_PATH( GLM_INCLUDE_DIRS
    NAMES
        glm.hpp
    PATHS
        ${GLM_SEARCH_PATHS}
    PATH_SUFFIXES
        include
)

IF ( GLM_INCLUDE_DIRS)
    SET( GLM_FOUND TRUE )
    MESSAGE(STATUS "Looking for GLM - found")
ELSE ( GLM_INCLUDE_DIRS )
    SET( ASSIMP_FOUND FALSE )
    MESSAGE(STATUS "Looking for GLM - not found")
ENDIF ( GLM_INCLUDE_DIRS )

# OpenGL
find_package(OpenGL REQUIRED)

# GameCreatorLibrary
file(GLOB HDRS ${ENGINE_SOURCE_DIR}src/*.h)
file(GLOB SRCS ${ENGINE_SOURCE_DIR}src/*.cpp src/*.c)
add_executable(GameCreatorEngine ${HDRS} ${SRCS})

# Define the include DIRs
include_directories(
    ${SDL2_INCLUDE_DIRS}
    ${GLEW_INCLUDE_DIRS}
    ${ASSIMP_INCLUDE_DIRS}
    ${GLM_INCLUDE_DIRS}
    ${OPENGL_INCLUDE_DIRS}
    ${ENGINE_SOURCE_DIR}/headers
    ${ENGINE_SOURCE_DIR}/sources
)

# Define the link libraries
target_link_libraries( GameCreatorEngine
    ${SDL2}
    ${SDL2_MAIN}
    ${GLEW_LIBRARIES}
    ${ASSIMP_LIBRARIES}
    ${OPENGL_LIBRARIES}
)

最佳答案

库的正确文件名扩展名在不同平台上有所不同。虽然Windows上的静态和dll导入库都使用.lib,但是OS X使用不同的命名约定(.a表示静态库,.so / .dylib表示动态库,可能带有lib前缀)。

为了仍然允许代码使用所有这些不同的命名约定,find_library希望您完全省略任何扩展名或前缀,而仅给出库的裸名。

因此,您应该只写find_library(SDL2 NAMES SDL2.lib [...])而不是find_library(SDL2 NAMES SDL2 [...])

从您的问题看来,您似乎还试图将Windows X二进制文件(.lib.dll文件扩展名)链接到OS X构建。这是行不通的。您需要为OS X编译的另一套二进制文件。

关于c++ - CMake FIND_LIBRARY在Windows上有效,但在OS X上无效,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26931872/

10-17 00:33