我目前正在尝试为https://github.com/Mojang/leveldb-mcpe进行JNI绑定,可以在https://github.com/GoMint/leveldbjni上找到。
在linux(ubuntu 18.04)下,使用src / main / c /中的compile.sh编译项目不是问题。问题是,当我在cygwin(g ++)中使用mingw64编译同一项目时,根据选择的优化级别,会出现链接器错误。
Windows构建脚本:
#!/bin/sh
CWD=$(pwd)
# First we start by this: you NEED cygwin with installed x86_64-w64-mingw32-g++ for this to work
CXX="x86_64-w64-mingw32-g++"
# We compile with c++0x because leveldb uses it as preferred language level
CXX="$CXX -std=c++0x"
# Some shared library switches
CXX="$CXX -s -shared -fPIC"
# This build should use the libc memcmp instead of the builtin one
CXX="$CXX -fno-builtin-memcmp"
# Since we use a "emulated" windows build chain we need to define that we are windows blue (10)
CXX="$CXX -D_WIN32_WINNT=0x0603"
# Now some leveldb config (telling we are windows and we want the mcpe windows hacks)
CXX="$CXX -DMCPE_PLATFORM_WINDOWS_FAMILY -DOS_WIN -DCYGWIN -DWIN32 -DNDEBUG -DDLLX="
# Some general improvements
CXX="$CXX -O2"
# Includes
CXX="$CXX -I$JAVA_HOME/include/ -I$JAVA_HOME/include/win32/ -I$CWD/leveldb-mcpe/ -I$CWD/leveldb-mcpe/include/ -v"
# We need the zlib.h in a seperate folder (because mojang added it to the wrong folder zlib/zlib.h where the normal import is simply zlib.h)
mkdir -p "$CWD/include/zlib/"
cp /usr/x86_64-w64-mingw32/sys-root/mingw/include/zlib.h "$CWD/include/zlib/zlib.h"
CXX="$CXX -I$CWD/include/"
# Verify that the built cmd is correct
echo $CXX
# Build the windows version
$CXX leveldb-mcpe/db/builder.cc leveldb-mcpe/db/c.cc\
leveldb-mcpe/db/db_impl.cc leveldb-mcpe/db/db_iter.cc\
leveldb-mcpe/db/dbformat.cc leveldb-mcpe/db/filename.cc\
leveldb-mcpe/db/log_reader.cc leveldb-mcpe/db/log_writer.cc\
leveldb-mcpe/db/memtable.cc leveldb-mcpe/db/repair.cc\
leveldb-mcpe/db/table_cache.cc leveldb-mcpe/db/version_edit.cc\
leveldb-mcpe/db/version_set.cc leveldb-mcpe/db/write_batch.cc\
leveldb-mcpe/db/snappy_compressor.cc\
leveldb-mcpe/db/zlib_compressor.cc\
leveldb-mcpe/db/zopfli_compressor.cc\
leveldb-mcpe/db/zstd_compressor.cc\
\
leveldb-mcpe/table/block.cc leveldb-mcpe/table/block_builder.cc\
leveldb-mcpe/table/filter_block.cc\
leveldb-mcpe/table/iterator.cc leveldb-mcpe/table/merger.cc\
leveldb-mcpe/table/table.cc leveldb-mcpe/table/table_builder.cc\
leveldb-mcpe/table/two_level_iterator.cc\
leveldb-mcpe/table/format.cc\
\
leveldb-mcpe/util/arena.cc leveldb-mcpe/util/bloom.cc\
leveldb-mcpe/util/cache.cc leveldb-mcpe/util/coding.cc\
leveldb-mcpe/util/comparator.cc leveldb-mcpe/util/crc32c.cc\
leveldb-mcpe/util/env.cc leveldb-mcpe/util/env_win.cc\
leveldb-mcpe/util/filter_policy.cc\
leveldb-mcpe/util/hash.cc\
leveldb-mcpe/util/histogram.cc leveldb-mcpe/util/logging.cc\
leveldb-mcpe/util/win_logger.cc leveldb-mcpe/util/options.cc\
leveldb-mcpe/util/status.cc\
\
leveldb-mcpe/port/port_win.cc leveldb-mcpe/port/port_posix_sse.cc\
\
io_gomint_leveldb_DB.cpp io_gomint_leveldb_Iterator.cpp io_gomint_leveldb_WriteBatch.cpp leveldbjni.cpp -o ../resources/leveldb-mcpe.dll -lz
哪个编译的很好,但是却给我这个链接器错误:
/tmp/ccciWZjc.o:env_win.cc:(.text+0xe6f): Warnung: undefinierter Verweis auf »std::basic_filebuf<char, std::char_traits<char> >::_close()«
/tmp/ccciWZjc.o:env_win.cc:(.text+0x1a18): Warnung: undefinierter Verweis auf »std::basic_filebuf<char, std::char_traits<char> >::_close()«
/tmp/ccciWZjc.o:env_win.cc:(.text+0x1b7c): Warnung: undefinierter Verweis auf »std::basic_filebuf<char, std::char_traits<char> >::_close()«
/tmp/ccciWZjc.o:env_win.cc:(.text+0x1da8): Warnung: undefinierter Verweis auf »std::basic_filebuf<char, std::char_traits<char> >::_close()«
/tmp/ccciWZjc.o:env_win.cc:(.text+0x1f0c): Warnung: undefinierter Verweis auf »std::basic_filebuf<char, std::char_traits<char> >::_close()«
/tmp/ccciWZjc.o:env_win.cc:(.text+0x2124): Warnung: weitere undefinierte Verweise auf »std::basic_filebuf<char, std::char_traits<char> >::_close()« folgen
当我删除优化级别时,链接器会产生此错误:
/tmp/ccD8ugVG.o:env_win.cc:(.text+0xa2c): Warnung: undefinierter Verweis auf »std::basic_ofstream<char, std::char_traits<char> >::_close()«