LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-19-2009, 09:29 AM   #1
Jarrax
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Rep: Reputation: 1
Linker problems: cannot find 'dlsym' 'dlopen' 'dlerror' 'dlclose'


Hi everyone

I am experimenting with putting lua (5.1) into cpp and have come across a problem. When I try to load the lualibs I get linker errors. I am using my own makescript (my first so might be the problem). Have also tryed running it with "make LDFLAGS+=-ldl" and I get the same result. Would like some help if anyone know how to fix this. Thanks in advance.

The error:

jakob@jakob-laptop:~/Skrivebord/test projekt$ make
gcc -c Inventory.cpp
gcc -c Printer.cpp
gcc -c Computer.cpp
gcc -c Keyboard.cpp
gcc -c main.cpp
g++ -o main main.o Inventory.o \
Printer.o Computer.o Keyboard.o -llua
/usr/local/lib/liblua.a(loadlib.o): In function `ll_loadfunc':
loadlib.c:(.text+0xa31): undefined reference to `dlsym'
loadlib.c:(.text+0xa7c): undefined reference to `dlopen'
loadlib.c:(.text+0xa89): undefined reference to `dlerror'
loadlib.c:(.text+0xaa1): undefined reference to `dlerror'
/usr/local/lib/liblua.a(loadlib.o): In function `gctm':
loadlib.c:(.text+0x109e): undefined reference to `dlclose'
collect2: ld returned 1 exit status
make: *** [build] Error 1


Makefile:

build:
gcc -c Inventory.cpp
gcc -c Printer.cpp
gcc -c Computer.cpp
gcc -c Keyboard.cpp
gcc -c main.cpp
g++ -o main main.o Inventory.o \
Printer.o Computer.o Keyboard.o -llua

clean:
rm -rf *.o
rm -rf *~
rm -rf *.gch
rm -f main


main.cpp:

#include "Inventory.h"
#include "Stock.h"
#include "Printer.h"
#include "Computer.h"
#include "Keyboard.h"
#include <iostream>
using namespace std;

//experiment
extern "C"
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}

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

for ( int n = 1; n<argc; ++n ) {
const char* file = argv[n];

lua_State *L = lua_open();

luaL_openlibs(L);

cout << "-- Loading file: " << file << endl;

lua_close(L);
cout << endl;
}

}

Last edited by Jarrax; 04-19-2009 at 09:31 AM.
 
Old 04-19-2009, 09:51 AM   #2
rriggs
Member
 
Registered: Mar 2009
Location: Colorado, US
Distribution: Fedora 13, Fedora 14, RHEL6 Beta
Posts: 46

Rep: Reputation: 17
You need to link in the "dl" libriary (-ldl on your link line).
Code:
g++ -o main main.o Inventory.o \
Printer.o Computer.o Keyboard.o -llua -ldl
 
Old 04-19-2009, 09:54 AM   #3
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
Your Makefile doesn't try to handle LDFLAGS= parameter. So your "-ldl" is ignored. You can simply add it to "g++ -o main main.o Inventory.o Printer.o Computer.o Keyboard.o -llua" (to get "g++ -o main main.o Inventory.o Printer.o Computer.o Keyboard.o -llua -ldl").
 
Old 04-19-2009, 09:58 AM   #4
Jarrax
LQ Newbie
 
Registered: Apr 2009
Posts: 3

Original Poster
Rep: Reputation: 1
That did it. Thx very much guys.
 
  


Reply

Tags
linking, lua, programming



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 to dlopen, dlclose, dlsym and dlerror patrickdepingui Slackware 5 02-14-2010 08:55 AM
compiling wpa_supplicant - howto fix dlerror, dlsym, dlopen, dlclose errors ichrispa Linux - Software 2 07-20-2007 06:03 AM
help translating pascal's libc "dlopen , dlsym and dlclose" into c source ... alred Programming 1 04-30-2006 04:49 PM
linker error: ld: cannot find -lstdc++ ofanan Linux - Software 0 02-08-2006 12:38 PM
Linker problems daveyboy685 Programming 3 03-31-2005 05:08 PM

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

All times are GMT -5. The time now is 07:18 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