Why is Lua messing up my linkage to the CRT libraries

Started by
6 comments, last by Drakkcon 17 years, 9 months ago
Here is my simple C++ program:

#include "lua.hpp"

int main(int argc, char** argv)
{
    using namespace std;
    
    lua_State* VM = lua_open();
}



Here are my errors:

C:/Dev-Cpp/lib/liblua5.1.a(lauxlib.o)(.text+0x12a4):lauxlib.c: undefined reference to `__errno'

C:/Dev-Cpp/lib/liblua5.1.a(lauxlib.o)(.text+0x13e8):lauxlib.c: undefined reference to `__getreent'
C:/Dev-Cpp/lib/liblua5.1.a(lauxlib.o)(.text+0x14b8):lauxlib.c: undefined reference to `__getreent'
C:/Dev-Cpp/lib/liblua5.1.a(lauxlib.o)(.text+0x151e):lauxlib.c: undefined reference to `__getreent'
C:/Dev-Cpp/lib/liblua5.1.a(lauxlib.o)(.text+0x1654):lauxlib.c: undefined reference to `__getreent'
C:/Dev-Cpp/lib/liblua5.1.a(lobject.o)(.text+0x13a):lobject.c: undefined reference to `_imp___ctype_'
C:/Dev-Cpp/lib/liblua5.1.a(ldo.o)(.text+0xdf):ldo.c: undefined reference to `setjmp'
C:/Dev-Cpp/lib/liblua5.1.a(llex.o)(.text+0x65):llex.c: undefined reference to `_imp___ctype_'
C:/Dev-Cpp/lib/liblua5.1.a(llex.o)(.text+0x4f5):llex.c: undefined reference to `_imp___ctype_'
C:/Dev-Cpp/lib/liblua5.1.a(llex.o)(.text+0x51c):llex.c: undefined reference to `_imp___ctype_'
C:/Dev-Cpp/lib/liblua5.1.a(llex.o)(.text+0x555):llex.c: undefined reference to `_imp___ctype_'
C:/Dev-Cpp/lib/liblua5.1.a(llex.o)(.text+0x961):llex.c: undefined reference to `_imp___ctype_'
C:/Dev-Cpp/lib/liblua5.1.a(llex.o)(.text+0xb5b):llex.c: more undefined references to `_imp___ctype_' follow


It's like the C runtimes aren't being linked or something. Can anyone help? PS: (It works normally, but when I include lua it gives the above errors)
Advertisement
I don't know about lua.hpp, but lua.h needs to wrapped in an extern "C" block when you include it in a C++ spurce file, like so:
extern "C" {#include <lua.h>}
Are those linker errors? I know nothing about Dev-Cpp...
It is wrapped, that's what lua.hpp does. It's just that block of code.

Yes, those are linker errors. Undefined reference ones which means that the library isn't being included at all.
Check all the library includes and make sure it is linking the library.

Try

int main()
{
printf("Hello World!\n");
}

And see if that links
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
It works. It's only a problem when I include lua.
It looks like you haven't included a library in the linker. You can set that in your project options.
I told it to link the standard library. I have no idea why including lua.hpp causes it to not work.
Crap. I found the problem, I was using the gcc version of the Lua library instead of the MinGw version. It compiles now. I feel really dumb [grin].

This topic is closed to new replies.

Advertisement