LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Linker problems: cannot find 'dlsym' 'dlopen' 'dlerror' 'dlclose' (http://www.linuxquestions.org/questions/programming-9/linker-problems-cannot-find-dlsym-dlopen-dlerror-dlclose-720199/)

Jarrax 04-19-2009 10:29 AM

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;
}

}

rriggs 04-19-2009 10:51 AM

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


raskin 04-19-2009 10:54 AM

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").

Jarrax 04-19-2009 10:58 AM

That did it. Thx very much guys.


All times are GMT -5. The time now is 02:51 PM.