- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在/usr/include/SDL2 上安装了 SDL2_image 库(在此目录中我可以找到 SDL_image.h)。
当我用 CLion 编译时一切正常,但在编辑器中,SDL2_image 库的包含和函数出现错误(编译器找到了这个库,但编辑器找不到)。
这是我的 CMake:
cmake_minimum_required(VERSION 3.2)
project(sdl)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(sdl ${SOURCE_FILES} Game.cpp Game.h)
INCLUDE(FindPkgConfig)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES})
add_custom_command(TARGET sdl POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/assets
$<TARGET_FILE_DIR:sdl>/assets)
问题是什么?
最佳答案
使用这个 FindSDL2_image.cmake 文件:
# Locate SDL2_image library
# This module defines
# SDL2_IMAGE_LIBRARY, the name of the library to link against
# SDL2_IMAGE_FOUND, if false, do not try to link to SDL2_image
# SDL2_IMAGE_INCLUDE_DIR, where to find SDL_image.h
#
# Additional Note: If you see an empty SDL2_IMAGE_LIBRARY_TEMP in your configuration
# and no SDL2_IMAGE_LIBRARY, it means CMake did not find your SDL2_Image library
# (SDL2_image.dll, libsdl2_image.so, SDL2_image.framework, etc).
# Set SDL2_IMAGE_LIBRARY_TEMP to point to your SDL2 library, and configure again.
# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
# as appropriate. These values are used to generate the final SDL2_IMAGE_LIBRARY
# variable, but when these values are unset, SDL2_IMAGE_LIBRARY does not get created.
#
# $SDL2 is an environment variable that would
# correspond to the ./configure --prefix=$SDL2
# used in building SDL2.
# l.e.galup 9-20-02
#
# Modified by Eric Wing.
# Added code to assist with automated building by using environmental variables
# and providing a more controlled/consistent search behavior.
# Added new modifications to recognize OS X frameworks and
# additional Unix paths (FreeBSD, etc).
# Also corrected the header search path to follow "proper" SDL2 guidelines.
# Added a search for SDL2main which is needed by some platforms.
# Added a search for threads which is needed by some platforms.
# Added needed compile switches for MinGW.
#
# On OSX, this will prefer the Framework version (if found) over others.
# People will have to manually change the cache values of
# SDL2_IMAGE_LIBRARY to override this selection or set the CMake environment
# CMAKE_INCLUDE_PATH to modify the search paths.
#
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
# This needed to change because "proper" SDL2 convention
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
# reasons because not all systems place things in SDL2/ (see FreeBSD).
#
# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake
# module with the minor edit of changing "SDL" to "SDL2" where necessary. This
# was not created for redistribution, and exists temporarily pending official
# SDL2 CMake modules.
#
# Note that on windows this will only search for the 32bit libraries, to search
# for 64bit change x86/i686-w64 to x64/x86_64-w64
#=============================================================================
# Copyright 2003-2009 Kitware, Inc.
#
# CMake - Cross Platform Makefile Generator
# Copyright 2000-2014 Kitware, Inc.
# Copyright 2000-2011 Insight Software Consortium
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the names of Kitware, Inc., the Insight Software Consortium,
# nor the names of their contributors may be used to endorse or promote
# products derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
FIND_PATH(SDL2_IMAGE_INCLUDE_DIR SDL_image.h
HINTS
${SDL2}
$ENV{SDL2}
$ENV{SDL2_IMAGE}
PATH_SUFFIXES include/SDL2 include SDL2
i686-w64-mingw32/include/SDL2
x86_64-w64-mingw32/include/SDL2
PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local/include/SDL2
/usr/include/SDL2
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
)
# Lookup the 64 bit libs on x64
IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
FIND_LIBRARY(SDL2_IMAGE_LIBRARY_TEMP
NAMES SDL2_image
HINTS
${SDL2}
$ENV{SDL2}
$ENV{SDL2_IMAGE}
PATH_SUFFIXES lib64 lib
lib/x64
x86_64-w64-mingw32/lib
PATHS
/sw
/opt/local
/opt/csw
/opt
)
# On 32bit build find the 32bit libs
ELSE(CMAKE_SIZEOF_VOID_P EQUAL 8)
FIND_LIBRARY(SDL2_IMAGE_LIBRARY_TEMP
NAMES SDL2_image
HINTS
${SDL2}
$ENV{SDL2}
$ENV{SDL2_IMAGE}
PATH_SUFFIXES lib
lib/x86
i686-w64-mingw32/lib
PATHS
/sw
/opt/local
/opt/csw
/opt
)
ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(SDL2_IMAGE_FOUND "NO")
IF(SDL2_IMAGE_LIBRARY_TEMP)
# Set the final string here so the GUI reflects the final state.
SET(SDL2_IMAGE_LIBRARY ${SDL2_IMAGE_LIBRARY_TEMP} CACHE STRING "Where the SDL2_image Library can be found")
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
SET(SDL2_IMAGE_LIBRARY_TEMP "${SDL2_IMAGE_LIBRARY_TEMP}" CACHE INTERNAL "")
SET(SDL2_IMAGE_FOUND "YES")
ENDIF(SDL2_IMAGE_LIBRARY_TEMP)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_IMAGE REQUIRED_VARS SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR)
在我的源代码树中,我有一个名为 cmake_modules 的文件夹,其中包含上面找到的 FindSDL2_image.cmake 文件。
您可以阅读该 .cmake 文件的底部以查看库并包含要使用的名称:FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_IMAGE REQUIRED_VARS SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR)
然后在我的 cmake 文件中看起来像这样:
PROJECT(project_name)
SET(SRC_FILES xxx.c xxx.c xxx.c xxx.c)
FIND_PACKAGE(SDL2 REQUIRED)
INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIR})
FIND_PACKAGE(OPENGL REQUIRED)
INCLUDE_DIRECTORIES( ${OPENGL_INCLUDE_DIR})
FIND_PACKAGE(SDL_IMAGE REQUIRED)
INCLUDE_DIRECTORIES( ${SDL2_IMAGE_INCLUDE_DIR})
ADD_LIBRARY(project_name SHARED ${SRC_FILES})
TARGET_LINK_LIBRARIES(project_name ${SDL2_LIBRARY} ${OPENGL_LIBRARIES} ${SDL2_IMAGE_LIBRARY})
关于c++ - CLion 无法识别 SDL2_image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31813588/
问题解决了 转到底部查看解决方案。 大家好,我用谷歌搜索了很长时间,但没有找到任何东西,所以,我们开始吧: 我有这样的设置: Compiler: MinGW IDE: Netbeans Library
如何在 SDL 中创建一个插入主窗口的新窗口?所以它可以是有重点的,有单独的绘图上下文和单独的处理事件。 最佳答案 窗中窗 您可以使用下面的示例在窗口中创建一个窗口。该示例将生成两个窗口,其中 sub
我是 SDL 的新手,我只是好奇为什么 sdl 使用静态和动态库?我的意思是,sdl.dll 中有哪些函数,为什么它是动态链接而不是静态链接?谢谢。 最佳答案 SDL.dll包含您在 SDL 中使用的
我通过 brew 在我的 mac 上安装了 SDL,但我无法包含它!这是我太简单的代码: #include int main(){ return 0; } 用cc编译时,CC找不到SDL.h
我正在尝试制作一个以恒定帧速率运行的 SDL 程序。但是我发现即使我的程序滞后很多并且跳过了很多帧(即使它以低帧运行并且没有渲染太多)。 你们有什么建议可以让我的程序运行更流畅吗? #include
我目前正在编写一款非常复杂和狡猾的游戏,它会让您充满敬畏和胜利 - 哦,好吧,这是 15 个谜题,我只是在熟悉 SDL。 我在窗口模式下运行,并使用 SDL_Flip 作为一般情况的页面更新,因为它会
我知道 SDL_TEXTUREACCESS_STATIC 和 SDL_TEXTUREACCESS_TARGET 之间的区别。我正在为一款游戏编写 SDL 后端,该游戏的平台无关核心不会告诉平台相关纹理
我们最近移植了 Bitfighter从 GLUT 到 SDL。这样做有很多好处,但也有一些缺点,特别是在窗口管理领域。 Bitfighter 在固定纵横比窗口(800x600 像素)中运行。用户可以将
我正在尝试使用 SDL 2.0 了解整个 2D 加速渲染过程。 所以我的问题是在屏幕上绘制圆圈最有效的方法是什么,为什么? 一些方法是: 首先创建一个软件表面,然后在该表面上绘制必要的像素,然后从该表
我正在尝试将纹理保存到 png 中,而我唯一得到的是 是屏幕的一部分的屏幕截图。 我的代码示例: src_texture = SDL_CreateTextureFromSurface( render
我正在使用 SDL1.2 在我的 openGL 框架中处理窗口管理。 程序运行时是否可以在不调用 SDL_Quit() 的情况下破坏窗口(表面)? ? 背景:我的框架实际上只是多媒体环境中的一个 gf
如何在 SDL 中缩放 Sprite ? 最佳答案 SDL 不直接提供缩放功能,但有 an additional library called SDL_gfx它提供旋转和缩放功能。还有another
我刚刚开始使用SDL2_ttf。我已经弄清楚如何使用 TTF_RenderText_Blished 在屏幕上获取一些文本,但是如何让它进行换行和自动换行? 似乎不支持\n;它只是创造一个空间而不是沿着
我安装了 FEDORA 和 SDL,并希望在编译时用 C 编程图形,我得到了很多对 SDL_MapRGB、SDL_Init 等的 undefined reference 我搜索了文件系统 SDL.dl
我在我的项目中使用 SDL 库,并且在 Windows 平台上工作。 当我决定将项目迁移到 SDL 2 时,我遇到了一个问题: SDL 1.2 中有一个选项可以将 stdout/stderr 的输出打
我正在尝试使用 Derelict 和 D 编写一个简单的图形测试程序。 当我尝试用 SDL 做几乎任何事情时,它都会出现段错误。这是有问题的代码: import std.stdio; import
我在考虑是否尝试使用 SDL 作为 DirectX 的替代品,似乎我只创建 2D 游戏,但是我找不到任何地方是否需要在最终用户计算机上安装 SDL 才能玩用 C# 开发的游戏,图形使用 SDL。 有人
我想使用 SDL_net 作为一个供少数程序使用的帮助程序库。然而,其中一些程序本身可能已经在使用 SDL。如果我理解正确的话,这意味着我在初始化/释放我的库时不能盲目使用 SDL_Init 和 SD
我希望我的游戏引擎停止将鼠标移动到中心(用于偏航和俯仰相机计算)。我写了一些应该处理它的代码,但鼠标在最小化时仍然移动。 void mainLoop() { // This is the ma
结构SDL_Keysym 有SDL_Scancode 和SDL_Keycode 成员。它们之间有什么区别?该文档并没有真正为我清除它。我都试过了,它们似乎做同样的事情。 最佳答案 参见 the SDL
我是一名优秀的程序员,十分优秀!