I have an Oracle Virtual Box installation running a Windows XP guest system on a Linux (Ubuntu) host. My intent at some point in the future is to compile C++ DLLs for a program on the XP guest system. My question is: will I have to install an IDE/C++ compiler on the XP guest system on Virtual Box, or can I install one (or use gcc++) on the Linux host? I would prefer not to have to install on the XP guest system on Virtual Box. I was thinking that maybe a cross platform compiler like Code:blocks could be used to compile on Linux and the resultant DLL put into a shared folder so that the pro开发者_StackOverflow中文版gram it was written for on the XP guest system can access it.
It depends on what this Windows program is: will it be/was it built with Visual C++? Or will it be built with GCC/Mingw32? If it's built with Visual C++, then building DLLs for it using gcc is not going to work (due to reasons like different name mangling between the compilers, as well as different standard library implementations in MS VC++ Runtime vs. libstdc++).
If you follow directions to do cross compiling for Windows on Linux via code::blocks, like in this link (link to some directions or more general instructions in their forum), you will be using mingw32, which relies on gcc and libstdc++.
Your linux distribution probably provides mingw
packages, which contain gcc/g++ et al and allow it to act as a cross-compiler for Windows. In short, you can build Windows executables (both EXE and DLL) from Linux for Windows.
You don't necessarily need an IDE (on linux) to achieve this. You could configure an IDE to use the cross compilers; you can do it from autoconf's configure script and you can do it from your own makefile. What you need are the correct include/library search paths as well as the correct binary.
Where these are located is different on a system-by-system basis. Usually, the compiler is in /usr/bin/triple-name
so for me, my actual gcc is named x86_64-redhat-linux-gcc
and my mingw binary is x86_64-pc-mingw32-gcc
for example. You'll need to use these tools specific to Windows/cross compilation rather than the built in defaults; you'll also need dlltool which is a tool for producing dll's.
精彩评论