Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将SDL2_网络与CMake链接_C++_Cmake_Sdl_Sdl 2_Sdl Net - Fatal编程技术网

C++ 将SDL2_网络与CMake链接

C++ 将SDL2_网络与CMake链接,c++,cmake,sdl,sdl-2,sdl-net,C++,Cmake,Sdl,Sdl 2,Sdl Net,我试图通过CMake将SDL2_net(SDL_net 2.0)链接到我的项目,但在四处搜索之后,我还没有找到解决方案。我的CMakeLists.txt当前如下所示: 1 cmake_minimum_required (VERSION 3.7) 2 project (SDL_net_test) 3 include (FindPkgConfig) 4 include (FindSDL_net) 5 6 pkg_search_module (SDL2 REQUIRED sdl2) 7 pkg_se

我试图通过CMake将SDL2_net(SDL_net 2.0)链接到我的项目,但在四处搜索之后,我还没有找到解决方案。我的CMakeLists.txt当前如下所示:

1 cmake_minimum_required (VERSION 3.7)
2 project (SDL_net_test)
3 include (FindPkgConfig)
4 include (FindSDL_net)
5 
6 pkg_search_module (SDL2 REQUIRED sdl2)
7 pkg_search_module (SDL_NET REQUIRED sdl2_net)
8 
9 include_directories (${SDL2_INCLUDE_DIRS} ${SDL_NET_INCLUDE_DIRS})
10 
11 add_executable (SDL_net_test main.cpp)
12 target_link_libraries (SDL_net_test ${SDL2_LIBRARIES} ${SDL_NET_LIBRARIES})
但是,当我尝试运行CMake时,会出现以下错误:


我已经从我的软件包管理器(Fedora 29上的dnf)安装了SDL2_net-devel软件包,并且我已经成功地将SDL2和SDL2_映像链接到以前基于它的软件包上,这非常有效。我也发现了,但我不完全确定如何使用它。我该怎么做呢?

因为提供答案的人只发表了一条关于它的评论,所以我自己会把它写在这里


解决方案似乎非常简单:我编写了
pkg\u搜索模块(SDL\u NET需要sdl2\u NET)
,而它应该是
pkg\u搜索模块(SDL\u NET需要sdl2\u NET)

因为提供答案的人只发表了一条关于它的评论,所以我将自己写在这里


解决方案似乎非常简单:我编写了
pkg\u搜索模块(SDL\u NET需要sdl2\u NET)
,而它应该是
pkg\u搜索模块(SDL\u NET需要sdl2\u NET)

为了方便地集成SDL2库和其他相关库(SDL2_-net、SDL2_-mixer等),我开发了一个可以如下使用的库:

  • 在我们的项目中克隆SDL2 CMake模块:
  • git克隆https://github.com/aminosbh/sdl2-cmake-modules cmake/sdl2
    
  • 在主CMakeLists.txt中添加以下行
  • 您甚至可以指定一个自定义路径来查找SDL2,SDL2_net。。。在Windows上特别有用

    cmake-DSDL2_PATH=“/PATH/to/sdl2”-DSDL2_NET_PATH=“/PATH/to/sdl2 NET”
    
    当然,您不应该忘记安装特定的软件包:

    #软呢帽/RPM
    sudo yum安装SDL2-devel SDL2_net-devel
    #Debian/Ubuntu
    sudo-apt安装libsdl2-dev libsdl2-net-dev
    
    为了方便地集成SDL2库和其他相关库(SDL2_-net、SDL2_-mixer等),我开发了一种可以如下使用的工具:

  • 在我们的项目中克隆SDL2 CMake模块:
  • git克隆https://github.com/aminosbh/sdl2-cmake-modules cmake/sdl2
    
  • 在主CMakeLists.txt中添加以下行
  • 您甚至可以指定一个自定义路径来查找SDL2,SDL2_net。。。在Windows上特别有用

    cmake-DSDL2_PATH=“/PATH/to/sdl2”-DSDL2_NET_PATH=“/PATH/to/sdl2 NET”
    
    当然,您不应该忘记安装特定的软件包:

    #软呢帽/RPM
    sudo yum安装SDL2-devel SDL2_net-devel
    #Debian/Ubuntu
    sudo-apt安装libsdl2-dev libsdl2-net-dev
    
    pkg_-config
    package,对应于Fedora30上的
    sdl2_-net
    sdl2_-net
    。您可以在
    SDL2\u net-devel
    RPM包的“文件”部分找到:。因此,您需要将
    SDL2\u net
    作为解决此问题的
    pkg\u搜索\u模块的最后一个参数传递给@Tsyvarev,谢谢
    pkg_config
    package,对应于Fedora30上的
    sdl2_net
    sdl2_net
    。您可以在
    SDL2\u net-devel
    RPM包的“文件”部分找到:。因此,您需要将
    SDL2\u net
    作为解决此问题的
    pkg\u搜索\u模块的最后一个参数传递给@Tsyvarev,谢谢!请注意,
    FindSDL2
    模块不是必需的,最新版本的
    sdl2
    已经附带了自己的
    SDL2Config.cmake
    请注意,
    FindSDL2
    模块不是必需的,最新版本的
    sdl2
    已经附带了自己的
    SDL2Config.cmake
    -- Could NOT find SDL_net (missing: SDL_NET_LIBRARIES SDL_NET_INCLUDE_DIRS) 
    -- Checking for one of the modules 'sdl2_net'
    CMake Error at /usr/share/cmake/Modules/FindPkgConfig.cmake:659 (message):
    None of the required 'sdl2_net' found
    Call Stack (most recent call first):
    CMakeLists.txt:7 (pkg_search_module)
    
    
    CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
    Please set them or make sure they are set and tested correctly in the CMake files:
    SDL_NET_INCLUDE_DIR (ADVANCED)
       used as include directory in directory /home/neboula/Programming/sandbox/sdl2_net
       used as include directory in directory /home/neboula/Programming/sandbox/sdl2_net
       used as include directory in directory /home/neboula/Programming/sandbox/sdl2_net
    SDL_NET_LIBRARY (ADVANCED)
        linked by target "SDL_net_test" in directory /home/neboula/Programming/sandbox/sdl2_net
    
    -- Configuring incomplete, errors occurred!
    See also "/home/neboula/Programming/sandbox/sdl2_net/build/CMakeFiles/CMakeOutput.log".
    
    list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)
    find_package(SDL2 REQUIRED)
    find_package(SDL2_net REQUIRED)
    target_link_libraries(${PROJECT_NAME} SDL2::Main SDL2:Net)