2017-12-02 330 views
0

首先我使用克利翁和内置的cmake在Ubuntu 17cmake错误:没有这样的文件?

构建按摩日志:

[ 20%] Linking C executable pacman 
cc: error: SDL2_image: No such file or directory 
CMakeFiles/pacman.dir/build.make:172: recipe for target 'pacman' failed 
make[3]: *** [pacman] Error 1 
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/pacman.dir/all' failed 
make[2]: *** [CMakeFiles/pacman.dir/all] Error 2 
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/pacman.dir/rule' failed 
make[1]: *** [CMakeFiles/pacman.dir/rule] Error 2 
Makefile:118: recipe for target 'pacman' failed 
make: *** [pacman] Error 2 

cmakeList.txt:

cmake_minimum_required(VERSION 3.9) 
project(pacman C) 
set(CMAKE_C_STANDARD 99) 
set(SOURCE src/main.c src/input.c src/input.h src/view.c src/view.h src/models.h src/models.c) 
add_executable(pacman "${SOURCE}") 
include_directories(src) 
include_directories(src/SDL2-2.0.7/include) 
INCLUDE(FindPkgConfig) 
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2) 
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED) 
set(SDL2_IMAGE_INCLUDE_DIR "src/SDL2_image-2.0.2") 
include_directories("${SDL2_IMAGE_INCLUDE_DIR}") 
target_link_libraries(pacman "${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES}") 

和一个名为Makefile的文件:(我不太了解它!不幸的是,这个错误终于从这里升起)

# Makefile for showimage 

CC = gcc 
CFLAGS = $(shell sdl2-config --cflags) -Wall -O 
LIBS = $(shell sdl2-config --libs) -lSDL2_image 
EXE = showimage 

all: $(EXE) 

showimage: showimage.c Makefile 
    $(CC) -o [email protected] [email protected] $(CFLAGS) $(LIBS) 

clean: 
    -rm *.o $(EXE) 

注意,我敢肯定,我已经安装使用这个命令所有SDL2库100%:

sudo apt-get install libsdl2* 

和正确的工作,一切都完了,没有任何错误输出这样的:

Reading package lists... Done 
Building dependency tree  
Reading state information... Done 
Note, selecting 'libsdl2-mixer-dev' for glob 'libsdl2*' 
Note, selecting 'libsdl2-image-dev' for glob 'libsdl2*' 
Note, selecting 'libsdl2-gfx-dev' for glob 'libsdl2*' 
Note, selecting 'libsdl2-gfx-doc' for glob 'libsdl2*' 
Note, selecting 'libsdl2-mixer-2.0-0' for glob 'libsdl2*' 
Note, selecting 'libsdl2-dev' for glob 'libsdl2*' 
Note, selecting 'libsdl2-doc' for glob 'libsdl2*' 
Note, selecting 'libsdl2-ttf-dev' for glob 'libsdl2*' 
Note, selecting 'libsdl2-net-2.0-0' for glob 'libsdl2*' 
Note, selecting 'libsdl2-net-dev' for glob 'libsdl2*' 
Note, selecting 'libsdl2-image-2.0-0' for glob 'libsdl2*' 
Note, selecting 'libsdl2-2.0-0' for glob 'libsdl2*' 
Note, selecting 'libsdl2-gfx-1.0-0' for glob 'libsdl2*' 
Note, selecting 'libsdl2-ttf-2.0-0' for glob 'libsdl2*' 
libsdl2-2.0-0 is already the newest version (2.0.6+dfsg1-3ubuntu1). 
libsdl2-dev is already the newest version (2.0.6+dfsg1-3ubuntu1). 
libsdl2-doc is already the newest version (2.0.6+dfsg1-3ubuntu1). 
libsdl2-gfx-1.0-0 is already the newest version (1.0.1+dfsg-5). 
libsdl2-gfx-dev is already the newest version (1.0.1+dfsg-5). 
libsdl2-gfx-doc is already the newest version (1.0.1+dfsg-5). 
libsdl2-image-2.0-0 is already the newest version (2.0.1+dfsg-3). 
libsdl2-image-dev is already the newest version (2.0.1+dfsg-3). 
libsdl2-mixer-2.0-0 is already the newest version (2.0.1+dfsg1-3). 
libsdl2-mixer-dev is already the newest version (2.0.1+dfsg1-3). 
libsdl2-net-2.0-0 is already the newest version (2.0.1+dfsg1-3). 
libsdl2-net-dev is already the newest version (2.0.1+dfsg1-3). 
libsdl2-ttf-2.0-0 is already the newest version (2.0.14+dfsg1-2). 
libsdl2-ttf-dev is already the newest version (2.0.14+dfsg1-2). 
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. 

感谢您的帮助beforehands :)))))

回答

0

我已经通过以这种方式更改cmake代码修复了这一切: 只需手动给出sdl目录路径即可!

cmake_minimum_required(VERSION 3.9) 
project(pacman C) 

set(CMAKE_C_STANDARD 99) 
set(SOURCE src/main.c src/input.c src/input.h src/view.c src/view.h src/models.h src/models.c src/controler.c src/controler.h) 
add_executable(pacman "${SOURCE}") 
include_directories(src) 

include_directories("/usr/include/SDL2") 
target_link_libraries(pacman m SDL2 SDL2_gfx SDL2_image) 

ADD_DEFINITIONS(-D_REENTRANT) 
0

使用find_library代替PKG_SEARCH_MODULE

find_library(SDL2_LIBRARY NAME SDL2) 
target_include_directories(pacman ${SDL2_INCLUDE_DIR}) 
target_link_libraries(pacman ${SDL2_LIBRARY}) 

如果找不到SDL2,则必须将SDL2的路径添加到CMAKE_PREFIX_PATH,即CMake查找已安装软件的位置。

+0

我左边的文件不变的休息,但改变了PKG_SEARCH_MODULE到find_library只是复制你的代码,但这个错误上升{让错误在的CMakeLists.txt:11(target_include_directories):调用的参数无效 target_include_directories 的CMake错误:在此项目中使用以下变量,但它们设置为NOTFOUND。 请设置它们或确保它们已在CMake文件中正确设置和测试: SDL2_LIBRARY 通过目标“pacman”链接到目录/ home/mrtalebi/Projects/CLionProjects/pacman} –

+0

我发现编译器链接器命令:像这样,它提高了错误:-o pacman -lSDL2 SDL2_image -lSDL2 –

+0

您需要甚至像我指定的方式添加target_include_directories和target_link_directories。做到这一点,并在这里发布会发生什么 –

相关问题