lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 27 October 2016 at 08:24, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> Compiling with this statement:
>> gcc -g -Wall -shared -fPIC example1.c luamodule.c -o example2.so
>> -I/usr/include/lua5.2 -llua5.2 -lm -ldl
>
> This is confusing. What is in example1.c?
>
> Also, I don't think you need -llua5.2 -lm -ldl.
> You may end up with a copy of the Lua runtime in example2.so.
>
> You may want to have a look at my libraries and their Makefiles:
>         http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/
>
> Look at a simple one like lbase64 or lrandom.
> You may need to add -fPIC to CFLAGS and MAKESO.

To avoid all these complications and trying to figure out which flags
are needed for which platform, you can just use LuaRocks. Create this
file example2-git-1.rockspec:

----------
--- example2-git-1.rockspec
----------
package="example2"
version="git-1"
source={ url="." } -- replace url with a real URL when you distribute the code
build = {
   type="builtin"
   modules={ example2 = { "example1.c", "luamodule.c" } }
}
----------

then type:

   luarocks make

Now your project builds nicely on Linux, *BSD, OSX, Windows (Visual
Studio, Cygwin, MinGW), etc.

-- Hisham