LNK1318: Unexpected PDB error; OK (0)
Asked Answered
C

15

31

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?

Coerce answered 23/11, 2010 at 13:33 Comment(1)
Several hints in this thread: social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/…Jarlathus
C
24

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

Coerce answered 24/2, 2011 at 13:24 Comment(7)
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!Alti
@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.Coerce
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.Alti
found this: incredibuild.force.com/s/article/…Alti
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.Stave
@Stave completely agree - but that's what we haveCoerce
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).Nullipore
N
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.

Nessy answered 10/11, 2021 at 10:7 Comment(0)
S
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.

Smattering answered 16/12, 2011 at 12:33 Comment(0)
S
4

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

Seamanlike answered 10/3, 2014 at 11:46 Comment(0)
S
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.
Sabadilla answered 1/12, 2016 at 8:22 Comment(3)
This is all I had to do as well. Use Process Explorer to kill mspdbsrv.exe, relink the failing project.Fillagree
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.Whore
easier: in cmd.exe taskkill /F /IM mspdbsrv.exe and repeat until you get ERROR: The process "mspdbsrv.exe" not foundIndigenous
W
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
Whore answered 22/6, 2018 at 2:4 Comment(2)
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.Knossos
_IsNativeEnvironment seems to be outdated and for Visual Studio 2012 according to microsoft.github.io/bond/manual/bond_cpp.html. Instead, try using /p:PreferredToolArchitecture=x64 as a parameter to msbuild: learn.microsoft.com/en-us/cpp/build/reference/…Allegory
L
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

Lorenzalorenzana answered 14/1, 2014 at 19:57 Comment(0)
F
2

Rebuilding the project solved the problem

Folberth answered 6/6, 2016 at 5:43 Comment(0)
S
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

Squatter answered 13/6, 2012 at 4:38 Comment(0)
P
1

No need to restart the VS or the PC. Also, No need to clean or fully rebuild. Just follow the steps below.

These errors usually come together:

LNK1318 - Unexpected PDB error; OK (0)

C1090 - PDB API call failed, error code '24'

To fix it, do a "Build Only" on the project(s) with "LNK1318 Unexpected PDB error; OK (0)". Then do an incremental Build over the Solution

Precipitation answered 26/6, 2024 at 14:14 Comment(0)
W
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.

Welldone answered 29/10, 2013 at 18:38 Comment(0)
E
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.

Earth answered 25/5, 2023 at 13:10 Comment(0)
H
0

Seems to have something to do with linking several executables in parallel. From what I gathered, MSVC linker (and sometimes the compiler too) uses a separate process to generate PDBs, and several instances of the linker will share the same process if launched in parallel. And apparently they can get confused when doing that.

For us, switching to lld-link seems to have worked. (Clang's linker, a drop-in replacement for Microsoft's link.exe.)

Hip answered 27/9, 2023 at 12:3 Comment(0)
D
-1

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

Definiendum answered 26/2, 2021 at 10:8 Comment(2)
And then what? After we go to the place you indicated, what should be done?Aegis
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.Allegory
A
-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".
Alti answered 8/10, 2021 at 15:51 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.