Author Topic: [NO BUG] linker explodes if Lua is compiled as C not C++  (Read 700 times)

jeremy_henty

  • Posts: 9
[NO BUG] linker explodes if Lua is compiled as C not C++
« on: January 13, 2010, 01:46:08 PM »
The Lua source can be compiled as either C or C++. If it is compiled as C then the Oblige build fails with a deluge of unresolved references when linking. This is because the Oblige source includes Lua headers that do not "extern C" the Lua declarations, so the linker tries to resolve C++ mangled symbol names from the Oblige object files against un-mangled symbol names from the Lua library. Hilarity ensues  :lol: ! The fix is for gui/hdr_lua.h to #include just "lua.hpp" instead of the three Lua header files that it currently #include's.

At least, that is the fix if your Lua was compiled as C rather than C++. I don't know a fix that works for <blues_brothers>both kinds</blues_brothers>. Any ideas?

starurchin

Glaice

  • Contributor
  • *****
  • Posts: 1250
  • Veteran OBLIGE modder
    • The Doom Video Vault
Re: [347] linker explodes if Lua is compiled as C instead of C++
« Reply #1 on: January 15, 2010, 04:40:45 PM »
Maybe it's meant to be compiled under C++ not C.

jeremy_henty

  • Posts: 9
Re: [347] linker explodes if Lua is compiled as C instead of C++
« Reply #2 on: January 16, 2010, 01:45:15 AM »
Quote from: "obligedoomchris"
Maybe it's meant to be compiled under C++ not C.

It's meant to be compiled as either. That's why there is a separate lua.hpp file. From the FAQ

Quote
Lua is implemented in pure ANSI C and compiles unmodified in all known platforms. All you need to build Lua is an ANSI C compiler (gcc is a popular one). Lua also compiles cleanly as C++.

I guess the configure script needs to check whether Lua was built as C or C++.

andrewj

  • Developer
  • *****
  • Posts: 1519
Re: [347] linker explodes if Lua is compiled as C instead of C++
« Reply #3 on: January 17, 2010, 05:25:15 PM »
Oblige requires Lua to be compiled as C++, as mentioned in INSTALL.txt

Using a system-wide install of Lua (e.g. apt-get install liblua50) won't work because they are compiled as C.

It is not just a symbol-name issue, the C version of Lua uses setjmp/longjmp for handling errors, but this is incompatible with C++ exception handling.  So using the C compiled version is not an option.

EDIT: the bigger problem with longjmp in C++ programs is that object destructors are not called properly, which can leave stuff in a messed up or invalid state.