2017-12-02 344 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。做到這一點,並在這裏發佈會發生什麼 –

相關問題