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

Build error #488

Open
lePereT opened this issue May 3, 2020 · 11 comments · Fixed by #489
Open

Build error #488

lePereT opened this issue May 3, 2020 · 11 comments · Fixed by #489

Comments

@lePereT
Copy link

lePereT commented May 3, 2020

Hi all, I'm getting an error from CMake in my attempt to build a recent version of luv for OpenWrt.

Essentially I'm using the makefile here: https://github.com/openwrt/packages/blob/master/lang/luv/Makefile and amending the version number and hash to 1.36 or 1.34. Whereas 1.22 builds, more recent version builds fail with this message:

CMake Error at /home/ubuntu/wrtbuilder/openwrt/staging_dir/host/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find Lua (missing: LUA_INCLUDE_DIR)
Call Stack (most recent call first):
  /home/ubuntu/wrtbuilder/openwrt/staging_dir/host/share/cmake-3.11/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  /home/ubuntu/wrtbuilder/openwrt/staging_dir/host/share/cmake-3.11/Modules/FindLua.cmake:193 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:111 (find_package)

Is there something basic that I'm doing wrong? Or has something changed between 1.22 and 1.34+ that I need to incorporate. Libuv appears to building fine.

Thanks!

@squeek502
Copy link
Member

squeek502 commented May 3, 2020

The find_package(Lua) changed to use REQUIRED in 1a70120

This might have been a mistake, since presumably it's failing to find the libraries, not the headers, and we only actually link against the libraries on Windows. So, the REQUIRED should probably be removed for find_package(Lua) on non-Windows.

@lePereT
Copy link
Author

lePereT commented May 4, 2020

Thanks for this squeek502. I've tried rebuilding with your patch applied atop 1.36.0 and voila, a slightly different error:

-- Could NOT find Lua (missing: LUA_INCLUDE_DIR)
CMake Error at CMakeLists.txt:128 (message):
  Failed to find Lua headers.  Variable `LUA_INCLUDE_DIR' expected to be
  defined.

(Using Ubuntu 18.04 x64 to build with lua 5.1 and libdevellua 5.1 and luarocks all installed)

@squeek502
Copy link
Member

Could you try the following patch:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 357d7f6..9b7ff1d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -112,9 +112,6 @@ else (LUA)
       else()
         find_package(LuaJIT)
       endif()
-      if(NOT LUAJIT_INCLUDE_DIR)
-        message( FATAL_ERROR "Failed to find LuaJIT headers. Variable `LUAJIT_INCLUDE_DIR' expected to be defined.")
-      endif()
       include_directories(${LUAJIT_INCLUDE_DIR})
     else (USE_LUAJIT)
       # We only link the libs on Windows, so find_package fully succeeding
@@ -124,9 +121,6 @@ else (LUA)
       else()
         find_package(Lua)
       endif()
-      if(NOT LUA_INCLUDE_DIR)
-        message( FATAL_ERROR "Failed to find Lua headers. Variable `LUA_INCLUDE_DIR' expected to be defined.")
-      endif()
       include_directories(${LUA_INCLUDE_DIR})
     endif (USE_LUAJIT)

I expect it to fail to find the headers at compile time, but if it doesn't, then that's worth knowing, as it means something stranger is going on.

@lePereT
Copy link
Author

lePereT commented May 4, 2020

as you suspected, it fails to find the headers:

/home/ubuntu/wrtbuilder/openwrt/build_dir/target-mips_24kc_musl/luv-1.36.0-0-rt1/src/luv.c:20:10: fatal error: compat-5.3.h: No such file or directory
 #include "compat-5.3.h"

so i'm glad those checks are working! am i missing an obvious package?

$ apt list --installed | grep lua

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

liblua5.1-0/bionic,now 5.1.5-8.1build2 amd64 [installed]
liblua5.1-0-dbg/bionic,now 5.1.5-8.1build2 amd64 [installed]
liblua5.1-0-dev/bionic,now 5.1.5-8.1build2 amd64 [installed]
liblua5.2-0/bionic,now 5.2.4-1.1build1 amd64 [installed,automatic]
liblua5.3-0/bionic-updates,bionic-security,now 5.3.3-1ubuntu0.18.04.1 amd64 [installed,automatic]
liblua5.3-dev/bionic-updates,bionic-security,now 5.3.3-1ubuntu0.18.04.1 amd64 [installed]
lua-any/bionic,now 24 all [installed,automatic]
lua-compat53/bionic,now 0.3-3 amd64 [installed]
lua-sec/bionic,now 0.6-4 amd64 [installed]
lua-socket/bionic,now 3.0~rc1+git+ac3201d-4 amd64 [installed,automatic]
lua5.1/bionic,now 5.1.5-8.1build2 amd64 [installed]
luarocks/bionic,now 2.4.2+dfsg-1 all [installed]

@squeek502
Copy link
Member

squeek502 commented May 4, 2020

That is not the header I expected it not to be able to find (I was expecting lua.h or some other Lua header). We provide compat-5.3.h in our release tarball, and add its directory to the include paths here:

luv/CMakeLists.txt

Lines 160 to 166 in 9054ac8

if(NOT LUA_COMPAT53_DIR)
set(LUA_COMPAT53_DIR deps/lua-compat-5.3)
endif()
if(DEFINED ENV{LUA_COMPAT53_DIR})
set(LUA_COMPAT53_DIR $ENV{LUA_COMPAT53_DIR})
endif()
include_directories(${LUA_COMPAT53_DIR}/c-api)

so I'm not really sure how its failing to find that...

@lePereT
Copy link
Author

lePereT commented May 4, 2020

I made a mistake with the packaging and lost lua-compat-5.3 my bad!

When I fixed, interestingly, the combination of your small patch on top of your pull request builds flawlessly, and leads to a working build:

root@OpenWrt:~# lua helloworld.lua 
Now quitting.
root@OpenWrt:~# 

The pull request by itself fails to build.

@squeek502
Copy link
Member

Strange, that means that CMake's FindLua.cmake is failing to find the Lua headers but your C compiler is succeeding. Do you know the path of the lua.h that is being used?

@rphillips
Copy link
Member

Does the following fix it?

  if(NOT LUA_COMPAT53_DIR)
    set(LUA_COMPAT53_DIR ${CMAKE_SOURCE_DIR}/deps/lua-compat-5.3)
  endif()

@squeek502
Copy link
Member

squeek502 commented May 11, 2020

Re-opening this because, while I think #489 is the correct fix for what I understand the problem to be, I still want to investigate what's going on here since #489 won't fix @lePereT's problem without the patch in #488 (comment), but that patch shouldn't be necessary. I want to try to understand how CMake can fail to find the Lua headers while the C compiler succeeds.

EDIT: @lePereT's could you answer this?

Do you know the path of the lua.h that is being used?

@squeek502 squeek502 reopened this May 11, 2020
@lePereT
Copy link
Author

lePereT commented May 11, 2020

Hi Squeek, could you tell me how I might do that? Simply look for lua.h on the Ubuntu build server?

@squeek502
Copy link
Member

squeek502 commented May 11, 2020

The best place to look would be the CMakeFiles/libluv.dir/depend.make generated in your CMake build directory and look for a line like CMakeFiles/libluv.dir/src/luv.c.o: /usr/include/lua5.1/lua.h.

EDIT: On second thought, the above probably won't have a lua.h since the problem is that CMake is unable to find the path to lua.h 🤔.

If you can't find that, then try:

ls -d /usr/include/*/lua.h
ls -d /usr/include/lua*
ls -d /usr/local/include/*/lua.h
ls -d /usr/local/include/lua*

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

Successfully merging a pull request may close this issue.

3 participants