I need to modify the below makefile to create a dll (SampleNew.dll) that will run on a 32-bit windows and 64-bit Windows environment. Maybe creating two dlls (one for 64 and one for 32) is the best approach. It needs to use SampleApi.dll (in LIBS declaration below). The below doesn’t create a valid 32 bit dll for Windows. Any ideas on how to modify the below to make it work?
CMODE=
SWIG = swig
CC = $(PREFIX)gcc
LD = $(CC)
OBJ_DIR = obj
AUTOGEN_DIR = ../src/java
PACKAGE_DIR = $(AUTOGEN_DIR)/com/test/sample
PACKAGE = com.test.sample
INCLUDES = -I$(JAVA_INCLUDE) \
-I$(SAMPLE_DIR)/include \
-I$(JDK_HOME)/include
LIB_INCLUDES = -L$(SAMPLE_DIR)/lib
LIBS = /lib/libssl.so.4 \
/lib/libcrypto.so.4 \
-lSampleApi \
-lm
DIRS = $(PACKAGE_DIR) $(DIST_DIR) $(OBJ_DIR) $(AUTOGEN_DIR)
CFLAGS = $(CMODE) -Wall -fpic $(INCLUDES) -O0 -g3
SFLAGS = -java $(INCLUDES) -package $(PACKAGE) -outdir $(PACKAGE_DIR)
LDFLAGS = -shared $(LIB_INCLUDES) $(LIBS)
OBJECTS = $(OBJ_DIR)/test_wrap.o
TARGET = $(LIB_DIR)/SampleNew.dll
all: $(DIRS) $(TARGET)
%_wrap.c: %.i
$(SWIG) $(SFLAGS) $<
$(OBJ_DIR)/%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
$(TARGET): $(OBJECTS)
$(LD) $(OBJECTS) $(LDFLAGS) -o $@
$(DIRS):
mkdir -p $@
clean:
rm -rf $(TARGET) $(PACKAGE_DIR)/* $(TARGET) $(AUTOGEN_DIR) $(OBJ_DIR)
Exception:
java.lang.UnsatisfiedLinkError c:\test\myDllFile.dll: can't load this .dll (machine code=0x101) on a IA 32-bit platform
update Makefile:
CMODE=
SWIG = swig
PREFIX=/test/mingw/mingw32/bin/i386-mingw32-
CC = $(PREFIX)gcc
LD = $(CC)
OBJ_DIR = obj
AUTOGEN_DIR = ../src/java
PACKAGE_DIR = $(AUTOGEN_DIR)/com/test/jni
PACKAGE = com.test.jni
INCLUDES = -I$(HEADER_FILES_DIR) # env var that points to a dir with all the .h files
LIB_INCLUDES = -L$(C_API_DIR)/lib # env var that points to a dir with the C libraries (dlls)
LIBS = -lMainApi \ # MainApi.dll
-lm
DIRS = $(PACKAGE_DIR) $(DIST_DIR) $(OBJ_DIR) $(AUTOGEN_DIR) # DIST_DIR is passed in
CFLAGS = $(CMODE) -Wall -fpic $(INCLUDES) -O0 -g3
SFLAGS = -java $(INCLUDES) -package $(PACKAGE) -outdir $(PACKAGE_DIR)
LDFLAGS = -shared $(LIB_INCLUDES) $(LIBS) -leay32 -lws2_32 -lrpcrt4
OBJECTS = $(OBJ_DIR)/test_wrap.o
TARGET = $(LIB_DIR)/SampleJni.dll
all: $(DIRS) $(TARGET)
%_wrap.c: %.i
$(SWIG) $(SFLAGS) $<
$(OBJ_DIR)/%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
$(TARGET): $(OBJECTS)
$(LD) $(OBJECTS) $(LDFLAGS) -o $@
$(DIRS):
mkdir -p $@
clean:
rm -rf $(TARGET) $(PACKAGE_DIR)/* $(TARGET) $(AUTOGEN_DIR) $(OBJ_DIR)
The simplest thing you can do is to build both separately. For example, defining:
Avoid
-m32, since it generates 32bit code for x86-64, which may use instructions not available in x86.