[英]Linking dynamic library to my project
After reading lots of post I am really confused. 看了很多文章后,我真的很困惑。 I want to link a dynamic library to my cpp code.
我想将动态库链接到我的cpp代码。
The library is in /usr/local/include/sbml
and the libsbml.so file can be found in /usr/local/lib
该库位于
/usr/local/include/sbml
,而libsbml.so文件位于/usr/local/lib
I have a makefile that looks like this 我有一个看起来像这样的makefile
SHELL = /bin/sh
VERSION = 5.04.02
CC = /usr/bin/g++
CFLAGS = -Wall -g -D_REENTRANT -DVERSION=\"$(VERSION)\"
LDFLAGS = -lsbml
OBJ = main.o SBML.o
prog: $(OBJ)
$(CC) $(CFLAGS) -o prog $(OBJ) $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) -c $<
.PHONY : clean
clean :
-rm edit $(OBJ)
If I run the makefile I get the following error: (undefined reference to SBMLReader::readSBMLFromFile()) 如果运行生成文件,则会出现以下错误:(对SBMLReader :: readSBMLFromFile()的未定义引用)
g++ -c -o SBML.o SBML.cpp
/usr/bin/g++ -Wall -g -D_REENTRANT -DVERSION=\"5.04.02\" -o prog main.o SBML.o -lsbml
sbml.o: In Funktion `SBML::readSBML()':
sbml.cpp:(.text+0x129): Nicht definierter Verweis auf `SBMLReader::readSBMLFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
collect2: error: ld returned 1 exit status
The library was not linked because you need to specify the folder containing the so-file as well: 未链接库,因为您还需要指定包含so-文件的文件夹:
LDFLAGS = -L/usr/local/lib -lsbml
Now it should link and your unresolved symbol should be gone as well. 现在它应该链接,您未解析的符号也应该消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.