# Using Swig and Lua

**URL:** https://discourse.cmake.org/t/using-swig-and-lua/3729
**Category:** Usage
**Tags:** os:linux, lang:swift
**Created:** [July 11, 2021, 11:21am UTC](https://discourse.cmake.org/t/using-swig-and-lua/3729 "2021-07-11T11:21:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![leventelist](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leventelist/32/1624_2.png) [@leventelist](https://discourse.cmake.org/u/leventelist)
#### Post date: [July 11, 2021, 11:21am UTC](https://discourse.cmake.org/t/using-swig-and-lua/3729/1 "2021-07-11T11:21:34Z")

</div>

I’d like to use CMake to generate my Lua wrapper. I used this before to produce python wrapper. I can generate my wrapper.c by running Everything works fine, but I don’t get my wrapper.c. I use the following code:

```auto
cmake_minimum_required (VERSION 3.1)

project(lbus_bindings)

#set prefix
if (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux")
	set (CMAKE_INSTALL_PREFIX "/usr/local")
elseif (${CMAKE_HOST_SYSTEM_NAME} STREQUAL "FreeBSD")
	set (CMAKE_INSTALL_PREFIX "/opt")
else ()
	set (CMAKE_INSTALL_PREFIX "/usr/local")
endif ()

FIND_PACKAGE(SWIG REQUIRED)

find_package(Lua 5.3)

INCLUDE(${SWIG_USE_FILE})

if (LUA_FOUND)
	include_directories("${LUA_INCLUDE_DIR}")
endif ()

#configure the compiler
set(CMAKE_C_FLAGS "-Wall -Wextra")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
set(CMAKE_C_FLAGS_RELEASE "-O2")

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
SET(CMAKE_SWIG_FLAGS "")
SWIG_ADD_LIBRARY(lbus LANGUAGE lua SOURCES lbus.i sensor_bind.c circ_buff.c lproto_l1_tty.c
serial.c lproto_debug.c lproto_l2.c debug.c lproto_sensors_common.c lib_crc.c)
SWIG_LINK_LIBRARIES(lbus ${LUA_LIBRARIES})

```

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [July 11, 2021, 12:06pm UTC](https://discourse.cmake.org/t/using-swig-and-lua/3729/2 "2021-07-11T12:06:36Z")

</div>

Your description is quite unclear…  
What is exactly the error messages?  
What is your environment (OS, CMake version, generator used, SWIG version)?

---

<div class="post-metadata">

### Author: ![leventelist](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leventelist/32/1624_2.png) [@leventelist](https://discourse.cmake.org/u/leventelist)
#### Post date: [July 11, 2021, 9:07pm UTC](https://discourse.cmake.org/t/using-swig-and-lua/3729/3 "2021-07-11T21:07:33Z")

</div>

Okay. There is no error message. If I run swig by hand like this:

swig -lua lbus.i

I get the lbus\_wrap.c file, which is what I need. However, if I run make, the file won’t generated.

It is on Debian stable,  
$ uname -a  
Linux jive 4.19.0-17-amd64 #1 SMP Debian 4.19.194-2 (2021-06-21) x86\_64 GNU/Linux  
$ swig -version

SWIG Version 3.0.12

Compiled with g++ [x86\_64-pc-linux-gnu]

Configured options: +pcre

$ cmake -version  
cmake version 3.13.4

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [July 12, 2021, 8:25am UTC](https://discourse.cmake.org/t/using-swig-and-lua/3729/4 "2021-07-12T08:25:55Z")

</div>

I am unable to reproduce your problem.

Can you show the result of `make VERBOSE=1` on a fresh `cmake` generation?
