7

I'm performing the (terrifying) task of building LLVM 3.3 on windows and I have got to the stage where I have a load of LLVM*.lib files. I want to link them together to one huge shared DLL but am struggling (this is my first time linking stuff on windows). I've tried:

link /DLL /MACHINE:X64 /OUT:LLVM3.3.dll LLVM*.lib

but to no avail. It errors with:

LINK : warning LNK4001: no object files specified; libraries used
LINK : error LNK2001: unresolved external symbol _DllMainCRTStartup
LLVM3.3.dll : fatal error LNK1120: 1 unresolved externals

The internet suggested adding the /DEFAULTLIB:corelib switch, so I did that but again it has problems:

> link /DLL /MACHINE:X64 /DEFAULTLIB:corelibc /OUT:LLVM3.3.dll LLVM*.lib

LINK : warning LNK4001: no object files specified; libraries used
LINK : fatal error LNK1104: cannot open file 'corelibc.lib'

How do I do this?


EDIT: I managed to fix the above problem, by implementing an empty DllMain and making an EmptyDllMain.obj from it:

#include <windows.h>

BOOL APIENTRY DllMain( HANDLE hModule, 
                   DWORD  ul_reason_for_call, 
                   LPVOID lpReserved
                 )
{
    return TRUE;
}

and then trying:

link /DLL /OUT:LLVM3.3.dll LLVM*.lib EmptyDllMain.obj

but the DLL I get out is just 8kb - it seems to have missed out the many megabytes of LLVM libraries! How do I get them included?


EDIT2: I solved the LLVM compilation on Windows problem, take a look at this document on github.

Callum Rogers
  • 15,630
  • 17
  • 67
  • 90
  • The reason the DLL is tiny is that lib files are only linked in if they are needed to satisfy references. You don't have any - so nothing is linked. Options are 1. Write a DEF file to create references; 2. Use `-WHOLEARCHIVE:` – Martin Bonner supports Monica Sep 20 '18 at 07:46

3 Answers3

3

I had this once while linking one lib with a wrong platform set together (X86 to X64). Make sure all the LLVM*.lib are build and linked with the correct toolchain:

[...]\Microsoft visual Studio 10.0\VC\bin\amd64\ cl.exe and link.exe

which you get by calling

"%PROGRAMFILES(X86)%\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" amd64

Also I had similar problems when mixing MT and MD CRTs, I recommend you stick to

/MD (or /MDd for debug) 

when compiling the objects for any of the LLVM*.lib (and any other objects from other external libraries you link into these).

[edit]

And kick out that ugly EmptyDllMain.obj !

[/edit]

Oliver Zendel
  • 2,695
  • 34
  • 29
  • I had the same issue and it was driving me crazy. In my case "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat" amd64_x86 was the trick to reset the toolchain. – Axel Podehl Oct 25 '18 at 16:49
  • "And kick out that ugly EmptyDllMain.obj " so how to solve the linker error then instead? – lalala Dec 06 '18 at 10:20
2

If you manually entered the _DllMainCRTStartup, be sure you spelled it (watch case) correctly. I had _DLLMainCRTStartup and took a while to catch why I still received the linker error. For Windows CE, the required link lib is corelibc.lib.

DilithiumMatrix
  • 17,795
  • 22
  • 77
  • 119
0

remove lib files from "ignore specific default libraries" from "Linker->Input" on project properties

S.Frank Richarrd
  • 488
  • 1
  • 3
  • 15