never mind this. the error isnt from cmake but because i forgot to include lua.hpp and luaconf.h. it works in gcc before because i used it in pure c
include lua library in kreversi using cmake (kdegames)
-
29-05-2022 - |
سؤال
So, i'm working on adding lua script into kreversi. I am a newbie on cmake and this is my first time trying to code into kde projects.
I'm using lua5.2 and found out that cmake doesnt officially support lua5.2 library. So i searched and found this cmake for lua5.2 and imitate his or her CMakeList.txt and modified accordingly to the kreversi CMakeList.txt.
here is my modified 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 )
When i try to run cmake, and then make, there are compile errors "undefined reference to luaL_newstate()'" and "undefined reference to
luaL_openlibs(lua_State*)'" which may indicate something wrong with the linking process.
i tried :
message("lua library : " ${LUA_LIBRARIES})
and it outputs this :
lua library : /usr/lib/i386-linux-gnu/liblua5.2.so/usr/lib/i386-linux-gnu/libm.so
is that correct? how can i include and link lua5.2 in cmake?
I have already installed lua5.2-dev in my computer and without cmake, have successfully compile c-lua program with gcc test.c -I/usr/include/lua5.2 -llua5.2
المحلول