ShanZhengYang
ShanZhengYang

Reputation: 17641

How do I test that a shared object/shared library has been compiled correctly?

I have the following Makefile for a multithreaded C++ package I am writing myCode, which requires linking to two existing C++ libraries, library1 and library2. myCode currently consists of ~7 *.cpp files with associated header files.

The following is meant to output the shared library myCode.so, whereby I've included the flags -fPIC and -shared:

LIBRARY1_DIR := ./library1/
LIBRARY2_DIR := ./library2/

ABS_LIBRARY1_DIR := $(realpath $(LIBRARY1_DIR))
ABS_LIBRARY2_DIR := $(realpath $(LIBRARY2_DIR))

CXX := g++
CXXFLAGS := -Wno-deprecated -Wall -O3 -fexceptions -g -Wl,-rpath,$(ABS_LIBRARY1_DIR)/lib/
INCLUDES := -I$(ABS_LIBRARY1_DIR)/include/ -I$(ABS_LIBRARY2_DIR)/ -L$(ABS_LIBRARY1_DIR)/lib/ -L$(ABS_LIBRARY2_DIR)/

all: library1 library2 myCode

.PHONY : myCode
myCode: file1.cpp file2.cpp file3.hh file3.cpp file4.hh file4.cpp file5.cpp file5.hh file6.hh file6.hh file7.cpp file7.hh
    $(CXX) $(CXXFLAGS) $(INCLUDES) file1.cpp file2.cpp -o myCode.so $(ABS_LIBRARY2_DIR)/importfile1.a -lz -ldl -llibrary1 -lpthread -fPIC -shared


.PHONY : library1
library1:
    mkdir $(ABS_LIBRARY1_DIR)/build; cd $(ABS_LIBRARY1_DIR)/build; cmake ..; make; cd ../

.PHONY : library2
library2:
    cd $(ABS_LIBRARY2_DIR); ./configure; make; cd ../

#.PHONY : clean
clean:
     rm myCode.so; rm -rf $(ABS_LIBRARY1_DIR)/build; rm -rf $(ABS_LIBRARY1_DIR)/include; rm -rf $(ABS_LIBRARY1_DIR)/lib; rm -rf $(ABS_LIBRARY1_DIR)/bin; cd $(ABS_LIBRARY2_DIR); make clean;

Question: How do I test that the shared library was created correctly? Are there ways to ensure that this works?

Upvotes: 2

Views: 1415

Answers (1)

SoronelHaetir
SoronelHaetir

Reputation: 15172

The only real proof is in the doing, attempting to use it.

You can be sure it compiled and linked okay with tools like objdump but until you use it you won't know that it actually does what you want.

Upvotes: 2

Related Questions