c++ - 如何测试共享对象/共享库是否已正确编译?

标签 c++ makefile shared-libraries

我有以下用于我正在编写 myCode 的多线程 C++ 包的 Makefile,它需要链接到两个现有的 C++ 库:library1library2 >。 myCode 目前由约 7 个 *.cpp 文件以及关联的头文件组成。

以下内容旨在输出共享库myCode.so,其中我包含了标志-fPIC-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;

问题:如何测试共享库是否正确创建?有没有办法确保这有效?

最佳答案

唯一真正的证据在于实践和尝试使用它。

您可以确定它可以使用 objdump 等工具编译和链接,但在您使用它之前,您不会知道它实际上做了您想要的事情。

关于c++ - 如何测试共享对象/共享库是否已正确编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47852306/

相关文章:

android - Android 库项目中的资源 ID

c++ - 为什么不鼓励使用 LD_PRELOAD?

c++ - 如何将 C++ 中的二维数组传递给 Fortran 子例程?

c++ - Qt5部署 "procedure entry point could not be located"

c++ - 在 Visual Studio 中使用/MT 标志编译 SFML

c++ - VSC throw 预期为 ')'

c - 使用 makefile 构建 xcode

c++ - Autotools:在 Makefile.am 中生成源代码和 header

c++ - ld : library not found for -lbitcoin

java - .jar 中的 .so (Eclipse)