我有以下 cmake 文件:
cmake_minimum_required(VERSION 2.8)
include(ExternalProject)
project(freetype_test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
set(LIBS_DIR ${PROJECT_SOURCE_DIR}/libs)
set(FREETYPE_VER "2.5.3")
set(SDL2_VER "2.0.3")
# ---
# Freetype library
ExternalProject_Add(freetype_project
URL http://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VER}.tar.gz
PREFIX ${LIBS_DIR}/freetype
INSTALL_COMMAND ""
)
ExternalProject_Get_Property(freetype_project SOURCE_DIR)
ExternalProject_Get_Property(freetype_project BINARY_DIR)
set(FREETYPE_SRC ${SOURCE_DIR})
set(FREETYPE_BIN ${BINARY_DIR})
# ---
# SDL library
ExternalProject_Add(sdl2_project
URL http://www.libsdl.org/release/SDL2-${SDL2_VER}.tar.gz
PREFIX ${LIBS_DIR}/SDL2
INSTALL_COMMAND ""
)
ExternalProject_Get_Property(sdl2_project SOURCE_DIR)
ExternalProject_Get_Property(sdl2_project BINARY_DIR)
set(SDL2_SRC ${SOURCE_DIR})
set(SDL2_BIN ${BINARY_DIR})
# ---
# SDL_image library
ExternalProject_Add(sdl2_image_project
URL https://www.libsdl.org/projects/SDL_image/release/SDL2_image-2.0.0.tar.gz
DEPENDS sdl2_project
PREFIX ${LIBS_DIR}/SDL2_image
CONFIGURE_COMMAND LDFLAGS=-L${SDL2_BIN} CFLAGS=-I${SDL2_SRC}/include SDL2_CONFIG=${SDL2_BIN}/sdl2-config <SOURCE_DIR>/configure --prefix=<INSTALL_DIR> --enable-shared=no
BUILD_COMMAND make
INSTALL_COMMAND ""
)
ExternalProject_Get_Property(sdl2_image_project SOURCE_DIR)
ExternalProject_Get_Property(sdl2_image_project BINARY_DIR)
set(SDL2_IMAGE_SRC ${SOURCE_DIR})
set(SDL2_IMAGE_BIN ${BINARY_DIR})
# ---
include_directories(${FREETYPE_SRC}/include)
include_directories(${SDL2_SRC}/include)
include_directories(${SDL2_IMAGE_SRC}/include)
set(SOURCE freetype_test.cpp)
add_executable(ft_test ${SOURCE})
add_dependencies(ft_test
freetype_project
sdl2_project
sdl2_image_project
)
target_link_libraries(ft_test
${FREETYPE_BIN}/libfreetype.a
${SDL2_BIN}/libSDL2.a
)
我像这样运行它:cmake .
然后make
.
我第一次收到以下错误:
checking for SDL... checking for sdl2-config... /home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project-build/sdl2-config
checking for SDL - version >= 2.0.0... /home/xubuntu/git/testCmake/libs/SDL2_image/src/sdl2_image_project/configure: line 12359: /home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project-build/sdl2-config: Permission denied
/home/xubuntu/git/testCmake/libs/SDL2_image/src/sdl2_image_project/configure: line 12360: /home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project-build/sdl2-config: Permission denied
/home/xubuntu/git/testCmake/libs/SDL2_image/src/sdl2_image_project/configure: line 12363: /home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project-build/sdl2-config: Permission denied
/home/xubuntu/git/testCmake/libs/SDL2_image/src/sdl2_image_project/configure: line 12365: /home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project-build/sdl2-config: Permission denied
/home/xubuntu/git/testCmake/libs/SDL2_image/src/sdl2_image_project/configure: line 12367: /home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project-build/sdl2-config: Permission denied
no
*** Could not run SDL test program, checking why...
*** The test program compiled, but did not run. This usually means
*** that the run-time linker is not finding SDL or finding the wrong
*** version of SDL. If it is not finding SDL, you'll need to set your
*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point
*** to the installed location Also, make sure you have run ldconfig if that
*** is required on your system
***
*** If you have an old version installed, it is best to remove it, although
*** you may also be able to get things to work by modifying LD_LIBRARY_PATH
configure: error: *** SDL version 2.0.0 not found!
CMakeFiles/sdl2_image_project.dir/build.make:109: recipe for target 'libs/SDL2_image/src/sdl2_image_project-stamp/sdl2_image_project-configure' failed
make[2]: *** [libs/SDL2_image/src/sdl2_image_project-stamp/sdl2_image_project-configure] Error 1
CMakeFiles/Makefile2:180: recipe for target 'CMakeFiles/sdl2_image_project.dir/all' failed
make[1]: *** [CMakeFiles/sdl2_image_project.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
所以我执行以下操作:chmod -R 777 /home/xubuntu/git/testCmake/libs/SDL2
然后make
再次,但随后出现以下错误:
r: `u' modifier ignored since `D' is the default (see `U')
libtool: link: ranlib .libs/libSDL2_image.a
libtool: link: ( cd ".libs" && rm -f "libSDL2_image.la" && ln -s "../libSDL2_image.la" "libSDL2_image.la" )
libtool: link: gcc -I/home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project/include -I/usr/local/include/SDL2 -I/usr/include -D_REENTRANT -o showimage showimage.o -Wl,-rpath -Wl,/usr/local/lib -pthread -L/home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project-build ./.libs/libSDL2_image.a -L/usr/local/lib -lSDL2 -pthread
/home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project-build/libSDL2.a(SDL_dynapi.c.o): In function `get_sdlapi_entry':
/home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project/src/dynapi/SDL_dynapi.c:227: undefined reference to `dlopen'
/home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project/src/dynapi/SDL_dynapi.c:228: undefined reference to `dlsym'
/home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project/src/dynapi/SDL_dynapi.c:227: undefined reference to `dlopen'
/home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project/src/dynapi/SDL_dynapi.c:228: undefined reference to `dlsym'
...
/home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project-build/libSDL2.a(SDL_systhread.c.o): In function `SDL_SYS_CreateThread':
/home/xubuntu/git/testCmake/libs/SDL2/src/sdl2_project/src/thread/pthread/SDL_systhread.c:91: undefined reference to `dlsym'
collect2: error: ld returned 1 exit status
Makefile:516: recipe for target 'showimage' failed
make[3]: *** [showimage] Error 1
CMakeFiles/sdl2_image_project.dir/build.make:114: recipe for target 'libs/SDL2_image/src/sdl2_image_project-stamp/sdl2_image_project-build' failed
make[2]: *** [libs/SDL2_image/src/sdl2_image_project-stamp/sdl2_image_project-build] Error 2
CMakeFiles/Makefile2:180: recipe for target 'CMakeFiles/sdl2_image_project.dir/all' failed
make[1]: *** [CMakeFiles/sdl2_image_project.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
我已经尝试了几个小时,但我无法使用 cmake 安装 sdl、sdl-image。
谢谢。