LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-02-2005, 08:20 PM   #1
eucharn
LQ Newbie
 
Registered: Jun 2005
Location: Sweden
Distribution: Mandrake
Posts: 4

Rep: Reputation: 0
Angry Lua embedding issues


Yay! I'm not a hardened Linux geek yet (but I aim to become ) and I've got some experience with Lua embedding in XP but know I'm stuck! I have a simple question (I think), but first I think I would fill in some information:

Distro:
Mandrake LE2005

GCC (gcc -v):
Reading specs from /usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/specs
Configured with: ../configure --prefix=/usr --libexecdir=/usr/lib --with-slibdir=/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --enable-long-long --enable-__cxa_atexit --enable-clocale=gnu --disable-libunwind-exceptions --enable-languages=c,c++,ada,f77,objc,java --host=i586-mandrake-linux-gnu --with-system-zlib
Thread model: posix
gcc version 3.4.3 (Mandrakelinux 10.2 3.4.3-7mdk)

Kdevelop:
Version 3.1.2

Lua:
Version 5.0

The thing is when I just link to liblua.a (-llua) it's ok, but as soon as I try to link liblualib.a (-llualib) into the project I get these errors:
Code:
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `log'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `sqrt'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `dlerror'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `dlclose'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `fmod'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `cos'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `sin'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `atan2'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `dlopen'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `pow'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `log10'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `dlsym'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `exp'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `tan'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `atan'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `asin'
/usr/lib/gcc/i586-mandrake-linux-gnu/3.4.3/../../../liblualib.so: undefined reference to `acos'
The code I tried to compile:
Code:
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"

lua_State* luavm;

int main (int argc, char *argv[])
{

	luavm = lua_open();
	lua_baselibopen(luavm);
	lua_dofile(luavm, "hello.lua");
	lua_close(luavm);

	return 0;
}
When this small program starts it will load up the "hello.lua" script and execute it. This is the very basic way of lua embedding, but I can't even make that work. Pretty disturbing.. because dlopen, dlclose, exp, sqrt and all others work just fine when using them from my own code, if you get what I mean. What's going on?? I bet there is some simple thing that I've done wrong, but I'm doing the best I can to fix it - which usually ends up in total disaster....

Hmm... I guess I'm the worst kind of newbie
 
Old 07-03-2005, 12:35 AM   #2
eucharn
LQ Newbie
 
Registered: Jun 2005
Location: Sweden
Distribution: Mandrake
Posts: 4

Original Poster
Rep: Reputation: 0
Lightbulb

Worked my way around it, but it's not the easy way..

This setup works for the above posted code:

Code:
#include <dlfcn.h>

extern "C" {
	
#include "lua.h"
}


typedef int (*LUA_BASELIBOPEN)(lua_State*);	// luaopen_base (lua_baselibopen == macro)
typedef int (*LUA_DOFILE)(lua_State*, char*);	// lua_dofile

char *dlname = "liblualib.so";
char *luaname = "test.lua";

int main(int argc, char *argv[]) {
	
	void		*lualib;
	lua_State	*luavm;
	
	lualib = dlopen(dlname, RTLD_LAZY);
	luavm = lua_open();
	
	LUA_BASELIBOPEN lua_baselibopen = (LUA_BASELIBOPEN)dlsym(lualib, "luaopen_base");
	LUA_DOFILE lua_dofile = (LUA_DOFILE)dlsym(lualib, "lua_dofile");
	
	lua_baselibopen(luavm);
	lua_dofile(luavm, luaname);
	
	return 1;
}
Awful..but working. I would really like to use those static libs
 
Old 07-16-2008, 04:36 PM   #3
POW R TOC H
Member
 
Registered: Mar 2008
Location: Serbia
Distribution: Fedora
Posts: 37

Rep: Reputation: 15
I had the exact same problem
Just add these options :
-ldl -lm
and it will do just fine.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Lua - seperating a string blackman890 Programming 13 03-28-2005 10:04 AM
embedding a command for at? Xstack Linux - General 2 02-21-2005 03:42 PM
pdf and ps font embedding salahuddin_66 Linux - Software 1 09-03-2004 11:29 PM
embedding applications using qt ankitgdit Programming 1 10-26-2003 10:46 AM
Embedding konsole parthi4u Linux - Software 0 03-08-2003 12:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration