HighPredator
HighPredator

Reputation: 772

LD error on existing file

Good day everyone. The problem is this. I'm using a makefile to make an application. In it I have both LDFLAGS and LDLIBS (as well as others, but those 2 are relevant) specified and pointing to correct *.a files in existing folders. While trying to make an app I get the following error from LD:

0706-006 Cannot find or open library file: -l test001 ld:open(): No such file or directory

Those occur for every library in the project I try to link. The line in makefile where it occurs:

    appname: appname.o
    $(CC) -bnoquiet appname.o -o $@ $(LDFLAGS) $(LDLIBS)

where

    LDFLAGS=-L$(LIBDIR)/
    LDLIBS=-ltest001 -ltest002 -ltest003 -ltest004

Any help would be appreciated. Thanks in advance.

Upvotes: 0

Views: 626

Answers (2)

HighPredator
HighPredator

Reputation: 772

As a temporary solution I decided to pass those library files to linker as if they were object files. Like this:

    LIBS=$(LIBDIR)/test001.a $(LIBDIR)/test002.a $(LIBDIR)/test003.a $(LIBDIR)/test004.a
    ...
    $(CC) -bnoquiet appname.o -o $@ $(LIBS)

Not the greatest way of doing it I think. Although it seems in this case any solution would render the documented way (using -L and -l keys) useless. A shame.

Upvotes: 1

Klas Lindbäck
Klas Lindbäck

Reputation: 33283

The problem is the library file names.

When you link with -ltest001 the linker will look for files named libtest001.so (not test001.so).

Edit (to answer question 1 in the comments below):

Add a dependency to libtest001.so in your link step. Also add a rule to create libtest001.so. It could look something like this:

# Change /a/b/ to a directory that is present in LD_LIBRARY_PATH
MY_LIBS="/a/b/libtest001.so"

mybinary: $(MY OBJS) $(MY_LIBS)
<tab> CC ...

/a/b/libtest001.so: test001.so
<tab> ln -s test001.so /a/b/libtest001.so

Upvotes: 0

Related Questions