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

Fix: A few minor compile warnings under MinGW #7057

Merged
merged 3 commits into from Jan 17, 2019

Conversation

@LordAro
Copy link
Member

@LordAro LordAro commented Jan 13, 2019

Fixed warnings:

In file included from C:/msys64/home/LordAro/OpenTTD/src/os/windows/win32.cpp:23:
C:/msys64/home/LordAro/OpenTTD/src/fios.h:204:20: error: 'SORT_ASCENDING' conflicts with a previous declaration
  SORT_ASCENDING  = 0,
                    ^
In file included from C:/msys64/mingw64/x86_64-w64-mingw32/include/shlobj.h:124,
                 from C:/msys64/home/LordAro/OpenTTD/src/os/windows/win32.cpp:20:
C:/msys64/mingw64/x86_64-w64-mingw32/include/shobjidl.h:6411:5: note: previous declaration 'tagSORTDIRECTION SORT_ASCENDING'
     SORT_ASCENDING = 1
     ^~~~~~~~~~~~~~
In file included from C:/msys64/home/LordAro/OpenTTD/src/os/windows/win32.cpp:23:
C:/msys64/home/LordAro/OpenTTD/src/fios.h:205:20: error: 'SORT_DESCENDING' conflicts with a previous declaration
  SORT_DESCENDING = 1,
                    ^
In file included from C:/msys64/mingw64/x86_64-w64-mingw32/include/shlobj.h:124,
                 from C:/msys64/home/LordAro/OpenTTD/src/os/windows/win32.cpp:20:
C:/msys64/mingw64/x86_64-w64-mingw32/include/shobjidl.h:6410:5: note: previous declaration 'tagSORTDIRECTION SORT_DESCENDING'
     SORT_DESCENDING = -1,
     ^~~~~~~~~~~~~~~

C:/msys64/home/LordAro/OpenTTD/src/video/win32_v.cpp:744:65: warning: cast between incompatible function types from 'void (*)(HWND, UINT, UINT, DWORD)' {aka 'void (*)(HWND__*, unsigned int, unsigned int, long unsigned int)'} to 'TIMERPROC' {aka 'void (*)(HWND__*, unsigned int, long long unsigned int, long unsigned int)'} [-Wcast-function-type]
      SetTimer(hwnd, TID_POLLMOUSE, MOUSE_POLL_DELAY, (TIMERPROC)TrackMouseTimerProc);

In file included from C:/msys64/home/LordAro/OpenTTD/src/network/core/address.h:15,
                 from C:/msys64/home/LordAro/OpenTTD/src/network/core/address.cpp:16:
In function 'int OTTDgetnameinfo(const sockaddr*, socklen_t, char*, DWORD, char*, DWORD, int)',
    inlined from 'const char* NetworkAddress::GetHostname()' at C:/msys64/home/LordAro/OpenTTD/src/network/core/address.cpp:30:14:
C:/msys64/home/LordAro/OpenTTD/src/network/core/os_abstraction.h:60:9: warning: 'char* strncpy(char*, const char*, size_t)' specified bound 80 equals destination size [-Wstringop-truncation]
  strncpy(host, inet_ntoa(((const struct sockaddr_in *)sa)->sin_addr), hostlen);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

NO_SHOBJIDL_SORTDIRECTION just disables some types that we don't use anyway, strncpy change makes sure it doesn't overwrite a '\0', and TrackMouseTimerProc is a simple type signature change

Remaining warnings:

C:/msys64/home/LordAro/OpenTTD/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp: In function 'void DumpLiteral(SQObjectPtr&)':
C:/msys64/home/LordAro/OpenTTD/src/3rdparty/squirrel/squirrel/sqfuncstate.cpp:88:27: warning: format '%d' expects argument of type 'int', but argument 2 has type 'SQInteger' {aka 'long long int'} [-Wformat=]
   case OT_INTEGER: printf("{" OTTD_PRINTF64 "}",_integer(o));break;

C:/msys64/home/LordAro/OpenTTD/src/os/windows/win32.cpp: In function 'bool LoadLibraryList(void (**)(int), const char*)':
C:/msys64/home/LordAro/OpenTTD/src/os/windows/win32.cpp:74:24: warning: cast between incompatible function types from 'FARPROC' {aka 'long long int (*)()'} to 'Function' {aka 'void (*)(int)'} [-Wcast-function-type]
    *proc++ = (Function)p;
                        ^
C:/msys64/home/LordAro/OpenTTD/src/os/windows/win32.cpp: In function 'int OTTDStringCompare(const char*, const char*)':
C:/msys64/home/LordAro/OpenTTD/src/os/windows/win32.cpp:780:107: warning: cast between incompatible function types from 'FARPROC' {aka 'long long int (*)()'} to 'PFNCOMPARESTRINGEX' {aka 'int (*)(const wchar_t*, long unsigned int, const wchar_t*, int, const wchar_t*, int, void*, void*, long long int)'} [-Wcast-function-type]
   _CompareStringEx = (PFNCOMPARESTRINGEX)GetProcAddress(GetModuleHandle(_T("Kernel32")), "CompareStringEx");

C:/msys64/home/LordAro/OpenTTD/src/video/win32_v.cpp: In function 'void RegisterWndClass()':
C:/msys64/home/LordAro/OpenTTD/src/video/win32_v.cpp:1032:106: warning: cast between incompatible function types from 'FARPROC' {aka 'long long int (*)()'} to 'PFNTRACKMOUSEEVENT' {aka 'int (*)(tagTRACKMOUSEEVENT*)'} [-Wcast-function-type]
   _pTrackMouseEvent = (PFNTRACKMOUSEEVENT)GetProcAddress(GetModuleHandle(_T("User32")), "TrackMouseEvent");

The printf related warning is very weird, as it doesn't trigger on any other code that uses it, and it should work. I did find https://sourceforge.net/p/mingw-w64/mailman/message/29704782/
FARPROC related warnings don't look solvable, due to GetProcAddress return type.

Still having to compile with freetype explicitly disabled, due to:

[SRC] Linking openttd.exe
C:/msys64/mingw64/lib\libharfbuzz.a(libharfbuzz_la-hb-directwrite.o):(.text+0x0): multiple definition of `operator new(unsigned long long)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.1\libstdc++.a(new_op.o):(.text$_Znwy+0x0): first defined here
C:/msys64/mingw64/lib\libharfbuzz.a(libharfbuzz_la-hb-directwrite.o):(.text+0x10): multiple definition of `operator new[](unsigned long long)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.1\libstdc++.a(new_opv.o):(.text$_Znay+0x0): first defined here
C:/msys64/mingw64/lib\libharfbuzz.a(libharfbuzz_la-hb-directwrite.o):(.text+0x20): multiple definition of `operator delete(void*)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.1\libstdc++.a(del_op.o):(.text$_ZdlPv+0x0): first defined here
C:/msys64/mingw64/lib\libharfbuzz.a(libharfbuzz_la-hb-directwrite.o):(.text+0x30): multiple definition of `operator delete[](void*)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.1\libstdc++.a(del_opv.o):(.text$_ZdaPv+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
@LordAro LordAro requested a review from glx22 Jan 13, 2019
@LordAro LordAro force-pushed the mingw-build-fix branch from 2dc2ed1 to 8e80930 Jan 13, 2019
src/video/win32_v.cpp Show resolved Hide resolved
@LordAro LordAro force-pushed the mingw-build-fix branch from 8e80930 to 9d3f6c5 Jan 15, 2019
@glx22
Copy link
Contributor

@glx22 glx22 commented Jan 16, 2019

To build with freetype we just have to move -lstdc++ addition to LIBS from config.lib:1512 to just before config.lib:1938 so it's after libharfbuzz.a

Removing -lstdc++ works too

glx22
glx22 approved these changes Jan 16, 2019
Copy link
Contributor

@glx22 glx22 left a comment

We probably can't do much about the printf warnings

@LordAro LordAro merged commit 6535abb into OpenTTD:master Jan 17, 2019
1 check passed
@LordAro LordAro deleted the mingw-build-fix branch Jan 17, 2019
@joestringer
Copy link
Contributor

@joestringer joestringer commented Oct 5, 2019

@LordAro did the __MINGW32__ && __CYGWIN__ case in src/network/core/os_abstraction.h cause compilation errors or warnings for your build environment? I found that I had to revert that change to cross-compile here using --host=x86_64-w64-mingw32 in a cygwin environment.

@LordAro
Copy link
Member Author

@LordAro LordAro commented Oct 5, 2019

I don't fully remember, but I don't believe so. I think I just assumed that it was a holdover from MSYS1 days. Feel free to open a PR to put it back (with a comment in the code explaining why it's necessary!)

@joestringer
Copy link
Contributor

@joestringer joestringer commented Oct 6, 2019

I'll see what the narrowest necessary change is and post a PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants