"Success is the sum of small efforts, repeated day in and day out." - Robert Collier   |    "Perl - The only language that looks the same before and after RSA encryption." - Keith Bostic   |    "The talent of success is nothing more than doing what you can do, well." - Henry W. Longfellow   |    "Nothing great was ever achieved without enthusiasm." - Ralph Waldo Emerson   |    "If Java had true garbage collection, most programs would delete themselves upon execution." - Robert Sewell   |    "We are still masters of our fate. We are still captains of our souls." - Winston Churchill   |    "We are what we repeatedly do. Excellence, therefore, is not an act but a habit." - Aristotle   |    Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.   |    "The more you learn, the more you need to learn." - Robert Heinlein   |    "Every artist was first an amateur." - Ralph Waldo Emerson   |    "Take calculated risks. That is quite different from being rash." - George S. Patton   |    "Nothing can stop the man with the right mental attitude from achieving his goal; nothing on earth can help the man with the wrong mental attitude." - Thomas Jefferson   |    "Good luck' follows careful preparation; 'bad luck' comes from sloppiness." - Robert Heinlein   |    "The more difficulties one has to encounter, within and without, the more significant and the higher in inspiration his life will be" - Horace Bushnell   |    "Nothing will ever be attempted if all possible objections must first be overcome." - Samuel Johnson   |    "There is no such thing as luck; there is only adequate or inadequate preparation to cope with a statistical universe." - Robert Heinlein   |    "The big secret in life is that there is no big secret. Whatever your goal, you can get there if you're willing to work." - Oprah Winfrey   |    "Our doubts are traitors, and make us lose the good we oft might win, by fearing to attempt." - William Shakespeare   |   

Code Reactor

The best of modern Web development

Compiling Tolua++ 1.0.93 without SCons (updated)

This guide is based on the http://lua-users.org/wiki/CompilingToluappWithoutScons
I just have modified some things in the Visual Studio part, because in the original, the steps didn’t work for me.

So, needless to say, most credit goes for the author of the original guide, I have just modified some stuff!

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.

The commands used are :
tolua++_1.0.5\src\lib> gcc -shared -o tolua++.dll *.c
\Lua502.dll -I..\..\include -I
– 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
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
\Lua502.dll -L..\lib\ -ltolua++
– 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
\Lua502.dll with -L
\lib -llua .

Using Visual Studio 2003

Library (.DLL/.lib)

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’. If you want to compile to a static library, choose Static Library (.lib)

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).
In more recent versions of lua there is just one library, for example “lua5.1.lib”. In that case, just include that.

Compiling the project should result in a tolua++.dll. or tolua++.lib, whichever you chose in the project settings.

Executable (.exe)

Now, to build the executable, you must first build the library. And even thou there is probably some way to do this using the .dll for of the library, it’s easier to do it with a static one. So before compiling the executable, first compile the library as a static library (not as .dll (project settings)), to get a proper .lib file.

To create tolua++.exe, open the “File->New Project” menu, select Visual C++-> Win32 -> Win32 console project. Add the files “tolua.c”, “toluabind.c” and “toluabind.h” to the project. (NOT toluabind_default.*)

Similarly to the previous step, add the lua .lib include directory (in project settings – linker – additional library directories) and the lib itself (project settings – linker – input (just write the library filename there (no path)))

If you have listened to my advice and linked the tolua++ library statically, don’t add anything in the “C/C++ -> Preprocessor” section. If you went with dll, you will probably have to add
“TOLUA_API=extern __declspec(dllimport)”

(NOTE: this is not the same line as in previous step. That one was with dllEXPORT).

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)

Update: For 1.0.93 with static linking, I didn’t have to remove anything like that. So don’t worry about this unless you get compiler errors.

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.

Codereactor update: Had no problems like this in VS2008, so maybe this is not the problem at all anymore.

You can also download the precompiled executable from here: tolua++.exe precompiled executable download.

As for the precompiled library, I advice you not to bother. Tolua++ is just a couple of c files, just include them into the sources in your project, and forget about all that library inclusion hassle.

Leave a Reply

You must be logged in to post a comment.

Your connection appears to be too slow, automatically disabling HeavyAjax (TM) for better performance...
You seem to run a browser without JavaScript support or it has been disabled. To fully experience Code Reactor please enable JavaScript. (It is not 1995 anymore :)
You seem to be using Internet Explorer. If you want to experience both Code Reactor and the rest of the web to their fullest and fastest, you are advised to download and install a real browser, like Opera, Firefox or Google Chrome.
You seem not only to use Internet Explorer, which is by far a joke when it comes to browsers, but to even use an old version of it!
If you want to experience both Code Reactor and the rest of the web to their fullest and fastest, you are STRONGLY advised to download and install a real browser, like Opera, Firefox or Google Chrome.