Martin Kersten
Martin Kersten

Reputation: 5513

How to compile 64Bit DLL in Eclipse CDT (using Windows SDK)?

What I want to be done: Create a 64bit DLL on win7 that interacts with the Windows API including the OLE32.dll.

What I have got:

I am currently stuck. I download Visual Studio 2015 Community Edition. I tried to create a DLL there and on creation it generated everything but no dll. The program did not complain, everything was setup as in the tutorial but no dll file.

So I skipped this and downloaded Eclipse CDT. I set up using the Visual C toolchain and after minor issues I had my DLL generated. So I used Java to fire it up but it complained (I use JNA for integration) and it seams that I have a 32bit DLL.

So I searched the web and read and did stuff but I am totally lost. Since the Visual Studio 2010 Express edition came without a 64bit compiler I am not even sure if the Community edition of Visual Studio supports 64bit dlls this time.

I also have the Windows SDK v7.1 installed. I link to a library file ole32.dll. It contains the method CoCreateInstance which I require. I have to add this manually in order for the compiler to pick it up. If I switch to the 64bit dll version the compiler complains about the CoCreateInstance method can not be linked.

So basically I am lost here. A source on the web gave a work around for the 2010 Express being not able to create x64 DLL and it turned out that the hint was getting windows SDK since it it comes along with a compiler.

Also I noticed that CDT uses Visual Studio 10 files so I guess it is using this compiler.

I set to both compiler and linker the /machine:64 option. But the linker still complains that the obj file from the compiler is 32bit.

Any Ideas?

[Update]

The Compiler prints the following line so basically it is not able to compile 64bit version. Any idea how to replace it? As said it uses the Visual Studio 10 folder but I also have a Visual Studio 12 and 14 folder as well.

cl : Command line warning D9002 : ignoring unknown option '/machine:x64'

Upvotes: 4

Views: 2280

Answers (1)

tommybee
tommybee

Reputation: 2551

Well, I don't think '/machine:x64' is a cl option but it's one of linker option.

If you want to make some dll maybe with windows sdk or visual studio environment.

I am not sure that my solution is fit for yours or not, this is what i did for my 64-bit project to compile with eclipse and windows sdk 7.1.

I have two eclipse IDEs which are 32bit and 64bit neon version. I choose a 64-bit one. You can check one of my answer about installation here. In my opinion, any version of them will be fine. It is your choice.

First step. run 'Windows SDK 7.1 Command Prompt from the start menu.

enter image description here

then, start my eclipse on the command window after changing 64-bit development level with command as follows.

enter image description here enter image description here

Second Step. Setting up path variables to my project. I have my own project with a properties window.

enter image description here

The important variable seems to be both LIB and PATH variable in my point.

I crosschecked this two variable, one was from the windows SDK's prompt window and another was current setting variables after installation.

SDK variables here enter image description here

My final variables are

LIB:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319;
C:\Windows\Microsoft.NET\Framework\v4.0.30319;
C:\Windows\Microsoft.NET\Framework64\v3.5;
C:\Windows\Microsoft.NET\Framework\v3.5;;
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Lib\amd64;
C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\X64

PATH: 
C:\Windows\Microsoft.NET\Framework64\v4.0.30319;
C:\Windows\Microsoft.NET\Framework\v4.0.30319;
C:\Windows\Microsoft.NET\Framework64\v3.5;
C:\Windows\Microsoft.NET\Framework\v3.5;;
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE;
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools;;
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\amd64;
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\VCPackages;;
C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\x64;
C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\x64;
C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin;;
C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;
C:\Windows\System32\WindowsPowerShell\v1.0\;

Third, I modified my linker flag as you see the picture below.

enter image description here

Finally, I compiled my project successfully.

Here is my build log.

Info: Internal Builder is used for build

cl /c /EHs /MD /Zi /nologo /Foutil.obj "..\util.c"

rc /Fo proc_view.res "..\proc_view.rc"

Microsoft (R) Windows (R) Resource Compiler Version 6.1.7600.16385 Copyright (C) Microsoft Corporation. All rights reserved.

cl /c /EHs /MD /Zi /nologo /Foprocss.obj "..\procss.c"

link /machine:x64 /debug /nologo /OUT:Systemer.exe FreeList.obj LinkedList.obj proc_main.obj proc_view.res procss.obj util.obj Kernel32.lib Psapi.lib User32.lib enter image description here

The last one had done with checking if my executable file was 64-bit or 32-bit with a dumpbin command.

enter image description here

That is all.

I think the Eclipse with MinGW or cygwin might be a better option.

I hope this is right for you.

Upvotes: 1

Related Questions