1

I really have a problem which I just don't understand why it is there. I want to use LUA as a Scripting language to embed it into C++ applications.

I have downloaded the LUA-binaries (Version 5.2.3 win64 vc12; at the time of writing, the newest).

First I tried out a simple "Hello World" that Looks like this:

main.cpp:

#pragma comment(lib, "lua52")

#include <stdio.h>
#include "lua.hpp"

int main(int argc, char* argv[])
{
  printf("Hello World of c++\n");

  lua_State* L = luaL_newstate();

  luaopen_base(L);

  if (luaL_dofile(L, "test01.lua"))
  {
      printf("%s\n", lua_tostring(L, -1));
  }

  lua_close(L);

  getchar();

  return 0;
}

test01.lua:

print("Hello World of LUA\n")

As you can see it is a very simple code.

I have edited the include directories to include the Path of the header-files and I have edited the library directories to include the path to the library lua52.lib.

But for some reason I get the error: "error LNK2019..."

I hope someone knows what to do.

Thanks!

Niall
  • 30,036
  • 10
  • 99
  • 142
Zydar
  • 85
  • 1
  • 8
  • 1
    possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Cory Kramer Sep 09 '14 at 12:01
  • 2
    As you are using 64-bit library, check what your program build platform is `x64` (64-bit). If they mismatch, then you get link errors. – Rimas Sep 09 '14 at 13:08
  • 1
    @Rimas, thank you so much that was exactly what was going wrong... I never looked at the build platform (stupid me) – Zydar Sep 09 '14 at 13:16

1 Answers1

0

The "bitness" needs to correspond, the library and the target need to be built to the same target platform; so for the 64-bit library, your binary is also required to be 64-bit; the same applies for the 32-bit version(s).


You will need to link the library;

#pragma comment(lib, "lua52.lib") // note the .lib

The question was tagged as C++. Lua seems to be implemented in C, so in your C++ application (if compiled as such; which is the default), you may need to include it as;

extern "C" {
  #include "lua.hpp"
}
Niall
  • 30,036
  • 10
  • 99
  • 142
  • I really hoped it would be such a stupid mistake of mine. unfortunatelly it still doesnt work – Zydar Sep 09 '14 at 12:12
  • @Zydar, You probably have more missing libraries. What symbols is it not finding? – Niall Sep 09 '14 at 12:14
  • i thought about more missing libraries too. I just cant figure out which ones. The symbols it is not finding are: "luaL_newstate" , "luaL_loadfilex" , "luaopen_base" , "lua_pcallk" , "lua_tolstring" and "lua_close" – Zydar Sep 09 '14 at 12:35
  • Yes, that's the Content of the included lua.hpp file. – Zydar Sep 09 '14 at 12:56
  • Still the same, no changes. – Zydar Sep 09 '14 at 13:02
  • Is it possible that the LUA-binaries aren't compatible with VS2013? – Zydar Sep 09 '14 at 13:03
  • @Zydar, possible but they should still link. Are you building and linking to the correct bitness (32 vs 64 bit)? – Niall Sep 09 '14 at 13:11
  • 1
    yes that was the Problem, I was using a 32 bit build platform.. so now I included the win32 binaries of LUA and it's working now – Zydar Sep 09 '14 at 13:19
  • `extern "C" { #include "lua.hpp" }` is not needed as `extern "C"` already is in `lua.hpp` – Rimas Sep 11 '14 at 08:18