Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined reference to `_ftelli64' - MINGW - #193

Closed
hsmku opened this issue Jun 22, 2021 · 7 comments · Fixed by #208
Closed

undefined reference to `_ftelli64' - MINGW - #193

hsmku opened this issue Jun 22, 2021 · 7 comments · Fixed by #208
Labels
windows related to windows OS

Comments

@hsmku
Copy link

hsmku commented Jun 22, 2021

Hello,

I compile under Windows 7 64 bits and i got this undefined reference !
I already added -lws2_32 in linker options !

Please help me !!

@hsmku
Copy link
Author

hsmku commented Jun 22, 2021

I use MINGW-64 for windows with GNU GCC - when I compile for C program, it give me the undefined ref above.
And the
I already added -lws2_32 in linker options !
has nothing to do here (for socket).

I tried to lookup many time on google but I found nothing !!!

Except a hook in CXFLAGS to do -D_ftelli64=_ftello64

But _ftello64 is also an undefined reference.

@hsmku
Copy link
Author

hsmku commented Jun 23, 2021

Hello : https://fr.osdn.net/projects/mingw/ticket/38225

Legacy WINDOWS does not implement _ftelli64 till msvcr80...

Just replaced _ftelli64 and _fseeki64 by ftell and fseek in miniz.h !!

Works exactly the same !!

THANKS ! This lib is great for microdevices !!!!

@hsmku hsmku closed this as completed Jun 23, 2021
@kuba--
Copy link
Owner

kuba-- commented Jun 23, 2021

Thanks, maybe I'll try to unify some configs, in the future.

@aicarambazigalo
Copy link

This issue has been encountered in two places:
ziglang/zig#9402
and
ikskuh/ZigAndroidTemplate#5 (comment)

@kuba-- kuba-- added the windows related to windows OS label Aug 31, 2021
@kuba-- kuba-- linked a pull request Aug 31, 2021 that will close this issue
@kuba--
Copy link
Owner

kuba-- commented Aug 31, 2021

I've just sent PR: https://github.com/kuba--/zip/pull/207 (replacing _ftelli64 and _fseeko64 by ftell and fseek on for MINGW32).
Please let me know if the fix works for you.

@aicarambazigalo
Copy link

unless I'm misunderstanding something, that PR may not be right currently... as it tries to change something else (_ftello64 for example, instead of _ftelli64). I'm on Windows 7 Professional 64bit SP1.

In my particular case here's what I've changed (commented out and replaced):

//#define MZ_FTELL64 _ftelli64
//#define MZ_FSEEK64 _fseeki64
#define MZ_FTELL64 ftell
#define MZ_FSEEK64 fseek

and in context they are:

...
static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) {
  wchar_t *wPath = str2wstr(pPath);
  wchar_t *wMode = str2wstr(pMode);
  FILE *pFile = _wfreopen(wPath, wMode, pStream);

  free(wPath);
  free(wMode);

  return pFile;
}

#ifndef MINIZ_NO_TIME
#include <sys/utime.h>
#endif
#define MZ_FILE FILE
#define MZ_FOPEN mz_fopen
#define MZ_FCLOSE fclose
#define MZ_FREAD fread
#define MZ_FWRITE fwrite
//#define MZ_FTELL64 _ftelli64
//#define MZ_FSEEK64 _fseeki64
#define MZ_FTELL64 ftell
#define MZ_FSEEK64 fseek
#define MZ_FILE_STAT_STRUCT _stat
#define MZ_FILE_STAT _stat
#define MZ_FFLUSH fflush
#define MZ_FREOPEN mz_freopen
#define MZ_DELETE_FILE remove
#elif defined(__MINGW32__)
#ifndef MINIZ_NO_TIME
#include <sys/utime.h>
#endif
#define MZ_FILE FILE
#define MZ_FOPEN(f, m) mz_fopen
#define MZ_FCLOSE fclose
#define MZ_FREAD fread
#define MZ_FWRITE fwrite
#define MZ_FTELL64 ftell
#define MZ_FSEEK64 fseek
#define MZ_FILE_STAT_STRUCT _stat
#define MZ_FILE_STAT _stat
#define MZ_FFLUSH fflush
#define MZ_FREOPEN(f, m, s) mz_freopen
#define MZ_DELETE_FILE remove
#elif defined(__TINYC__)
#ifndef MINIZ_NO_TIME
#include <sys/utime.h>
#endif
#define MZ_FILE FILE
#define MZ_FOPEN(f, m) fopen(f, m)
#define MZ_FCLOSE fclose
#define MZ_FREAD fread
#define MZ_FWRITE fwrite
#define MZ_FTELL64 ftell
#define MZ_FSEEK64 fseek
#define MZ_FILE_STAT_STRUCT stat
#define MZ_FILE_STAT stat
#define MZ_FFLUSH fflush
#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
#define MZ_DELETE_FILE remove
#elif defined(__GNUC__) && _LARGEFILE64_SOURCE
#ifndef MINIZ_NO_TIME
#include <utime.h>
#endif
#define MZ_FILE FILE
#define MZ_FOPEN(f, m) fopen64(f, m)
#define MZ_FCLOSE fclose
#define MZ_FREAD fread
#define MZ_FWRITE fwrite
#define MZ_FTELL64 ftello64
#define MZ_FSEEK64 fseeko64
#define MZ_FILE_STAT_STRUCT stat64
#define MZ_FILE_STAT stat64
#define MZ_FFLUSH fflush
#define MZ_FREOPEN(p, m, s) freopen64(p, m, s)
#define MZ_DELETE_FILE remove
#else
#ifndef MINIZ_NO_TIME
#include <utime.h>
#endif
#define MZ_FILE FILE
#define MZ_FOPEN(f, m) fopen(f, m)
#define MZ_FCLOSE fclose
#define MZ_FREAD fread
#define MZ_FWRITE fwrite
#if _FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L
#define MZ_FTELL64 ftello
#define MZ_FSEEK64 fseeko
#else
#define MZ_FTELL64 ftell
#define MZ_FSEEK64 fseek
#endif
#define MZ_FILE_STAT_STRUCT stat
#define MZ_FILE_STAT stat
#define MZ_FFLUSH fflush
#define MZ_FREOPEN(f, m, s) freopen(f, m, s)
#define MZ_DELETE_FILE remove
#endif // #ifdef _MSC_VER
#endif // #ifdef MINIZ_NO_STDIO
...

@aicarambazigalo
Copy link

aicarambazigalo commented Sep 1, 2021

hmm looks like I've already had a version of miniz.h with the change in that PR from https://github.com/MasterQ32/ZigAndroidTemplate/blob/66daf5ae5c9828680e060a5a1f46b35c41537022/vendor/kuba-zip/miniz.h#L4157-L4174
(EDIT: ok that's v 1.15 that I've had, and the PR has v 2.2.0)

so then, perhaps in addition to that PR, I've had to do the aforementioned 2-line change too.

EDIT2: ok, if I use these 3 files from the PR https://github.com/kuba--/zip/tree/4e0e277b97d098f2df5da865855a39af6e2b9f7a/src
in my case, with ZigAndroidTemplate, I get the errors:

a@a-PC MINGW64 /e/zat/ZigAndroidTemplate (master)
$ time zig build
Code Generation [402/3084] std.hash_map.HashMapUnmanaged([]const u8,[]const u8,s
Code Generation [317/817] std.array_list.ArrayListAligned(std.pdb.SectionContriblld-link: error: undefined symbol: __declspec(dllimport) _fseeki64
>>> referenced by E:\zat\ZigAndroidTemplate\vendor\kuba-zip\miniz.h:5905
>>>               E:\zat\ZigAndroidTemplate\zig-cache\o\ece6ef23a8af0fc2c8e437d79690b23c\zip.obj:(mz_zip_reader_init_file_v2)
>>> referenced by E:\zat\ZigAndroidTemplate\vendor\kuba-zip\miniz.h:5875
>>>               E:\zat\ZigAndroidTemplate\zig-cache\o\ece6ef23a8af0fc2c8e437d79690b23c\zip.obj:(mz_zip_file_read_func)
>>> referenced by E:\zat\ZigAndroidTemplate\vendor\kuba-zip\miniz.h:5951
>>>               E:\zat\ZigAndroidTemplate\zig-cache\o\ece6ef23a8af0fc2c8e437d79690b23c\zip.obj:(mz_zip_reader_init_cfile)
>>> referenced 6 more times

lld-link: error: undefined symbol: __declspec(dllimport) _ftelli64
>>> referenced by E:\zat\ZigAndroidTemplate\vendor\kuba-zip\miniz.h:5910
>>>               E:\zat\ZigAndroidTemplate\zig-cache\o\ece6ef23a8af0fc2c8e437d79690b23c\zip.obj:(mz_zip_reader_init_file_v2)
>>> referenced by E:\zat\ZigAndroidTemplate\vendor\kuba-zip\miniz.h:5871
>>>               E:\zat\ZigAndroidTemplate\zig-cache\o\ece6ef23a8af0fc2c8e437d79690b23c\zip.obj:(mz_zip_file_read_func)
>>> referenced by E:\zat\ZigAndroidTemplate\vendor\kuba-zip\miniz.h:5948
>>>               E:\zat\ZigAndroidTemplate\zig-cache\o\ece6ef23a8af0fc2c8e437d79690b23c\zip.obj:(mz_zip_reader_init_cfile)
>>> referenced 5 more times
error: LLDReportedFailure
zip_add...The following command exited with error code 1:
C:\zig\zig.exe build-exe E:\zat\ZigAndroidTemplate\tools\zip_add.zig -cflags -std=c99 -fno-sanitize=undefined -- E:\zat\ZigAndroidTemplate\vendor\kuba-zip\zip.c -lc --cache-dir E:\zat\ZigAndroidTemplate\zig-cache --global-cache-dir C:\Users\a\AppData\Local\zig --name zip_add -I E:\zat\ZigAndroidTemplate\vendor\kuba-zip --enable-cache
error: the following build command failed with exit code 1:
E:\zat\ZigAndroidTemplate\zig-cache\o\51eff65f619f195d3133532edfbc5a8a\build.exe C:\zig\zig.exe E:\zat\ZigAndroidTemplate E:\zat\ZigAndroidTemplate\zig-cache C:\Users\a\AppData\Local\zig

real    0m16.039s
user    0m0.000s
sys     0m0.031s

but if I apply the change I've mentioned in prev. comment, then it works, i get another error somewhere else further, but it passes the 'zip' issue:

a@a-PC MINGW64 /e/zat/ZigAndroidTemplate (master)
$ time zig build
Code Generation [653/3084] std.io.writer.Writer(std.fs.file.File,std.os.WriteErrCode Generation [2434/3084] std.hash_map.HashMapUnmanaged([]const u8,void,std.haCode Generation [2989/3084] std.hash_map.HashMapUnmanaged([]const u8,[]const u8,Code Generation [140/817] std.io.reader.Reader(std.fs.file.File,std.os.ReadErrorerror(libc_installation): missing field: kernel32_lib_dir

error: unable to parse libc paths file at path E:\zat\ZigAndroidTemplate\zig-cache\android-libc\android-30-arm64-v8a.conf: ParseError
zig-app-template...The following command exited with error code 1:
C:\zig\zig.exe build-lib E:\zat\ZigAndroidTemplate\example\main.zig -lc -lGLESv2 -lEGL -landroid -llog -ffunction-sections --libc E:\zat\ZigAndroidTemplate\zig-cache\android-libc\android-30-arm64-v8a.conf --cache-dir E:\zat\ZigAndroidTemplate\zig-cache --global-cache-dir C:\Users\a\AppData\Local\zig --name zig-app-template -dynamic -fcompiler-rt -target aarch64-linux-android -mcpu=generic+v8a --pkg-begin android E:\zat\ZigAndroidTemplate\src\android-support.zig --pkg-begin build_options E:\zat\ZigAndroidTemplate\zig-cache\android-sdk\o\1bc404ad8ad4a58fb6197b77cb82c279cb9282b7\build_options.zig --pkg-end --pkg-end -I C:\Users\a\AppData\Local\Android\Sdk\ndk\21.1.6352462\sysroot\usr\include -I C:\Users\a\AppData\Local\Android\Sdk\ndk\21.1.6352462\sysroot\usr\include\aarch64-linux-android -L C:\Users\a\AppData\Local\Android\Sdk\ndk\21.1.6352462\platforms\android-30\arch-arm64\usr\lib -D ANDROID -fPIC --enable-cache
error: the following build command failed with exit code 1:
E:\zat\ZigAndroidTemplate\zig-cache\o\51eff65f619f195d3133532edfbc5a8a\build.exe C:\zig\zig.exe E:\zat\ZigAndroidTemplate E:\zat\ZigAndroidTemplate\zig-cache C:\Users\a\AppData\Local\zig

real    0m15.899s
user    0m0.000s
sys     0m0.046s

so this is the change on top of your PR:

diff --git a/E:/Downloads/miniz.h b/vendor/kuba-zip/miniz.h
index 7148d33..96536a2 100644
--- a/E:/Downloads/miniz.h
+++ b/vendor/kuba-zip/miniz.h
@@ -4874,8 +4874,12 @@ static int mz_mkdir(const char *pDirname) {
 #define MZ_FCLOSE fclose
 #define MZ_FREAD fread
 #define MZ_FWRITE fwrite
-#define MZ_FTELL64 _ftelli64
-#define MZ_FSEEK64 _fseeki64
+
+//#define MZ_FTELL64 _ftelli64
+//#define MZ_FSEEK64 _fseeki64
+#define MZ_FTELL64 ftell
+#define MZ_FSEEK64 fseek
+
 #define MZ_FILE_STAT_STRUCT _stat64
 #define MZ_FILE_STAT mz_stat
 #define MZ_FFLUSH fflush

EDIT3: I've just realized that in my particular case, the change from the PR (for __MINGW32__) is not hit, so it can be anything there or nothing, the only important thing is the above 2-line change, in my case.

@kuba-- kuba-- linked a pull request Sep 1, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
windows related to windows OS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants