LinuxQuestions.org
Visit the LQ Articles and Editorials section
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

Tags used in this thread
Popular LQ Tags , ,

Reply
 
Thread Tools
Old 04-19-2009, 10:29 AM   #1
Jarrax
LQ Newbie
 
Registered: Apr 2009
Posts: 3
Thanked: 1
Linker problems: cannot find 'dlsym' 'dlopen' 'dlerror' 'dlclose'


[Log in to get rid of this advertisement]
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 10:31 AM..
Jarrax is offline  
Tag This Post , ,
Reply With Quote
Old 04-19-2009, 10:51 AM   #2
rriggs
Member
 
Registered: Mar 2009
Location: Colorado, US
Distribution: Fedora 10
Posts: 40
Thanked: 3
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
rriggs is offline     Reply With Quote
Old 04-19-2009, 10:54 AM   #3
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,812
Thanked: 23
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").
raskin is offline     Reply With Quote
Old 04-19-2009, 10:58 AM   #4
Jarrax
LQ Newbie
 
Registered: Apr 2009
Posts: 3
Thanked: 1

Original Poster
That did it. Thx very much guys.
Jarrax is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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


All times are GMT -5. The time now is 12:56 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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration