C++ Linking to .so file within makefile

Austin

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
Smeeheey

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Hard linking within makefile

From Dev

Hard linking within makefile

From Dev

Linking so file within android ndk

From Dev

libboost_*.so: file not recognized: File truncated When dynamically linking using libtool and automake to generate makefile

From Dev

libboost_*.so: file not recognized: File truncated When dynamically linking using libtool and automake to generate makefile

From Dev

Clang linking with a .so file

From Dev

Clang linking with a .so file

From Dev

Basic makefile/linking/library issue: No such file or directory

From Dev

Linking/using .so file in another

From Dev

What does "linker input file unused because linking not done" mean? (C makefile)

From Dev

C: Creating static library and linking using a Makefile

From Dev

c++ MakeFile linking to SQlite library

From Dev

C++ Class file linking

From Dev

C++ Class file linking

From Dev

Using "$**" to direct file input within a Makefile

From Dev

C++ Makefile doesn't compile dependencies/ linking error?

From Dev

C++ linking custom .so libraries and then with JNI

From Dev

Makefile not linking required dependency

From Dev

makefile for creating (.so) file from existing files

From Dev

linking error with c++ and mex file

From Dev

Define linking options in C++ source file

From Dev

dlclose() not unloading .so-file which is linking to boost

From Dev

Linking within a page with Bootstrap

From Dev

Linking within the page

From Dev

Makefile not linking the necessary .hpp files

From Dev

Makefile linking: undefined reference to _exit

From Dev

Makefile Linking with shared library fails

From Dev

Makefile linking issue with stacked classes

From Dev

Issue - kextload linking (Linking with .a file)

Related Related

HotTag

Archive