A few key definitions

How to implement Lua in a C ++ program? I downloaded the Lua source, placed the .c files in the src folder and the .h files in my include folder, included lua.h in my program source code (with extern "C" {}, of course), and clicked "Build" ,.

Like all the tutorials tell me to use Lua with a C ++ project.

But now I get the error "multiple definition of main" and some characters in the Lua code that cannot be resolved. I understand what the first error means (conflict, because Lua has the main, but my program also has), but how can I solve it?

Or did I understand something completely wrong regarding the implementation of Lua in a C ++ program?

+4
source share
3 answers

Make sure you do not include luac.c , lua.c and the source for any other programs that are included in Lua along with the source code. The Lua source includes several additional utilities (i.e. Luac), and most likely you just included them in the project and forgot to delete them, which resulted in more than one main .

In short, these are separate programs that you do not add to your project. If you can, just create Lua as a rule, a link to the library and include the header files as usual.

So, if you do not understand how to use Lua, you probably did it to a certain extent. It is possible to simply copy the Lua source into your code, although it is probably not recommended. What you really want to do is pull the extracted Lua source into the terminal and build it. Then (according to the Lua INSTALL document) you will need to enter make platform , where you replace the platform with whatever platform you are currently using (i.e. I would use macosx , you could use linux , refer to INSTALL , for which platforms). After that, it is up to you if you want to install it or not, but you just do make install (or sudo make install ) to do it.

After that, add the appropriate compiler linker flags to link to Lua (e.g. -llua ) or change your project settings in your editor to do roughly the same thing. However, you would like to refer to the INSTALL document provided by Lua for complete instructions on this.

+12
source

I embed Lua in my projects differently, I prefer IMO: compiled Lua as a static library.

+1
source

Just comment on the two main blocks () in Lua.c Luac.c, then click "Create" and run again.

I did this on Lua 5.3.

0
source

All Articles