From fd671a7a4a8f018e449966a8ada5020de702d742 Mon Sep 17 00:00:00 2001
From: AlexeyAB <kikots@mail.ru>
Date: Fri, 04 Aug 2017 14:57:05 +0000
Subject: [PATCH] LIBSO=1 compile darknet.so library on Linux
---
Makefile | 26 ++++++++++++++++++++++----
src/yolo_v2_class.hpp | 8 ++++++++
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index a2a90f7..cd3bccb 100644
--- a/Makefile
+++ b/Makefile
@@ -3,12 +3,14 @@
OPENCV=0
DEBUG=0
OPENMP=0
+LIBSO=0
ARCH= -gencode arch=compute_20,code=[sm_20,sm_21] \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=[sm_50,compute_50] \
- -gencode arch=compute_52,code=[sm_52,compute_52]
+ -gencode arch=compute_52,code=[sm_52,compute_52] \
+ -gencode arch=compute_61,code=[sm_61,compute_61]
# This is what I use, uncomment if you know your arch and want to specify
# ARCH= -gencode arch=compute_52,code=compute_52
@@ -17,12 +19,18 @@
EXEC=darknet
OBJDIR=./obj/
+ifeq ($(LIBSO), 1)
+LIBNAMESO=darknet.so
+APPNAMESO=uselib
+endif
+
CC=gcc
+CPP=g++
NVCC=nvcc
OPTS=-Ofast
LDFLAGS= -lm -pthread
COMMON=
-CFLAGS=-Wall -Wfatal-errors
+CFLAGS=-Wall -Wfatal-errors
ifeq ($(DEBUG), 1)
OPTS=-O0 -g
@@ -63,7 +71,17 @@
OBJS = $(addprefix $(OBJDIR), $(OBJ))
DEPS = $(wildcard src/*.h) Makefile
-all: obj backup results $(EXEC)
+all: obj backup results $(EXEC) $(LIBNAMESO) $(APPNAMESO)
+
+ifeq ($(LIBSO), 1)
+CFLAGS+= -fPIC
+
+$(LIBNAMESO): $(OBJS)
+ $(CPP) -shared -std=c++11 -fvisibility=hidden -DYOLODLL_EXPORTS $(COMMON) $(CFLAGS) $^ -o $@ src/yolo_v2_class.cpp $(LDFLAGS)
+
+$(APPNAMESO): $(OBJS)
+ $(CPP) -std=c++11 $(COMMON) $(CFLAGS) -o $@ src/yolo_console_dll.cpp $(LDFLAGS) -L ./ -l:$(LIBNAMESO)
+endif
$(EXEC): $(OBJS)
$(CC) $(COMMON) $(CFLAGS) $^ -o $@ $(LDFLAGS)
@@ -84,5 +102,5 @@
.PHONY: clean
clean:
- rm -rf $(OBJS) $(EXEC)
+ rm -rf $(OBJS) $(EXEC) $(LIBNAMESO) $(APPNAMESO)
diff --git a/src/yolo_v2_class.hpp b/src/yolo_v2_class.hpp
index 8330dfc..9a8baa6 100644
--- a/src/yolo_v2_class.hpp
+++ b/src/yolo_v2_class.hpp
@@ -11,9 +11,17 @@
#endif // OPENCV
#ifdef YOLODLL_EXPORTS
+#if defined(_MSC_VER)
#define YOLODLL_API __declspec(dllexport)
#else
+#define YOLODLL_API __attribute__((visibility("default")))
+#endif
+#else
+#if defined(_MSC_VER)
#define YOLODLL_API __declspec(dllimport)
+#else
+#define YOLODLL_API
+#endif
#endif
struct bbox_t {
--
Gitblit v1.10.0