www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Building 32bit program with MSVC?

reply "Jeremy DeHaan" <dehaan.jeremiah gmail.com> writes:
I know that we can use MSVC to build a 64 bit program, but is it 
also possible to use it to build a 32 bit program as well?
May 29 2014
next sibling parent "Remo" <remo4d gmail.com> writes:
On Thursday, 29 May 2014 at 18:25:19 UTC, Jeremy DeHaan wrote:
 I know that we can use MSVC to build a 64 bit program, but is 
 it also possible to use it to build a 32 bit program as well?
Yes of course it is possible. It you are talking about Visual-D then it is possible there too.
May 29 2014
prev sibling next sibling parent Jonathan M Davis via Digitalmars-d-learn writes:
On Thu, 29 May 2014 20:12:52 +0000
Remo via Digitalmars-d-learn <digitalmars-d-learn puremagic.com> wrote:

 On Thursday, 29 May 2014 at 18:25:19 UTC, Jeremy DeHaan wrote:
 I know that we can use MSVC to build a 64 bit program, but is
 it also possible to use it to build a 32 bit program as well?
Yes of course it is possible. It you are talking about Visual-D then it is possible there too.
If you are talking about building a 32-bit program with dmd and linking with Microsoft's linker, it's my understanding that that will not work, because dmd always produces OMF object files in 32-bit (which is what optlink uses), whereas dmd produces COFF object files in 64-bit (which is what Microsoft's linker uses). Walter went to the trouble of getting dmd to produce COFF object files to link with Microsoft's linker when he added 64-bit Windows support but did not want to go to the trouble of adding COFF support to 32-bit. - Jonathan M Davis
May 29 2014
prev sibling next sibling parent Mike Parker <aldacron gmail.com> writes:
On 5/30/2014 3:25 AM, Jeremy DeHaan wrote:
 I know that we can use MSVC to build a 64 bit program, but is it also
 possible to use it to build a 32 bit program as well?
If you mean using the MSVC toolchain with DMD, then the answer is no, not at the moment. Rainer has done some work toward this, though. I recall seeing it brought up again in a recent thread.
May 30 2014
prev sibling parent reply "Kagamin" <spam here.lot> writes:
You can try ldc, which uses mingw toolchain, it's probably 
compatible with msvc.
May 30 2014
parent reply "Jeremy DeHaan" <dehaan.jeremiah gmail.com> writes:
On Friday, 30 May 2014 at 20:48:44 UTC, Kagamin wrote:
 You can try ldc, which uses mingw toolchain, it's probably 
 compatible with msvc.
I don't necessarily need to do this, I was just wondering if it was possible. Mostly because MSVC provides a lot of import and static libraries that DMC doesn't, and MSVC is supported in a lot of major tools(such as CMake) where DMC isn't.
May 30 2014
parent reply "Kagamin" <spam here.lot> writes:
They may use different debugging formats, but just linking should 
be possible, especially with import libraries.
May 30 2014
parent reply Jonathan M Davis via Digitalmars-d-learn writes:
On Sat, 31 May 2014 06:38:46 +0000
Kagamin via Digitalmars-d-learn <digitalmars-d-learn puremagic.com>
wrote:

 They may use different debugging formats, but just linking should
 be possible, especially with import libraries.
_Dynamic_ linking is possible. Static linking is not. - Jonathan M Davis
May 31 2014
parent reply "Kagamin" <spam here.lot> writes:
By dynamic linking do you mean LoadLibrary or linking with import 
library?
May 31 2014
parent reply Jonathan M Davis via Digitalmars-d-learn writes:
On Sat, 31 May 2014 07:53:40 +0000
Kagamin via Digitalmars-d-learn <digitalmars-d-learn puremagic.com>
wrote:

 By dynamic linking do you mean LoadLibrary or linking with import
 library?
Both will work, otherwise we couldn't use Microsoft's libraries - e.g. std.windows.registry uses advapi32.dll to talk to the registry. But static linking requires that the library formats match. However, I'm afraid that I don't know enough about how linking works to know why that's a problem for static linking and not for dynamic linking. - Jonathan M Davis
May 31 2014
parent reply "Daniel Murphy" <yebbliesnospam gmail.com> writes:
"Jonathan M Davis via Digitalmars-d-learn"  wrote in message 
news:mailman.1421.1401576730.2907.digitalmars-d-learn puremagic.com...

 By dynamic linking do you mean LoadLibrary or linking with import
 library?
Both will work, otherwise we couldn't use Microsoft's libraries - e.g. std.windows.registry uses advapi32.dll to talk to the registry. But static linking requires that the library formats match. However, I'm afraid that I don't know enough about how linking works to know why that's a problem for static linking and not for dynamic linking.
The big issue with static linking is sharing the c runtime, which you can avoid if you're using dlls. Import libs only contain a mapping from mangled name to exported name (or ordinal) and this can easily be converted from one library format to another. In some very simple cases it _is_ possible to convert COFF (msvc) to OMF (dmc) object files and static libraries, but as soon as msvc inserts anything msvc-runtime specific it will fail miserably. Some examples are stack-check functions, special sections, runtime built-ins (eg 64-bit divide on some platforms).
May 31 2014
parent "Kagamin" <spam here.lot> writes:
LLVM never supported OMF. LDC uses msvcrt runtime, and MS claims 
that whatever can link with msvcrt, it also can link with later 
versions of msvcrt.
Jun 04 2014