0

在 Windows 中的 Cmake 上运行的相同代码找到了库,但在 mac 上找不到它们。代码找到 Include 目录很好,只是没有找到库

这是 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}
)
4

1 回答 1

1

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

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

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

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

于 2014-11-17T09:52:06.617 回答