1

I am trying to link to a .so library file from a makefile. I have three files in my project: main.cpp, shm.h, and shm.cpp. main.cpp includes the shm class. Furthermore, the shm class relies on several header files stored within the alcommon library (libalcommon.so).

My makefile is currently written as follows. My thinking is that the .so file should be a dependency for shm.o, and therefore should be included as such.

Variables
CXXFLAGS=-Wall -g
CXX = g++

#Executable
#TransformTests: TransformTests.o Transform.o
#       $(CXX) $(CXXFLAGS) -o TransformTests TransformTests.o Transform.o

#Dynamics Library Creation


#Object Targets
main.o: main.cpp shm.h
        #(CXX) $(CXXFLAGS) -c main.cpp

shm.o: shm.cpp shm.h -L../../naoqi-sdk-2.1.3.3-linux32/lib -lalcommon
        $(CXX) $(CXXFLAGS) -c shm.cpp

clean:
        rm -f *o main
        rm -f *o shm

all: shm main
Austin
  • 79
  • 1
  • 6

1 Answers1

0

You need the program itself to be a target, and this is where the .so comes in (during linking, not compilation). Something like this:

Variables
CXXFLAGS=-Wall -g
CXX = g++

#Executable
#TransformTests: TransformTests.o Transform.o
#       $(CXX) $(CXXFLAGS) -o TransformTests TransformTests.o Transform.o

#Dynamics Library Creation


#Object Targets
main.o: main.cpp shm.h
        $(CXX) $(CXXFLAGS) -c main.cpp

shm.o: shm.cpp shm.h
        $(CXX) $(CXXFLAGS) -c shm.cpp

myprog: shm.o main.o 
        $(CXX) $(CXXFLAGS) -o myprog shm.o main.o -L ../../naoqi-sdk-2.1.3.3-linux32/lib -lalcommon

clean:
        rm -f *o main
        rm -f *o shm

all: shm main
Smeeheey
  • 9,906
  • 23
  • 39
  • You may like to auto-generate header dependencies, otherwise it is error-prone. – Maxim Egorushkin May 24 '16 at 15:34
  • Ok. How do I get around the fact that I am including header files from the .so library? – Austin May 24 '16 at 15:45
  • You don't need to get around it. As long as they are visible to the compiler during compilation (with the relevant `-I` switches if necessary) it will work. – Smeeheey May 24 '16 at 15:47
  • That makes sense. Could you explain how I can use the -I switch, since I don't have the .h files? I apologize if these are trivial questions - I'm not very comfortable with makefiles. – Austin May 24 '16 at 15:58
  • Actually, I found a link that is helping to explain this - http://stackoverflow.com/questions/1176427/shared-libraries-and-h-files – Austin May 24 '16 at 16:00
  • Maxim, could you explain what is involved in auto-generating header dependencies? I was not familiar with this feature. – Austin May 25 '16 at 15:53