NUSMV:链接库C ++

问题描述 投票:0回答:1

我正在努力将一个项目链接到一个外部项目(名为NuSMV2.6)。我不习惯大型项目和依赖问题,这是我第一次遇到这样的问题来链接另一个库。

我想将此库作为静态或更好的库,作为MyProject的动态库。NuSMV的编译为我提供了静态库(“ .a”),我将它们包含在我的“基本” Makefile中,这是它的图片:

Makefile :

CXX = g++
SRCS = $(shell find . -name "*.cpp")
OBJS = $(addsuffix .o, $(basename $(SRCS))
EXEC = bmctool
CXXFLAGS += -std=c++17 -O3 

LIBS = -L./nusmv/NuSMV/build 
-lnusmvcore -L./nusmv/NuSMV/build \
-lpthread -lz -lm -static -lboost_system


CXXFLAGS += -I/usr/local/include/code \
            -D __STDC_LIMIT_MACROS -D __STDC_FORMAT_MACROS -std=c++11 -O3
all : $(EXEC)

$(EXEC): $(OBJS) 
    @$(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS)


%.o: %.cpp 
    @$(CXX) -o $@ -c $< $(CXXFLAGS) $(LIBS)

.PHONY: clean mrproper

clean:
        @rm -f $(OBJS)

mrproper: clean
        @rm -rf $(EXEC)

这里是项目层次结构的图片:

MyProject
|
|
|------ BMCMain.cpp
|
|------ BMCFILES_THAT_USE_NUSMV_FUNCTIONS
|                    |
|                    |------ ModelCheckerTool 
|                    |             |
|                    |             |------- NuSMV.cpp
|                    |             |------- NuSMV.h 
|
|------ NuSMV-Project
|
|------ Makefile

当我运行时,编译器会识别NuSMV文件的头,但是当我想使用NuSMV函数时,它会返回:

ModelChecker/NuSMV.o : In function « NuSMV::createModel(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) » :
/home/git/bmctool/bmctool-src/ModelChecker/NuSMV.cpp:37 : underfined reference to « NuSMVCore_init_data() »
/home/git/bmctool/bmctool-src/ModelChecker/NuSMV.cpp:41 : underfined reference to « NuSMVCore_init(NuSMVEnv_TAG*, void (* (*) [2])(NuSMVEnv_TAG*), int) »
collect2: error: ld returned 1 exit status
Makefile:46: recipe for target 'bmctool' failed
make: *** [bmctool] Error 1

我试图生成动态库,以避免订购库的问题,但是没有用。

对不起,但是我希望我的解释清楚。

谢谢。

c++ static-linking dynamic-linking nusmv external-library
1个回答
0
投票

未定义的引用表示链接器无法找到该库,请在./nusmv/NuSMV/build中查找libnusmvcore。请注意相对路径,可以将其更改为绝对路径,以确保链接器在正确的位置查找。

© www.soinside.com 2019 - 2024. All rights reserved.