wsk3q

导航

使用mingw编译zeroC ICE库

使用mingw编译zeroC ICE库, 首先来说这种作法有点不明智,个人觉得作为工具库的话,boost和QT自带的功能足够强大。
而RPC库的话,选择太多了,grpc、brpc、trpc都不错。
好了,说回重点。

蚊子太多了,只简单写一下……

zeroC ICE 官方对visual studio的支持相当完美,所以用VC的话,几乎是不需要自己编译的。
而在linux下编译,makefile也支持得不错。只是这个挺复杂的makefile在mingw 环境下编译是不通过的,有一堆问题。个人的做法是自己写Makefile.

 

(1)依赖关系
ice 直接依赖 IceUtil, bzip2, 以及slice2cpp.exe 生成的一些头文件。
slice2cpp --> slice
IceSSL -->ice

slice2pp.exe 用来编译ice\slice\Ice\*.ice


(2) 大致步骤


(2.1) 编译 IceUtil, 这个小工具库挺好编译的,没什么大问题,看msbuild的做法是把它编译成静态库。这里是我的Makefile, 大致能用:
MAKEFILE      = IceUtil.Makefile
EQ            = =

CC            = gcc
CXX           = g++
DEFINES       = -DWIN32 -DMINGW_HAS_SECURE_API=1 -DICE_BUILDING_SLICE_COMPILERS -DICE_BUILDING_SRC -DICE_STATIC_LIBS -D_WIN32_WINNT=0x0601 -DWIN32_LEAN_AND_MEAN

# CFG参数
ifeq ("$(CFG)", "")
 #for debug
 DEBUG_FLAG    = -g
else
 #for release
 DEBUG_FLAG    = -O2
endif

CFLAGS        = -fno-keep-inline-dllexport $(DEBUG_FLAG) -Wall -Wextra -Wextra $(DEFINES)
CXXFLAGS      = -fno-keep-inline-dllexport $(DEBUG_FLAG) -std=gnu++11 -Wall -Wextra -Wextra -fexceptions -mthreads $(DEFINES)
INCPATH       = -I..\mingwBuild -I. -I..\include -I..\src
LIB        =        ar -rc
CHK_DIR_EXISTS= if not exist
MKDIR         = mkdir
COPY          = copy /y
COPY_FILE     = copy /y
COPY_DIR      = xcopy /s /q /y /i
INSTALL_FILE  = copy /y
INSTALL_PROGRAM = copy /y
INSTALL_DIR   = xcopy /s /q /y /i
#DEL_FILE      = del
DEL_FILE      = rm -f
DEL_DIR       = rmdir
MOVE          = move
IDC           = idc
IDL           = midl
ZIP           = zip -r -9
DEF_FILE      =
RES_FILE      =
MOVE          = move

####### Output directory

OBJECTS_DIR   = build_IceUtil

####### Files

SOURCES       = ..\src\IceUtil\ConsoleUtil.cpp \
  ..\src\IceUtil\ConvertUTF.cpp \
  ..\src\IceUtil\CtrlCHandler.cpp \
  ..\src\IceUtil\FileUtil.cpp \
  ..\src\IceUtil\InputUtil.cpp \
  ..\src\IceUtil\MutexProtocol.cpp \
  ..\src\IceUtil\Options.cpp \
  ..\src\IceUtil\OutputUtil.cpp \
  ..\src\IceUtil\Random.cpp \
  ..\src\IceUtil\RecMutex.cpp \
  ..\src\IceUtil\Shared.cpp \
  ..\src\IceUtil\StringConverter.cpp \
  ..\src\IceUtil\StringUtil.cpp \
  ..\src\IceUtil\ThreadException.cpp \
  ..\src\IceUtil\Time.cpp \
  ..\src\IceUtil\UUID.cpp \
  ..\src\IceUtil\Unicode.cpp \
  ..\src\IceUtil\UtilException.cpp
OBJECTS       = $(OBJECTS_DIR)/ConsoleUtil.o \
  $(OBJECTS_DIR)/ConvertUTF.o \
  $(OBJECTS_DIR)/CtrlCHandler.o \
  $(OBJECTS_DIR)/FileUtil.o \
  $(OBJECTS_DIR)/InputUtil.o \
  $(OBJECTS_DIR)/MutexProtocol.o \
  $(OBJECTS_DIR)/Options.o \
  $(OBJECTS_DIR)/OutputUtil.o \
  $(OBJECTS_DIR)/Random.o \
  $(OBJECTS_DIR)/RecMutex.o \
  $(OBJECTS_DIR)/Shared.o \
  $(OBJECTS_DIR)/StringConverter.o \
  $(OBJECTS_DIR)/StringUtil.o \
  $(OBJECTS_DIR)/ThreadException.o \
  $(OBJECTS_DIR)/Time.o \
  $(OBJECTS_DIR)/UUID.o \
  $(OBJECTS_DIR)/Unicode.o \
  $(OBJECTS_DIR)/UtilException.o

TARGET         = libIceUtil.a
DESTDIR_TARGET = $(OBJECTS_DIR)\libIceUtil.a

####### Build rules

first: all
all: $(MAKEFILE)  $(OBJECTS_DIR)/libIceUtil.a

$(OBJECTS_DIR)/libIceUtil.a:  $(OBJECTS)
 -$(DEL_FILE) $(DESTDIR_TARGET) 2>NUL
 ar -rc $(OBJECTS_DIR)\libIceUtil.a $(OBJECTS)

clean: compiler_clean
 -$(DEL_FILE) $(OBJECTS_DIR)\libIceUtil.a
 -$(DEL_FILE) $(OBJECTS_DIR)/*.o


####### Compile

$(OBJECTS_DIR)/ConsoleUtil.o: ../src/IceUtil/ConsoleUtil.cpp ../include/IceUtil/ConsoleUtil.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/StringConverter.h \
  ../include/IceUtil/Exception.h \
  ../include/IceUtil/Shared.h \
  ../include/IceUtil/Atomic.h \
  ../include/IceUtil/Mutex.h \
  ../include/IceUtil/Lock.h \
  ../include/IceUtil/ThreadException.h \
  ../include/IceUtil/Time.h \
  ../include/IceUtil/MutexProtocol.h \
  ../include/IceUtil/Handle.h \
  ../include/IceUtil/MutexPtrLock.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\ConsoleUtil.o ..\src\IceUtil\ConsoleUtil.cpp

$(OBJECTS_DIR)/ConvertUTF.o: ../src/IceUtil/ConvertUTF.cpp ../include/IceUtil/Config.h \
  ../src/IceUtil/ConvertUTF.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\ConvertUTF.o ..\src\IceUtil\ConvertUTF.cpp

$(OBJECTS_DIR)/CtrlCHandler.o: ../src/IceUtil/CtrlCHandler.cpp ../include/IceUtil/CtrlCHandler.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/Exception.h \
  ../include/IceUtil/MutexPtrLock.h \
  ../include/IceUtil/ThreadException.h \
  ../include/IceUtil/Time.h \
  ../include/IceUtil/Mutex.h \
  ../include/IceUtil/Lock.h \
  ../include/IceUtil/MutexProtocol.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\CtrlCHandler.o ..\src\IceUtil\CtrlCHandler.cpp

$(OBJECTS_DIR)/FileUtil.o: ../src/IceUtil/FileUtil.cpp ../include/IceUtil/DisableWarnings.h \
  ../include/IceUtil/FileUtil.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/Shared.h \
  ../include/IceUtil/Atomic.h \
  ../include/IceUtil/Mutex.h \
  ../include/IceUtil/Lock.h \
  ../include/IceUtil/ThreadException.h \
  ../include/IceUtil/Exception.h \
  ../include/IceUtil/Time.h \
  ../include/IceUtil/MutexProtocol.h \
  ../include/IceUtil/Handle.h \
  ../include/IceUtil/StringConverter.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\FileUtil.o ..\src\IceUtil\FileUtil.cpp

$(OBJECTS_DIR)/InputUtil.o: ../src/IceUtil/InputUtil.cpp ../include/IceUtil/InputUtil.h \
  ../include/IceUtil/Config.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\InputUtil.o ..\src\IceUtil\InputUtil.cpp

$(OBJECTS_DIR)/MutexProtocol.o: ../src/IceUtil/MutexProtocol.cpp ../include/IceUtil/MutexProtocol.h \
  ../include/IceUtil/Config.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\MutexProtocol.o ..\src\IceUtil\MutexProtocol.cpp

$(OBJECTS_DIR)/Options.o: ../src/IceUtil/Options.cpp ../include/IceUtil/Options.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/RecMutex.h \
  ../include/IceUtil/Lock.h \
  ../include/IceUtil/ThreadException.h \
  ../include/IceUtil/Exception.h \
  ../include/IceUtil/Time.h \
  ../include/IceUtil/MutexProtocol.h \
  ../include/IceUtil/Shared.h \
  ../include/IceUtil/Atomic.h \
  ../include/IceUtil/Mutex.h \
  ../include/IceUtil/Handle.h \
  ../include/IceUtil/StringUtil.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\Options.o ..\src\IceUtil\Options.cpp

$(OBJECTS_DIR)/OutputUtil.o: ../src/IceUtil/OutputUtil.cpp ../include/IceUtil/OutputUtil.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/FileUtil.h \
  ../include/IceUtil/Shared.h \
  ../include/IceUtil/Atomic.h \
  ../include/IceUtil/Mutex.h \
  ../include/IceUtil/Lock.h \
  ../include/IceUtil/ThreadException.h \
  ../include/IceUtil/Exception.h \
  ../include/IceUtil/Time.h \
  ../include/IceUtil/MutexProtocol.h \
  ../include/IceUtil/Handle.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\OutputUtil.o ..\src\IceUtil\OutputUtil.cpp

$(OBJECTS_DIR)/Random.o: ../src/IceUtil/Random.cpp ../include/IceUtil/Random.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/Exception.h \
  ../include/IceUtil/Mutex.h \
  ../include/IceUtil/Lock.h \
  ../include/IceUtil/ThreadException.h \
  ../include/IceUtil/Time.h \
  ../include/IceUtil/MutexProtocol.h \
  ../include/IceUtil/MutexPtrLock.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\Random.o ..\src\IceUtil\Random.cpp

$(OBJECTS_DIR)/RecMutex.o: ../src/IceUtil/RecMutex.cpp ../include/IceUtil/RecMutex.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/Lock.h \
  ../include/IceUtil/ThreadException.h \
  ../include/IceUtil/Exception.h \
  ../include/IceUtil/Time.h \
  ../include/IceUtil/MutexProtocol.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\RecMutex.o ..\src\IceUtil\RecMutex.cpp

$(OBJECTS_DIR)/Shared.o: ../src/IceUtil/Shared.cpp ../include/IceUtil/Shared.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/Atomic.h \
  ../include/IceUtil/Mutex.h \
  ../include/IceUtil/Lock.h \
  ../include/IceUtil/ThreadException.h \
  ../include/IceUtil/Exception.h \
  ../include/IceUtil/Time.h \
  ../include/IceUtil/MutexProtocol.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\Shared.o ..\src\IceUtil\Shared.cpp

$(OBJECTS_DIR)/StringConverter.o: ../src/IceUtil/StringConverter.cpp ../include/IceUtil/StringConverter.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/Exception.h \
  ../include/IceUtil/Shared.h \
  ../include/IceUtil/Atomic.h \
  ../include/IceUtil/Mutex.h \
  ../include/IceUtil/Lock.h \
  ../include/IceUtil/ThreadException.h \
  ../include/IceUtil/Time.h \
  ../include/IceUtil/MutexProtocol.h \
  ../include/IceUtil/Handle.h \
  ../include/IceUtil/MutexPtrLock.h \
  ../include/IceUtil/StringUtil.h \
  ../src/IceUtil/Unicode.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\StringConverter.o ..\src\IceUtil\StringConverter.cpp

$(OBJECTS_DIR)/StringUtil.o: ../src/IceUtil/StringUtil.cpp ../include/IceUtil/StringUtil.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/StringConverter.h \
  ../include/IceUtil/Exception.h \
  ../include/IceUtil/Shared.h \
  ../include/IceUtil/Atomic.h \
  ../include/IceUtil/Mutex.h \
  ../include/IceUtil/Lock.h \
  ../include/IceUtil/ThreadException.h \
  ../include/IceUtil/Time.h \
  ../include/IceUtil/MutexProtocol.h \
  ../include/IceUtil/Handle.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\StringUtil.o ..\src\IceUtil\StringUtil.cpp

$(OBJECTS_DIR)/ThreadException.o: ../src/IceUtil/ThreadException.cpp ../include/IceUtil/ThreadException.h \
  ../include/IceUtil/Exception.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/Time.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\ThreadException.o ..\src\IceUtil\ThreadException.cpp

$(OBJECTS_DIR)/Time.o: ../src/IceUtil/Time.cpp ../include/IceUtil/DisableWarnings.h \
  ../include/IceUtil/Exception.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/Time.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\Time.o ..\src\IceUtil\Time.cpp

$(OBJECTS_DIR)/UUID.o: ../src/IceUtil/UUID.cpp ../include/IceUtil/UUID.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/Random.h \
  ../include/IceUtil/Exception.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\UUID.o ..\src\IceUtil\UUID.cpp

$(OBJECTS_DIR)/Unicode.o: ../src/IceUtil/Unicode.cpp ../include/IceUtil/Config.h \
  ../src/IceUtil/Unicode.h \
  ../include/IceUtil/Exception.h \
  ../src/IceUtil/ConvertUTF.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\Unicode.o ..\src\IceUtil\Unicode.cpp

$(OBJECTS_DIR)/UtilException.o: ../src/IceUtil/UtilException.cpp ../include/IceUtil/Exception.h \
  ../include/IceUtil/Config.h \
  ../include/IceUtil/MutexPtrLock.h \
  ../include/IceUtil/ThreadException.h \
  ../include/IceUtil/Time.h \
  ../include/IceUtil/Mutex.h \
  ../include/IceUtil/Lock.h \
  ../include/IceUtil/MutexProtocol.h \
  ../include/IceUtil/StringUtil.h \
  ../include/IceUtil/StringConverter.h \
  ../include/IceUtil/Shared.h \
  ../include/IceUtil/Atomic.h \
  ../include/IceUtil/Handle.h
 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $(OBJECTS_DIR)\UtilException.o ..\src\IceUtil\UtilException.cpp

FORCE:

 

(2.2) bzip2库,可以使用自己的,没的放编译,准备好。


(2.3) slice2cpp.exe如果有话,就不用自己编译了。它还依赖了Slice库和IceUtil。

它的用处是处理ice\slice\Ice目录下的*.ice文件。

 

(2.4) 准备编译Ice
EventLoggerMsg.mc 需要用 windmc来处理一下,生成EventLoggerMsg.h 和 EventLoggerMsg.rc

在Ice3.7 有一些文件需要改一下:
cpp/src/Ice/Network.cpp 的inet_pton需要屏蔽:
#if defined(__MINGW32__)
#if (_WIN32_WINNT < 0x0600)
//
// Work-around for missing definitions in MinGW Windows headers
//
#   ifndef IPV6_V6ONLY
#       define IPV6_V6ONLY 27
#   endif

extern "C"
{
    WINSOCK_API_LINKAGE int WSAAPI inet_pton(INT, PCTSTR, PVOID);
}
#endif
#endif


cpp/src/IceUtil/Time.cpp 要处理一下:
    struct tm tr;
#if defined(_MSC_VER) ||defined(__MINGW32__)
    localtime_s(&tr, &time);
#else
    localtime_r(&time, &tr);
#endif


另外Ice/Process.h 可能与windows SDK的process.h冲突,需要改一下名字。

 

(2.5) 编译Ice
把Ice源码、IceUtil、bzip2、slice2cpp生成的文件凑一起编译,生成动态库即可。
本来还要一点要写,但这样蚊子太多了,忍不住了,赶紧撤。。。
[end]

 

posted on 2021-07-29 11:46  wsk3q  阅读(415)  评论(0编辑  收藏  举报