I made the makefile below:
CC = gcc
CCFLAGS = -Wall -L. -lall -ldl -g
LIBFLAGS = -shared -fPIC -Wall
SRC = tema4.c
PROGRAM = allocator
LIB = liball.so
LIBSRC = liballoc.c
build:
gcc -fPIC -c liballoc.c
ld -shared -soname liball.so.1 -o liball.so.1.0 -lc liballoc.o
ldconfig -v -n .
ln -sf liball.so.1 liball.so
$(CC) -o $(PROGRAM) $(SRC) $(CCFLAGS)
export LD_LIBRARY_PATH=.
run:
export LD_LIBRARY_PATH=.
./allocator
clean:
rm -f $(PROGRAM) core *~
I run the command make and then I try to run the program but it seems it cannot open shared object liball.so (no such file or directory)
I am working on ubuntu 11.10 and I have no root privileges
Try making the last part:
Alternately:
The problem is that when you have multiple lines of commands for a target, make runs each line in its own shell. So environment vars set on one line (in one shell) don’t get inherited by the shells run for other lines. The solution is to put it all on one line (so it goes to one instance of a shell), either by writing the command as a single line or use line continuations.