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

[Help Request] Cross-compiling windows build from Linux #26

Closed
Sanaki opened this issue Jan 13, 2020 · 8 comments
Closed

[Help Request] Cross-compiling windows build from Linux #26

Sanaki opened this issue Jan 13, 2020 · 8 comments

Comments

@Sanaki
Copy link

Sanaki commented Jan 13, 2020

Normally I avoid making this sort of issue, but I'm having no luck thus far. I'm looking to be able to compile the windows executable from Linux, but have no familiarity with mingw. Is there some easy way to accomplish this? My specific interest in this case is in making the -I flag available to Winfolk I work with on the retroachievements platform.

I have a feeling as a last resort I could use the windows mingw from within wine, but that feels extremely unnecessary.

@Alcaro
Copy link
Owner

Alcaro commented Jan 13, 2020

Windows mingw in Wine is what I do. If it looks stupid but works, it ain't stupid. I've never tried an actual cross compiler.

wine g++ *.c *.cpp -mwindows -lgdi32 -lcomdlg32 -lcomctl32 -luser32 -lkernel32 -lshell32 -ladvapi32 gives a working binary for me; not fast, and lacks icons, but those aren't really necessary for -I. Should work just as well if you replace wine g++ with i686-w64-mingw32-g++ or similar.

(If you compile as 32bit and get warnings about unsigned / unsigned long mismatch in sprintfs in flips.cpp, ignore them. size_t can't make up its mind on whether it's unsigned int or unsigned long, and if I fix it on one compiler, it'll break on others. The C integer types are weird.) edit: ignore that, turns out I was wrong on all compilers, and forgot enabling warnings so I didn't notice.

@Sanaki
Copy link
Author

Sanaki commented Jan 13, 2020

Currently it spits out no output and generates a single file named a.exe. I'll keep poking at it and post back here if I have any luck.

@Alcaro
Copy link
Owner

Alcaro commented Jan 13, 2020

Yeah, a.exe is mingw's default output filename. Rename it to flips.exe.

@Sanaki
Copy link
Author

Sanaki commented Jan 13, 2020

Sorry, I should have been more clear. That file generates errors when run via wine. Didn't get that part written.

002b:err:module:import_dll Library libgcc_s_seh-1.dll (which is needed by L"Z:\\home\\ccrowley\\src\\flips-win\\a.exe") not found
002b:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\ccrowley\\src\\flips-win\\a.exe") not found
002b:err:module:LdrInitializeThunk Importing dlls for L"Z:\\home\\ccrowley\\src\\flips-win\\a.exe" failed, status c0000135

@Alcaro
Copy link
Owner

Alcaro commented Jan 13, 2020

Yeah, mingw programs usually need those dlls. I wrote some tricky code so they're not needed with my compiler, but I'm not sure if that trick works elsewhere.

Attach your binary and I'll see if I can identify and delete them. Alternatively, you should have those dlls somewhere in your mingw installation; look them up and put them beside the exe.

@Sanaki
Copy link
Author

Sanaki commented Jan 13, 2020

Ah, you're correct. Based on which dlls were requested I was thinking it compiled some intermediate part and stopped. Symlinked those in and it's fine. That said, if you can indeed bypass needing them, that'd be better, since combined they're about 16MiB.

a.zip

@Alcaro
Copy link
Owner

Alcaro commented Jan 13, 2020

objdump -p a.exe

 000250a0	000255b4 00000000 00000000 000266c8 00025ac4

	DLL Name: libgcc_s_seh-1.dll
	vma:  Hint/Ord Member-Name Bound-To
	26378	   15  _Unwind_Resume

 000250b4	000255c4 00000000 00000000 000266ec 00025ad4

	DLL Name: libstdc++-6.dll
	vma:  Hint/Ord Member-Name Bound-To
	2638c	 4974  _ZTVN10__cxxabiv117__class_type_infoE
	263b4	 4978  _ZTVN10__cxxabiv120__si_class_type_infoE
	263e0	 5220  _ZdlPvy
	263ec	 5269  __gxx_personality_seh0

(plus a few thousand lines of uninteresting stuff)

If all uses of these functions are deleted, the DLLs will go away too.

Unwind and personality is exceptions - to get rid of that, compile with -fno-exceptions. Flips doesn't use exceptions anyways.

ZTVN is typeid and dynamic_cast. Flips doesn't need that either; to opt out, -fno-rtti.

Zdl is a C++14 thing. Fixed in latest commit, or you can use -std=c++11 or c++98. I also added a #warning recommending -fno-exceptions/no-rtti; this should avoid a few future instances of this issue.

@Sanaki
Copy link
Author

Sanaki commented Jan 13, 2020

Beautiful. Thank you. Final commands:

32-bit:
i686-w64-mingw32-g++ *.c *.cpp -mwindows -lgdi32 -lcomdlg32 -lcomctl32 -luser32 -lkernel32 -lshell32 -ladvapi32 -fno-exceptions -fno-rtti -o flips.exe

64-bit:
x86_64-w64-mingw32-g++ *.c *.cpp -mwindows -lgdi32 -lcomdlg32 -lcomctl32 -luser32 -lkernel32 -lshell32 -ladvapi32 -fno-exceptions -fno-rtti -o flips.exe

EDIT: Added the output filename and 32-bit variant just for kicks. Works like a charm.

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

No branches or pull requests

2 participants