Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link issue on Linux #11

Closed
RhettTR opened this issue Jun 21, 2020 · 2 comments
Closed

Link issue on Linux #11

RhettTR opened this issue Jun 21, 2020 · 2 comments

Comments

@RhettTR
Copy link

RhettTR commented Jun 21, 2020

Hi. I have tried to make a Linux version of lqt.

This is my CMakeLists.txt (made only for Linux and what Qt I need) :

 cmake_minimum_required(VERSION 3.1.0)

 project(lqt5)

 set(REUSE_FILES 1)
 set(CMAKE_BUILD_TYPE Debug)

 set(Qt5Script_DIR /home/test/projects/alben/build-qt5/qtbase/lib/cmake/Qt5Script)
 set(Qt5ScriptTools_DIR /home/test/projects/alben/build-qt5/qtbase/lib/cmake/Qt5ScriptTools)
 set(Qt5OpenGL_DIR /home/test/projects/alben/build-qt5/qtbase/lib/cmake/Qt5OpenGL)
 set(Qt5UiTools_DIR /home/test/projects/alben/build-qt5/qtbase/lib/cmake/Qt5UiTools)
 set(Qt5WebSockets_DIR /home/test/projects/alben/build-qt5/qtbase/lib/cmake/Qt5WebSockets)


 set(CMAKE_SOURCE_DIR /home/test/projects/alben/lqt)
 set(CMAKE_BINARY_DIR /home/test/projects/alben/build-lqt)



set(CMAKE_RUNTIME_OUTPUT_DIRECTORY  ${CMAKE_BINARY_DIR}/bin) 
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY  ${CMAKE_BINARY_DIR}/lib) 
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY  ${CMAKE_BINARY_DIR}/lib) 

set(LUA_INCLUDE_DIR ${CMAKE_BINARY_DIR}/../lqt/modules/src/LuaJIT/src)
set(CMAKE_PROGRAM_PATH ${LUA_INCLUDE_DIR})


set(CMAKE_PREFIX_PATH /home/test/projects/alben/build-qt5/qtbase/lib/cmake)
set(LUA_LIBRARIES ${LUA_INCLUDE_DIR}/libluajit.so)


set(QT_SCHEMA_DIR ${CMAKE_BINARY_DIR}/../lqt/generator/schema)

find_package(Qt5 REQUIRED
    Core 
    Sql
    Positioning
    Script
    ScriptTools
    Gui
    Widgets
    OpenGL
    PrintSupport
    UiTools
)



set(VERBOSE_BUILD 1)

set(EXTRA_LUA_OPTIONS )
option(VERBOSE_BUILD "Create a verbose build which logs every binding call" ON)
if(VERBOSE_BUILD)
    add_definitions(-DVERBOSE_BUILD)
    set(EXTRA_LUA_OPTIONS -v)
endif()



find_package(Lua51 REQUIRED)

find_program(LUA_CMD NAMES luajit lua lua5.1 lua51)
message("-- Lua program is : ${LUA_CMD}")



set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS  "${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -flat_namespace -undefined   dynamic_lookup")
set(CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS "${CMAKE_SHARED_MODULE_CREATE_CXX_FLAGS} -flat_namespace -undefined dynamic_lookup")

add_subdirectory(cpptoxml)



set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -std=c++11 -Wno-deprecated-declarations")


function(build_qt_lib_binding BINDING_HEADER)

    <snipped>

endfunction()


set(REUSE_FILES 1)
set(QT_LIBRARIES Core)
build_qt_lib_binding(QtCore)

set(REUSE_FILES 1)
set(QT_LIBRARIES Sql Core)
build_qt_lib_binding(QtSql QtCore)

set(REUSE_FILES 1)
set(QT_LIBRARIES Positioning Core)
build_qt_lib_binding(QtPositioning QtCore)

set(REUSE_FILES 1)
set(QT_LIBRARIES Script Core)
build_qt_lib_binding(QtScript QtCore)

set(REUSE_FILES 1)
set(QT_LIBRARIES ScriptTools Widgets Gui Script Core)
build_qt_lib_binding(QtScriptTools QtWidgets QtGui QtScript QtCore)

set(REUSE_FILES 1)
set(QT_LIBRARIES Gui Core)
build_qt_lib_binding(QtGui QtCore)

set(REUSE_FILES 1)
set(QT_LIBRARIES Widgets Gui Core)
build_qt_lib_binding(QtWidgets QtGui QtCore)

set(REUSE_FILES 1)
set(QT_LIBRARIES OpenGL Widgets Gui Core)
build_qt_lib_binding(QtOpenGL QtWidgets QtGui QtCore)

set(REUSE_FILES 1)
set(QT_LIBRARIES PrintSupport Widgets Gui Core)
build_qt_lib_binding(QtPrintSupport QtWidgets QtGui QtCore)

set(REUSE_FILES 1)
set(QT_LIBRARIES UiTools Widgets Gui Core)
build_qt_lib_binding(QtUiTools QtWidgets QtGui QtCore)



add_subdirectory(modules/lrdb)
add_subdirectory(modules/lpeglabel)
add_subdirectory(modules/lfs)
add_subdirectory(modules/lpath)
add_subdirectory(modules/lua-miniz)
add_subdirectory(modules/luautf8)
add_subdirectory(modules/luagbk)
add_subdirectory(modules/luasocket)
add_subdirectory(modules/lanes)

The cmake:

test@test-VirtualBox:~/projects/alben/build-lqt$ cmake ../lqt
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Lua53: /usr/local/lib/liblua.a;/usr/lib/x86_64-linux-gnu/libm.so (found version "5.1.4") 
-- Lua program is : /home/test/projects/alben/lqt/modules/src/LuaJIT/src/luajit
-- Configuring done
-- Generating done
-- Build files have been written to: /home/test/projects/alben/build-lqt

The make finishes to 100%.

But when I run this script:

--------------------------------- hello world.lua ------------------
package.cpath = "/home/test/projects/alben/build-lqt/lib/?.so"

local QtCore = require 'qtcore'
local QtGui = require 'qtgui'
local QtWidgets = require 'qtwidgets'

local app = QtWidgets.QApplication.new(select('#',...) + 1, {'lua', ...})

local btn = QtWidgets.QPushButton.new("Hello World!")
btn:connect('2pressed()', function(self)
    print("I'm about to close...")
    self:close()
end)
btn:setWindowTitle("A great example!")
btn:resize(300,50)
btn:show()

app.exec()

the output is:

test@test-VirtualBox:~$ lua '/home/test/projects/alben/scripts/hello world.lua' 
lua: error loading module 'qtcore' from file '/home/test/projects/alben/build-lqt/lib/qtcore.so':
    /home/test/projects/alben/build-lqt/lib/qtcore.so: undefined symbol: lua_tonumber
stack traceback:
    [C]: in ?
    [C]: in function 'require'
    /home/test/projects/alben/scripts/hello world.lua:3: in main chunk
    [C]: in ?

This must be a link error .. ?

@sanikoyes
Copy link
Collaborator

sanikoyes commented Jun 22, 2020

it seems cmake detect wrong version of lua:
-- Found Lua53: /usr/local/lib/liblua.a;/usr/lib/x86_64-linux-gnu/libm.so (found version "5.1.4")
correct is:
/home/test/projects/alben/lqt/modules/src/LuaJIT/src/libluajit.a or libluajit.so

@RhettTR
Copy link
Author

RhettTR commented Jun 22, 2020

Thank you for the reply. It now seems to work.

I had to make a special file FindLuaJiT.cmake in /usr/share/cmake-3.10/Modules to find luajit.

find_path(LUA_INCLUDE_DIR lua.h
  PATHS
  /home/test/projects/alben/lqt/modules/src/LuaJIT/src
)

find_library(LUA_LIBRARY
  NAMES libluajit.a
  PATHS
  /home/test/projects/alben/lqt/modules/src/LuaJIT/src
)

<snipped>

The CMakeLists.txt:

<snipped>

find_package(LuaJiT REQUIRED)

find_program(LUA_CMD NAMES luajit)
message("-- Lua program is : ${LUA_CMD}")

<snipped>

The cmake:

test@test-VirtualBox:~/projects/alben/build-lqt$ cmake ../lqt
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found LuaJiT: /home/test/projects/alben/lqt/modules/src/LuaJIT/src/libluajit.a;/usr/lib/x86_64-linux-gnu/libm.so (found version "5.1.4") 
-- Lua program is : /home/test/projects/alben/lqt/modules/src/LuaJIT/src/luajit
-- Configuring done
-- Generating done
-- Build files have been written to: /home/test/projects/alben/build-lqt

The make finishes to 100%.

I now ran luajit and it worked (writing out debug info):

test@test-VirtualBox:~/projects/alben/lqt/modules/src/LuaJIT/src$ ./luajit '/home/test/projects/alben/scripts/hello world.lua'
[0x7f84fcd54b80; static] QApplication :: QApplication (2)
lqtL_register 0x5614f8097360 QApplication*
[0x7f84fcd54b80; static] QPushButton :: QPushButton (1)
[0x7f84fcd54b80; 0x5614f8097360] call virtual QApplication :: notify (10) => 0
[0x7f84fcd54b80; 0x5614f8097360] call virtual QApplication :: notify (10) => 0
[0x7f84fcd54b80; 0x5614f8097360] call virtual QApplication :: notify (10) => 0
lqtL_register 0x5614f8159940 QPushButton*
Connect method (0x5614f8159940) 32(`2pressed()`) to lua-method `1LQT_SLOT_0()`
lqtL_touintarray n=21
dump lqtL_touintarray data, size = 21
21, 8, 0, 0, 0, 1, 14, 0, 20, 0, 0, 0, 0, 0, 0, 2, 
0, 19, 2, 10, 43, 
StringData is : LuaObject(QPushButton*: 0x5614f8159940)
Array: 0 39 72 88
StringData is : 
Array: 1 0 88 65
StringData is : LQT_SLOT_0
Array: 2 10 65 52
Dump stringdata
3, 0, 0, 0, 255, 255, 255, 255, 39, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 88, 0, 0, 0, 
0, 0, 0, 0, 255, 255, 255, 255, 10, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 76, 117, 97, 79, 
98, 106, 101, 99, 116, 40, 81, 80, 117, 115, 104, 66, 117, 116, 116, 111, 
110, 42, 58, 32, 48, 120, 53, 54, 49, 52, 102, 56, 49, 53, 57, 57, 
52, 48, 41, 0, 0, 76, 81, 84, 95, 83, 76, 79, 
[0x7f84fcd54b80; 0x5614f8159940] call virtual QObject :: connectNotify (22) => 0
[0x7f84fcd54b80; 0x5614f8159940] QWidget :: setWindowTitle (2)

<snipped>

lua.h in LuaJIT/src has version 5.1.4. What does it take to update to the latest lua 5.3.5 version ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants