30

I'm trying to link against a library (libcef_wrapper_dll.lib) that was built with the /MDd flag. My application is build with /MDd and /CLR so should be compatible. The project compiles fine but when linking I get the very unhelpful error below:

   Error    1   fatal error LNK1318: Unexpected PDB error; OK (0) ''    c:\Projects\Cef\CefSharp\libcef_dll_wrapper.lib 1   CefSharp

I don't have a .PDB file for the .LIB, do I need one?

chillitom
  • 24,888
  • 17
  • 83
  • 118
  • Several hints in this thread: http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/9e58b7d1-a47d-4a76-943a-4f35090616e8 – Hans Passant Nov 23 '10 at 14:33

13 Answers13

23

Turned out that I needed to delete all of the project temp files inc. caches etc., kill the debug symbol server and restart windows.

chillitom
  • 24,888
  • 17
  • 83
  • 118
  • 1
    I am facing this often.. deleting everything or restarting machine doesn't looks a practical or good solution.. what's the root cause, and is there any proper permanent fix we can use! – Shivendra Agarwal Oct 05 '21 at 13:33
  • @ShivendraAgarwal I wish I knew - I was using VS2008 so this was a long time ago, are you experiencing the same thing with newer versions? Obviously restarting is a drastic and tedious action but it was the only thing that appeared to work. – chillitom Oct 06 '21 at 08:17
  • 1
    i m using visual studio 2019 as of now. and yes this still exist :o.. every-time this happens i have to delete whole workspace and rebuild everything, which is literally painful. – Shivendra Agarwal Oct 07 '21 at 08:31
  • found this: https://incredibuild.force.com/s/article/fatal-error-LNK1318-unexpected-PDB-error-OK-0 – Shivendra Agarwal Oct 08 '21 at 15:49
  • Deleting temp-files, deleting caches, rebuilding, restarting Windows - all these cannot be considered as a solution. I work with a very big project. Rebuilding all can take 15 minutes. – PazO Jan 13 '22 at 11:37
  • @PazO completely agree - but that's what we have – chillitom Jan 14 '22 at 10:52
  • I ran into this (stupid) problem after "repairing/optimizing" my hard drives for some reason. Turns out I had to delete all build and temporary build files from my *executable* project (where full linking happens). – PinkTurtle May 20 '22 at 15:00
6

I had the same problem when upgrading VS2019 v16.10.x to v16.11.x.

This fixed it for me:

Open your *.vcxproj file(s). Look for this line :

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

Just below that, add these 3 lines :

<PropertyGroup>
  <PreferredToolArchitecture>x64</PreferredToolArchitecture>
</PropertyGroup>

Now the 64-bit tool chain is used and you should no longer have any problems.

Sander Bouwhuis
  • 647
  • 7
  • 8
4

This one worked for me: Project properties -> C/C++ -> Code Generation -> Enable Function Level Linking -> Yes

b4da
  • 3,010
  • 4
  • 27
  • 34
4

I've seen LNK1318: Unexpected PDB error; UNKNOWN (24) when linking.

It happened when I had more than two links of large outputs happening at once - mspdbsrc.exe used more and more memory, hit 2gig or so, then crashed.

doctorlove
  • 18,872
  • 2
  • 46
  • 62
3

Best solution for me has always been to simply kill Visual Studio's Debug Symbol Server:

for /F "tokens=2 delims= " %I in ('tasklist|findstr /I "mspdbsrv.exe"') do taskkill /F /PID %I>NUL && echo VS Debug Symbol Server killed.

This command could also be run from a batch file like so:

@for /F "tokens=2 delims= " %%I in ('tasklist^|findstr /I "mspdbsrv.exe"') do taskkill /F /PID %%I>NUL && echo Debug Symbol Server killed.
Andreas
  • 5,393
  • 9
  • 44
  • 53
  • This is all I had to do as well. Use Process Explorer to kill mspdbsrv.exe, relink the failing project. – Steve Townsend May 11 '17 at 12:01
  • 1
    For use outside of a batch file, use `for /F "tokens=2 delims= " %I in ('tasklist|findstr /I "mspdbsrv.exe"') do taskkill /F /PID %I>NUL && echo VS debug symbol server killed.` – cowlinator May 15 '18 at 01:36
3

If using /MP or /MDd with MSBuild, also use the /Zf compiler option. (See https://learn.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-error-lnk1318 )

Other troubleshooting steps for LNK1318:

  • Do a full Clean/Rebuild
  • Restart mspdbsrv.exe
  • Turn off antivirus checks in your project directories.
  • Change the Debug Information Format to /C7 or None
  • Try building with /property:_IsNativeEnvironment=true
cowlinator
  • 7,195
  • 6
  • 41
  • 61
  • Setting the Debug Information Format to /C7 helps resolving the issue often, but not always. Unfortunately, it's not what you want to do, especially not for debug builds. – PMF Mar 13 '19 at 09:22
  • 1
    `_IsNativeEnvironment` seems to be outdated and for Visual Studio 2012 according to https://microsoft.github.io/bond/manual/bond_cpp.html. Instead, try using `/p:PreferredToolArchitecture=x64` as a parameter to `msbuild`: https://learn.microsoft.com/en-us/cpp/build/reference/msbuild-visual-cpp-overview?view=msvc-160 – Florian Winter Nov 03 '21 at 14:52
2

This is a technical limitation of the VC linker. You should try split your code modules up more. Splitting up libraries also help with extremely long link times.

See if you can successfully build on release mode

Sid Sarasvati
  • 819
  • 9
  • 10
2

Rebuilding the project solved the problem

1

I got the build error as follow also: LINK : fatal error LNK1318: Unexpected PDB error;

There are severa URL talked about this, but it seeems no completed solutions. Someone said mspdbsrv.exe is the trouble maker. After I clean the incremental build result and make a real clean build, it works well.

http://connect.microsoft.com/VisualStudio/feedback/details/296978/link-fatal-error-lnk1318-unexpected-pdb-error-unknown-24

http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/9e58b7d1-a47d-4a76-943a-4f35090616e8

DragonDU
  • 51
  • 4
0

I had the problem because I had a file with the /clr option that was messing things up. I moved the CLR specific code to a separate file, cleaned, rebuilt and the problem is gone.

DanW
  • 1,976
  • 18
  • 14
0

This may not be the answer. I encountered this on VS 2019. There was a time when I frequently have to "cancel build". On repeated "cancel builds", I started seeing this issue starting from following "builds".

Technically, the cancel build does not clean up few things (as you can see some recommendation of killing "mspdbsrv.exe" that might not been gracefully exited with "clean build".

finally, I would advice to leave the build run instead of "clean build" to avoid this issue. I think waiting for the build to finish is at least better than restarting the computer.

-1

This worked for me: Go to Project properties -> C/C++ -> Code Generation ->Runtime Library->Multi-threaded Debug (/MTd).

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • And then what? After we go to the place you indicated, what should be done? – Brandt Feb 27 '21 at 09:30
  • Since this error occurs sporadically, he probably changed a setting, and then the problem randomly did not occur. Changing the runtime library (to a library that you do not want to use in Release builds) most likely does not fix this. – Florian Winter Nov 03 '21 at 14:35
-1

this looks to be some incredibuild issue. refer: https://incredibuild.force.com/s/article/fatal-error-LNK1318-unexpected-PDB-error-OK-0

Fatal error LNK1318: Unexpected PDB error; OK (0) Content

--> This error may occur in a random manner - usually when building large Solutions.

There are 2 ways solving your LNK1318 error:

1. Switching to the old PDB method - C7 (/Z7) since this error seems to invoke when the regular "PDB for Edit And Continue" option is enabled.
2. Switching to 64-bit native compiler. You can enable the 64bit native compiler using Agent Settings -> Visual Studio Builds -> Advanced. Under the "PDB File Allocation" please mark the "Force 64-bit toolset".