Bry
Bry

Reputation: 11

Symbol lookup error: undefined symbol atexit (linux/C)

I get the error Symbol lookup error: undefined symbol atexit (linux/C) when I try to run my program. atexit() should be defined in <stdlib.h>.

Is there anything I could add to the -l option when I compile it with gcc? Or anything else I could do? This is in C.

I am trying to write a shared object where I call atexit once. I also define the corresponding function like explained.

$ LD_PRELOAD=mymal.so /bin/ls 
/bin/ls: symbol lookup error: ./mymal.so: undefined symbol: atexit

I don't get a error after compilation, just when I try to execute it.

I build the shared library with the commands (source):

gcc -fPIC -c -ldl mymal.c
ld -shared -soname mymal.so.1 -o mymal.so -lc mymal.o

solved: it worked with g++ instead of gcc.

Upvotes: 1

Views: 3930

Answers (1)

ThiefMaster
ThiefMaster

Reputation: 318598

The function is called atexit, not Atexit.

Upvotes: 1

Related Questions