1.使用makefile编译一个动态库lib_darknet.so,然后把lib_darknet.so与yolo.o打包成一个pps_demo的应用程序,其中yolo.o是由yolo.c编译得来,yolo.c里有main函数。
2.所有编译,makefile没有问题报出,编译成功,且可执行程序与库都已生成。程序跑起来出现段错误,错误信息
[1] 31863 segmentation default ./pps_demo
3.使用gdb调试,进入main函数第一行就挂掉,出现段错误,main函数代码如下
void main(int argc, char **argv)
{
int i;
float thresh = find_float_arg(argc, argv, -"thresh", .2);
int cam_index = find_int_arg(argc, argv, -"c", 0);
char *type = find_char_arg(argc, argv, "-type", "image");
int save_video = find_int_arg(argc, argv, "-save", 0);
int pad_type = find_int_arg(argc, argv, "-pad", 0);
char *cfg, *weights, *filename;
for(i = 0; i < test_classes; ++i)
{
char buff[256];
sprintf(buff, "./labels/%s.png", voc_names[i]);
}
printf("please choose padding type:\n"
"\t0:pad_none\n"
"\t1:pad_topbot\n"
"\t2:pad_bottom\n"
"\t3:pad_top\n");
if (argc < 4){
fprintf(stderr, "usage: %s %s [train/test/valid] [cfg] [weights (optional)] \n",
argv[0], argv[1]);
return;
}
cfg = argv[3];
weights = (argc > 4) ? argv[4] : 0;
filename = argv[5];
if (0 == strcmp(argc[2] , "test"))
test_yolo(cfg, weights, filename, thresh, type, save_video, (PAD_TYPE)pad_type);
}
4. makefile如下
DEBUG=1
CC=gcc
OPENCV=1
EXTRA=
INCDIR=-I -I./lib_pendantp -I./lib_darknet -I./include/darknet
LDDIR=-L. -L/opt/intel/lib/intel64 -L/usr/lib
OPTS=-Ofast
CFLAGS=-g3 -Wall -Wfatal-errors -shared -fPIC $(EXTRA) $(INCDIR)
LDLIBS=$(LDDIR)
LDFLAGS=$(LDLIBS)
BLAS_LIBRARY=mkl
ifeq ($(DEBUG), 1)
OPTS=-O0 -g
endif
COMMON:=
ifeq ("$(BLAS_LIBRARY)", "mkl")
COMMON+=-DUSE_MKL -I/opt/intel/mkl/include
LDFLAGS+=-L/opt/intel/lib/intel64 -L/opt/intel/mkl/lib/intel64 -lmkl_core -lmkl_intel_thread -lmkl_intel_lp64 -liomp5
endif
CFLAGS+=$(OPTS) -I/usr/local/cuda/include $(COMMON)
PROGRAMS = lib_darknet.so pps_demo
MODULE1=lib_darknet
MODULE2=lib_pendantp
MODULE3=test_lib_darknet
SRCDIR1=./$(MODULE1)
SRCDIR2=./$(MODULE2)
SRCDIR3=./$(MODULE3)
OBJDIR1=./obj/$(MODULE1)
OBJDIR2=./obj/$(MODULE2)
OBJDIR3=./obj/$(MODULE3)
OBJ=activation.o avgpool.o
OBJ2=pendant_paperbox.o
DEMO_OBJ1=yolo.o
ifeq($(OPENCV), 1)
CFLAGS+=-DOPENCV
INCDIR+=-I/usr/include/opencv -I/usr/include/opencv2
LDFLAGS+=-lopencv_core -lopencv_imgproc -lopencv_highgui
endif
OBJS=$(addprefix $(OBJDIR1)/, $(OBJ))
DEMO_OBJ=$(addprefix $(OBJDIR3)/, $(DEMO_OBJ1))
all: build $(PROGRAMS)
.PHONY: build
build:
@mkdir -p obj
lib_darknet.so: $(OBJS)
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
$(OBJS): $(OBJDIR1)/%.o: $(SRCDIR1)/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
$(DEMO_OBJ): $(OBJDIR3)/%.o: $(SRCDIR3)/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
pps_demo: lib_darknet.so $(DEMO_OBJ)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
clean:
@rm -rf $(PROGRAMS) $(OBJDIR1)/*.o $(OBJDIR3)/*.o
recompile: clean all
.PHONY: check-syntax
check-syntax:
$(CC) $(CFLAGS) -Wall -Wextra -pedantic -fsyntax-only $(CHK_SOURCES)
请大家帮帮忙,不知道是哪里的问题,非常的奇怪
1 个解决方案
#1
动态库与静态库混用了?!你编的动态度,用的系统的静态度?
只是大致的揣测一下
只是大致的揣测一下
#1
动态库与静态库混用了?!你编的动态度,用的系统的静态度?
只是大致的揣测一下
只是大致的揣测一下