3

I am trying to write a C program that uses dlysm, and I keep getting an undefined reference to dlysm. I think I need to set my -ldl flags but I have no idea how to do this.

I am very new to linux and setting variables. If this is what I need to do can someone help me out with the commands?

2 Answers 2

3

-l library options are used at link time.

If you compile just one source file (gcc -o program program.c), then you both compile and link in one go. Just add the -ldl.

If you compile multiple object (*.o) files, and then link them together, specify the -ldl option to the linker (ld).

See also man ld and man cc

Sign up to request clarification or add additional context in comments.

2 Comments

I get this error user@ubuntu8041:~$ gcc -Wall -g -o mymalloc mymalloc.c -ldl /usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../lib/crt1.o: In function _start': (.text+0x18): undefined reference to main' collect2: ld returned 1 exit status
This says that you didn't define a main() function; the runtime library requires a main to run your program.
1

Pass -ldl as a parameter to the compiler.

Example:

gcc myprog.c -o app -ldl

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.