1

I'm trying to add a .so library to my project, but my knowledge in makefiles are very limited, and I unfortunately don't understand the tutorial I could find...

Here is the structure of my project :

/project ex1.c ex1.h ex1_client.c ex1_client.h /lib libmylib.so 

I need to use mylib in ex1 and ex1_client, two executables, but I don't success in including it in the makefile (and I'm thinking I may not know how to include it in my .c files...)

My makefile is :

CC= gcc CFLAGS= -Wall -pedantic -std=c99 -pthread RM= rm -f LFLAGS= -L./lib LIBS= -lmylib #Don't know if the following is necessary LD_LIBRARY_PATH= ./lib all: ex1 ex1_client ex1: ex1.o $(CC) $(CFLAGS) -o ex1 ex1.o $(LFLAGS) $(LIBS) ex1_client: ex1_client.o $(CC) $(CFLAGS) -o ex1_client ex1_client.o $(LFLAGS) $(LIBS) ex1.o: ex1.c ex1.h $(CC) $(CFLAGS) -c ex1.c ex1.h ex1_client.o: ex1_client.c ex1_client.h $(CC) $(CFLAGS) -c ex1_client.c ex1_client.h clean: $(RM) *.o ex1 ex1_client *~ 

It doesn't work - seems to don't know where to find mylib, or juste don't know it has something to find.

In addition of that, I didn't write anything about mylib in my .c files... I mean no #include. Probably one of all of the problems.

Explanations about libraries and makefiles seems really hard to me to understand... and please excuse the school-learned english of a young french developper ;)

2
  • The canonical name for libraries is libXYZ.so; GCC knows this, and is expecting flags of the form -lXYZ. Commented Mar 10, 2013 at 13:52
  • So in short, your library file should be libmylib.so. Commented Mar 10, 2013 at 14:03

1 Answer 1

3

mylib.so should be libmylib.so, else the linker can't find it.

(How about having a look at the libraries already installed on your system instead of making wrong assumptions?)

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

3 Comments

Sorry, I was wrong when I copied it here : my library's name's actually "libmylib.so" (I replace its real name by "mylib", but its complete name is "libSocketTCP.so")
Could you please answer my question, now I fixed it?
@user2153863 Naturellement :) So. In first place, what does "doesn't work" mean? Is it still that the linker can't find the library?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.