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

GCC cannot find lua headers on Ubuntu #5179

Open
rws-git opened this issue Jun 2, 2024 · 6 comments
Open

GCC cannot find lua headers on Ubuntu #5179

rws-git opened this issue Jun 2, 2024 · 6 comments
Labels

Comments

@rws-git
Copy link

rws-git commented Jun 2, 2024

Xmake Version

v2.8.7+20240401

Operating System Version and Architecture

Ubuntu 24.04 LTS x86_64

Describe Bug

I am trying to compile a simple program inside an Ubuntu Docker container, but the compiler cannot locate Lua header files.
All necessary packages for building are installed inside the container, including lua5.1 and liblua5.1-dev. xmake is installed as instructed on the website. Here is the .Dockerfile contents. If you're not familiar with Docker, it's basically taking latest headless Ubuntu distribution as a base system and runs the commands between ALL_RUN ... ALL_RUN.

# syntax=docker/dockerfile

FROM ubuntu:latest

RUN <<ALL_RUN
add-apt-repository ppa:xmake-io/xmake
apt-get -y --no-install-recommends --no-upgrade update
apt-get -y --no-install-recommends install git ca-certificates build-essential unzip xmake
apt-get -y --no-install-recommends install lua5.1 liblua5.1-dev
apt-get -y clean
groupadd -r developer && useradd -m -g developer developer
ALL_RUN

USER developer

WORKDIR /home/developer

What I end up is a command line version of Ubuntu with xmake, gcc and lua5.1 installed.
Then I try to build this simple program:

#include <lua.hpp>
#include <iostream>

int main(int argc, char* argv[]) {
	std::cout << "Hello world" << std::endl;
	return 0;
}

I've attached the error message as a screenshot. Searching for lua.hpp gives one result in /usr/include/lua5.1/lua.hpp.
So I suspect this has something to do with the header being inside a version folder and that folder is not passed to the compiler as include directory.
Is it an xmake bug where it fails to provide proper include directories? Or is it a known Ubuntu+Lua feature, that requires special treatment? Btw, same thing happens on Debian. Am I doing something wrong here?
I'd appreciate any help.

Expected Behavior

The program is built correctly with xmake -v luatest

Project Configuration

set_xmakever("2.8.6")

add_requires("lua")

target("luatest")
    set_kind("binary")

    add_files("main.cpp")

    add_packages("lua")

Additional Information and Error Logs

Screenshot from 2024-06-02 14-42-56

@rws-git rws-git added the bug label Jun 2, 2024
@waruqi
Copy link
Member

waruqi commented Jun 3, 2024

you can disable system package. add_requires("lua", {system = false})

or open a pr to improve to find lua from system in xmake-repo.

add on_fetch or add_extsources to improve it.

https://github.com/xmake-io/xmake-repo/blob/dev/packages/l/lua/xmake.lua

@rws-git
Copy link
Author

rws-git commented Jun 3, 2024

Hi @waruqi . Thank you for your suggestions.
Disabling system package is not desirable in my case as my goal is to test code compilation using system Lua distributions.

I'd be glad to help improve xmake-repo, but I'd need some time to dive into the code.

@rws-git
Copy link
Author

rws-git commented Aug 24, 2024

@waruqi hello. I've finally returned to research this issue.
There is a number of things to consider. Some systems put all Lua headers inside version subfolder, like /usr/include/lua5.1/ on Ubuntu.
Arch and Manjaro do the same, but they additionally put lua.h, lua.hpp and some other headers of the current version to /usr/include.
Therefore Ubuntu expects that a programmer would use:
#include <lua5.1/lua.h>
And Arch/Manjaro allow using the default system one with:
#include <lua.h>

I checked how CMake handles this, and they have an extensive search through different version folders and some heuristic for choosing the most relevant one. See here: https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/FindLua.cmake#L91
This allows using #include <lua.h> on Ubuntu with CMake. CMake would take care of adding correct include directories to project.

Here's the question for Xmake. Does it sound like Xmake's responsibility to automatically provide include directories to most relevant Lua version? Say, if a developer uses add_requires("lua", {system = true})?
What if developer sets specific version for Xmake to use: add_requires("lua 5.4", {system = true})?

@waruqi
Copy link
Member

waruqi commented Aug 25, 2024

we can use pkgconfig to find it, and use pkg-config --modversion to detect version.

if on_fetch return info with version, add_requires("lua 5.4", {system = true}) will match version.

add add_extsources("pkgconfig::lua") or call package:find_package("pkgconfig::lua") in on_fetch, it will detect version if exists

and we can add more extsource for more linux os. e.g. add_extsources("pacman::lua") add_extsources("apt::lua"), it will improve to find lua too.

But we need set correct package name for different package managers. maybe lua, lua-dev, lua-devel ...

you can refer other packages in xmake-repo.

@rws-git
Copy link
Author

rws-git commented Sep 3, 2024

xmake does correctly find Lua in the system. But it doesn't add correct include directory.
xmake adds /usr/include, but what should be added is /usr/include/lua5.1.
I tried to edit the package file at .xmake/repositories/xmake-repo/packages/l/lua/xmake.lua:

  • placed add_includedirs("/usr/include/lua5.1")
  • placed package:add("includedirs", "/usr/include/lua5.1") inside on_fetch and inside on_load
    When I then build my project, these directories are not passed to gcc.

@waruqi
Copy link
Member

waruqi commented Sep 4, 2024

please do not use add_includedirs, it's only for xmake package, not system libs.

see:

add add_extsources("pkgconfig::lua") or call package:find_package("pkgconfig::lua") in on_fetch, it will detect version if exists

and we can add more extsource for more linux os. e.g. add_extsources("pacman::lua") add_extsources("apt::lua"), it will improve to find lua too.

https://github.com/xmake-io/xmake-repo/blob/6bdd1eb2268ae298fc7e30ee6bd0aec54241037d/packages/g/glib/xmake.lua#L37-L61

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

No branches or pull requests

2 participants