LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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-20-2011, 02:10 PM   #1
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Undefined reference error when using Lua API


I wrote a small test program, and this is what happens when I try to compile it:

Code:
$ g++ -llua main.cpp 
/tmp/ccHJ8HR3.o: In function `main':
main.cpp:(.text+0xc): undefined reference to `luaL_newstate()'
main.cpp:(.text+0x1c): undefined reference to `luaL_openlibs(lua_State*)'
main.cpp:(.text+0x28): undefined reference to `lua_close(lua_State*)'
collect2: ld returned 1 exit status\
I do have Lua installed, and I have liblua.a and liblua.so in /usr/lib.
 
Old 07-20-2011, 03:34 PM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2014.08, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 13,953

Rep: Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602
Arch, 64bits : ls /usr/lib/liblua*
/usr/lib/liblua.a /usr/lib/liblua.so@ /usr/lib/liblua.so.5.1*

The objects luaL_newstate luaL_openlibs lua_close are present :

readelf -s /usr/lib/liblua.so | grep luaL_newstate
134: 00000000000194f0 43 FUNC GLOBAL DEFAULT 11 luaL_newstate
554: 00000000000194f0 43 FUNC GLOBAL DEFAULT 11 luaL_newstate

etc. etc.

Are you missing 'liblua.so.5.1' ? Or is it not an "ELF 64-bit LSB shared object, x86-64" ?
( The file command and 'ls -l /usr/lib/liblua.so' will show, if it is a valid link.)

..
 
Old 07-20-2011, 03:45 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Code:
$ ls -l /usr/lib/liblua*
-rw-r--r-- 1 root root 345020 Jul 28  2010 /usr/lib/liblua.a
lrwxrwxrwx 1 root root     13 Jul 28  2010 /usr/lib/liblua.so -> liblua.so.5.1
-rwxr-xr-x 1 root root 183992 Jul 28  2010 /usr/lib/liblua.so.5.1
EDIT: Why does the "liblua.so" symlink have 777 permissions?

Last edited by MTK358; 07-20-2011 at 03:46 PM.
 
Old 07-20-2011, 04:02 PM   #4
markush
Senior Member
 
Registered: Apr 2007
Location: Germany
Distribution: Slackware
Posts: 3,971

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
Quote:
Originally Posted by MTK358 View Post
EDIT: Why does the "liblua.so" symlink have 777 permissions?
Symlinks have always 777 permissions.

Markus
 
Old 07-20-2011, 04:04 PM   #5
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2014.08, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 13,953

Rep: Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602Reputation: 2602
777 for <lib>.so links :

Never thought about it. Seems to be the same for other libraries too.
 
Old 07-20-2011, 04:35 PM   #6
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You need to place the lib after the .cpp file so it gets searched after the linker knows what dependencies the .cpp has.
Kevin Barry
 
Old 07-20-2011, 05:14 PM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Quote:
Originally Posted by ta0kira View Post
You need to place the lib after the .cpp file so it gets searched after the linker knows what dependencies the .cpp has.
If you mean this:

Code:
g++ main.cpp -llua
Then it didn't help.
 
Old 07-20-2011, 05:31 PM   #8
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by MTK358 View Post
If you mean this:

Code:
g++ main.cpp -llua
Then it didn't help.
That's what i meant.

Try wrapping the #include with extern "C" { } in case g++ is mangling the library symbols from the header.
Kevin Barry
 
1 members found this post helpful.
Old 07-20-2011, 07:14 PM   #9
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Quote:
Originally Posted by ta0kira View Post
Try wrapping the #include with extern "C" { } in case g++ is mangling the library symbols from the header.
That works!

I'm marking the thread as solved.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Undefined reference error jacques83 Programming 20 04-11-2013 07:23 AM
Undefined Reference error JMJ_coder Programming 6 03-20-2008 01:27 AM
undefined reference to error in C++ knobby67 Programming 3 01-19-2008 10:34 PM
undefined reference error bahadur Programming 5 07-25-2006 09:18 PM
undefined reference error Quest101 Programming 3 01-01-2005 12:27 PM


All times are GMT -5. The time now is 03:13 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration