Compiling Toluapp Without Scons

lua-users home

Compiling Tolua++ without SCons

I wanted to post this on the tolua++ site but they dont have a wiki.

The tolua++ INSTALL file lets you figure out how to compile it without SCons. Its easy enough, but I wanted to save the people the 5 ( err... 15 ) minutes they need to figure this out.

Using GCC/Mingw

I am using gcc 3.4.2, on a mingw installation. But I think this should work for most people, at least those using gcc, with minor modifications.

*First you want to cd to the directory of your tolua++ folder you downloaded and extracted.

cd <path_to_tolua++_folder>\src\lib
The commands used are :
tolua++_1.0.5\src\lib> gcc -shared -o tolua++.dll *.c <path_to_lua>\Lua502.dll -I ..\..\include -I <path_to_lua>\include
- This will create the dynamic library tolua++.dll in the src\lib directory.
tolua++_1.0.5-1\src\lib> gcc -c *.c  -I ..\..\include -I <path_to_lua>\include
tolua++_1.0.5-1\src\lib> ar rcsv libtolua++.a *.o
- This will create the static linking library in the src\lib dir.
tolua++_1.0.5\src\bin> gcc tolua.c toluabind.c -I ..\..\include -I <path_to_lua>\include -L ..\lib\ -ltolua++ -L <path_to_lua>\Lua502.dll 
- This creates the tolua++ executable in the src\bin dir, assuming the libtolua++.a was created in the src\lib dir.

Note1: If you are linking against the lua static library instead of the dynamic library, replace <path_to_lua>\Lua502.dll with -L <path_to_lua>\lib -llua .

Using Visual Studio 2003


Open the "File->New Project" menu. From the project types listbox, select "Visual C++ Projects->Win32". From the Templates listbox, select "Win32 project". For a project name, type in "tolua++".

When the wizard opens, select "Application Settings" on the right hand side. Choose "DLL" and click 'Finish'.

In the Solution Explorer right click on "source files" and select "Add->Existing Item". Browse to the location of the tolua++\src\lib directory. Highlight all .c and .h files and add them to the project. You may also optionally want to add the tolua++.h file from the include directory into the "header files" folder.

Right click on the tolua++ project in the Solution Explorer and select "Properties".

Under the "C/C++ -> General" section select the "Additional include directories" option. Navigate to the location of your Lua include files.

Under the "C/C++ -> Preprocessor" section add the following: TOLUA_API=extern __declspec(dllexport) Under the "C/C++ -> Precompiled headers" section, turn off precompiled headers. Under the "Linker -> General" section select the "additional library directories" option and navigate to the location of your Lua .lib library files. Under the "Linker -> Input" section add lua.lib and lualib.lib (assuming those are your lua libraries).

Compiling the project should result in a tolua++.dll.


To create tolua++.exe, open the "File->New Project" menu, select Visual C++-> Win32 -> Win32 console project. Add the files tolua.c and toluabind.c to the project.

You will need to add all of the relevant lua include and library directories to this project. The process is the same as above. Under the "C/C++ -> Preprocessor" section, add: TOLUA_API=extern __declspec(dllimport), ... etc ...

Note that for v1.0.92, I had to remove the TOLUA_API that appears in toluabind.c:

int TOLUA_API tolua_tolua_open (lua_State* tolua_S)
int tolua_tolua_open (lua_State* tolua_S)

Using Visual Studio 2005

The same comments as above (for vs2003) generally apply, although some minor tweaks need to be made.

Note that, due to VS' poor c99 support, 'toluabind.c' in the "EXE" build will not compile. There are many lines that look like:

... int top; top = lua_gettop(tolua_S); static unsigned char B[] = { ...

These need to be changed to:

... int top = lua_gettop(tolua_S); static unsigned char B[] = { ...

or similar.

Tested with vs2005 (no service packs) and tolua++ 1.0.91.

RecentChanges · preferences
edit · history
Last edited March 6, 2013 3:17 am GMT (diff)