使用cmake(kdegames)在kreversi中包含lua库

时间:2013-05-17 10:13:28

标签: lua cmake kde

所以,我正在努力将lua脚本添加到kreversi中。我是cmake的新手,这是我第一次尝试编写kde项目代码。

我正在使用lua5.2并发现cmake没有正式支持lua5.2库。所以我搜索并找到this cmake获取lua5.2并模仿他或她的CMakeList.txt并相应地修改为kreversi CMakeList.txt。

这是我修改过的kreversi CMakeList:

project(kreversi)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")

if(NOT COMPILING_KDEGAMES)
    find_package(KDE4 REQUIRED)
    include(KDE4Defaults)
    include(MacroLibrary)
    find_package(KDEGames 4.9.0 REQUIRED)

    add_definitions(${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
    add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
    include_directories(${KDEGAMES_INCLUDE_DIRS} ${KDEGAMES_INCLUDE_DIR}/highscore ${KDE4_INCLUDES} ${QDBUS_INCLUDE_DIRS})
endif(NOT COMPILING_KDEGAMES)

add_subdirectory( pics ) 
add_subdirectory( sounds ) 
add_subdirectory( icons ) 
add_subdirectory( doc )

find_package(Lua52 REQUIRED) #### I ADDED THIS LINE #####

include_directories( ${CMAKE_SOURCE_DIR}/libkdegames/highscore ${LUA_INCLUDE_DIR} ) #### I MODIFIED THIS LINE #####

########### next target ###############

set(kreversi_SRCS 
    kreversichip.cpp
    kreversigame.cpp
    kreversiscene.cpp
    kreversiview.cpp
    Engine.cpp
    highscores.cpp
    mainwindow.cpp
    main.cpp )

kde4_add_kcfg_files(kreversi_SRCS preferences.kcfgc)

kde4_add_app_icon(kreversi_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/icons/hi*-app-kreversi.png")
kde4_add_executable(kreversi ${kreversi_SRCS})
target_link_libraries(kreversi ${KDE4_KDEUI_LIBS} kdegames ${LUA_LIBRARIES}) #### I MODIFIED THIS LINE #####
install(TARGETS kreversi  ${INSTALL_TARGETS_DEFAULT_ARGS} )

########### install files ###############

install( PROGRAMS kreversi.desktop  DESTINATION  ${XDG_APPS_INSTALL_DIR} )
#install( FILES kreversi.kcfg  DESTINATION  ${KCFG_INSTALL_DIR} )
install( FILES kreversiui.rc  DESTINATION  ${DATA_INSTALL_DIR}/kreversi )

当我尝试运行cmake,然后make时,会出现编译错误“未定义引用luaL_newstate()'" and "undefined reference to luaL_openlibs(lua_State *)'”,这可能表示链接过程有问题。

我试过了:

message("lua library : " ${LUA_LIBRARIES})

并输出:

lua library : /usr/lib/i386-linux-gnu/liblua5.2.so/usr/lib/i386-linux-gnu/libm.so

是正确的吗?我如何在cmake中包含和链接lua5.2?

我已经在我的计算机上安装了lua5.2-dev而没有使用cmake,已经使用gcc test.c -I / usr / include / lua5.2 -llua5.2成功编译了c-lua程序

1 个答案:

答案 0 :(得分:0)

不要小心这个。错误不是来自cmake,但因为我忘了包含lua.hpp和luaconf.h。它之前在gcc中工作,因为我在纯c中使用它