Author Topic: Lua library linking issue  (Read 7099 times)

Offline CBradford

  • Single posting newcomer
  • *
  • Posts: 4
Lua library linking issue
« on: April 24, 2010, 03:24:24 am »
Hi, I've wasted the entire day trying to get the Lua library lua52.lib linked to my C++ project in Code Blocks.
I'm at a loss as to what is wrong. I have the .lib file in C:\MinGW\lib. I have the header cLua.h in C:\MinGW\include.
The .lib file is specified in the Link Libraries list in Build options. I (of course)  #include "cLua.h" in my project.
The directories for library and include are specified in "Search Directories" for the compiler.

Whenever I try to create a new instance of the cLua class from cLua.h
Code
cLua *pLua = new cLua;

the following error appears during the linking stage:

Code
undefined reference to `cLua::cLua()'


I'm trying to figure out what I've overlooked here. This library just refuses to link no matter what. Please help. Going insane here :P


Edit: I should note that other libraries such as SDL have linked just fine.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: Lua library linking issue
« Reply #1 on: April 24, 2010, 04:58:27 am »
The .lib extension is NOT correct for MinGW GCC/Code::Blocks Static Library.

If it is a real MinGW GCC Static Library rename it with .a extension.

Tim S.

C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline CBradford

  • Single posting newcomer
  • *
  • Posts: 4
Re: Lua library linking issue
« Reply #2 on: April 24, 2010, 06:02:15 am »
I forgot to mention I've also tried it with .a format library files as well.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: Lua library linking issue
« Reply #3 on: April 24, 2010, 07:05:02 pm »
Turn on Full Compiler Logging and post the Build Log, of a Re-Build, where someone who uses Lua can see it.
No idea, if an Lua users are on Code::Blocks.

Tim S.

http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline CBradford

  • Single posting newcomer
  • *
  • Posts: 4
Re: Lua library linking issue
« Reply #4 on: April 24, 2010, 09:11:57 pm »
Yeah this may be more a Lua issue. But im really not sure.
At this point I've tried just about everything. I even built Lua from source with the proper mingw commands in the make file. same thing.

I'm using the header file cLua.h. This inits Lua. Could this be the problem?
Is there a definitive way to test and see if a library is linking properly?

cLua.h:

Code
#ifndef __CLUA__
#define __CLUA__

struct lua_State;

#define LuaGlue extern "C" int
extern "C" {
typedef int (*LuaFunctionType)(struct lua_State *pLuaState);
};

class cLua
{
public:
cLua();
virtual ~cLua();

bool RunScript(const char *pFilename);
bool RunString(const char *pCommand);
const char *GetErrorString(void);
bool AddFunction(const char *pFunctionName, LuaFunctionType pFunction);
const char *GetStringArgument(int num, const char *pDefault=NULL);
double GetNumberArgument(int num, double dDefault=0.0);
void PushString(const char *pString);
void PushNumber(double value);

void SetErrorHandler(void(*pErrHandler)(const char *pError)) {m_pErrorHandler = pErrHandler;}

lua_State *GetScriptContext(void) {return m_pScriptContext;}

private:
lua_State *m_pScriptContext;
void(*m_pErrorHandler)(const char *pError);
};

#endif


Offline CBradford

  • Single posting newcomer
  • *
  • Posts: 4
Re: Lua library linking issue
« Reply #5 on: April 24, 2010, 09:59:15 pm »
yeah I figured out what it is. I'm using the cLua.h header which actually utilizes a custom Lua library, not the standard release one. doh. Now the hard part is getting that to work.