Skip to content

Commit 9cf022a

Browse files
authored
make : fix embdinput library and server examples building on MSYS2 (#2235)
* make : fix embdinput library and server examples building on MSYS2 * cmake : fix server example building on MSYS2
1 parent e782c9e commit 9cf022a

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

Makefile

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Define the default target now so that it is always the first target
2-
BUILD_TARGETS = main quantize quantize-stats perplexity embedding vdot train-text-from-scratch simple server libembdinput.so embd-input-test
2+
BUILD_TARGETS = main quantize quantize-stats perplexity embedding vdot train-text-from-scratch simple server embd-input-test
33

44
default: $(BUILD_TARGETS)
55

@@ -90,6 +90,28 @@ ifeq ($(UNAME_S),Haiku)
9090
CXXFLAGS += -pthread
9191
endif
9292

93+
# detect Windows
94+
ifneq ($(findstring _NT,$(UNAME_S)),)
95+
_WIN32 := 1
96+
endif
97+
98+
# library name prefix
99+
ifneq ($(_WIN32),1)
100+
LIB_PRE := lib
101+
endif
102+
103+
# Dynamic Shared Object extension
104+
ifneq ($(_WIN32),1)
105+
DSO_EXT := .so
106+
else
107+
DSO_EXT := .dll
108+
endif
109+
110+
# Windows Sockets 2 (Winsock) for network-capable apps
111+
ifeq ($(_WIN32),1)
112+
LWINSOCK2 := -lws2_32
113+
endif
114+
93115
ifdef LLAMA_GPROF
94116
CFLAGS += -pg
95117
CXXFLAGS += -pg
@@ -294,7 +316,7 @@ libllama.so: llama.o ggml.o $(OBJS)
294316
$(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
295317

296318
clean:
297-
rm -vf *.o *.so main quantize quantize-stats perplexity embedding benchmark-matmult save-load-state server simple vdot train-text-from-scratch embd-input-test build-info.h
319+
rm -vf *.o *.so *.dll main quantize quantize-stats perplexity embedding benchmark-matmult save-load-state server simple vdot train-text-from-scratch embd-input-test build-info.h
298320

299321
#
300322
# Examples
@@ -325,14 +347,14 @@ save-load-state: examples/save-load-state/save-load-state.cpp build-info.h ggml.
325347
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
326348

327349
server: examples/server/server.cpp examples/server/httplib.h examples/server/json.hpp build-info.h ggml.o llama.o common.o $(OBJS)
328-
$(CXX) $(CXXFLAGS) -Iexamples/server $(filter-out %.h,$(filter-out %.hpp,$^)) -o $@ $(LDFLAGS)
350+
$(CXX) $(CXXFLAGS) -Iexamples/server $(filter-out %.h,$(filter-out %.hpp,$^)) -o $@ $(LDFLAGS) $(LWINSOCK2)
329351

330-
libembdinput.so: examples/embd-input/embd-input.h examples/embd-input/embd-input-lib.cpp build-info.h ggml.o llama.o common.o $(OBJS)
352+
$(LIB_PRE)embdinput$(DSO_EXT): examples/embd-input/embd-input.h examples/embd-input/embd-input-lib.cpp build-info.h ggml.o llama.o common.o $(OBJS)
331353
$(CXX) --shared $(CXXFLAGS) $(filter-out %.h,$(filter-out %.hpp,$^)) -o $@ $(LDFLAGS)
332354

333355

334-
embd-input-test: libembdinput.so examples/embd-input/embd-input-test.cpp build-info.h ggml.o llama.o common.o $(OBJS)
335-
$(CXX) $(CXXFLAGS) $(filter-out %.so,$(filter-out %.h,$(filter-out %.hpp,$^))) -o $@ $(LDFLAGS) -L. -lembdinput
356+
embd-input-test: $(LIB_PRE)embdinput$(DSO_EXT) examples/embd-input/embd-input-test.cpp build-info.h ggml.o llama.o common.o $(OBJS)
357+
$(CXX) $(CXXFLAGS) $(filter-out %$(DSO_EXT),$(filter-out %.h,$(filter-out %.hpp,$^))) -o $@ $(LDFLAGS) -L. -lembdinput
336358

337359
train-text-from-scratch: examples/train-text-from-scratch/train-text-from-scratch.cpp build-info.h ggml.o llama.o $(OBJS)
338360
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)

examples/server/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ target_compile_definitions(${TARGET} PRIVATE
77
SERVER_VERBOSE=$<BOOL:${LLAMA_SERVER_VERBOSE}>
88
)
99
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
10+
if (WIN32)
11+
TARGET_LINK_LIBRARIES(${TARGET} PRIVATE ws2_32)
12+
endif()
1013
target_compile_features(${TARGET} PRIVATE cxx_std_11)
1114
if(TARGET BUILD_INFO)
1215
add_dependencies(${TARGET} BUILD_INFO)

0 commit comments

Comments
 (0)