0

I see below linking error on compiling with x64 environment set.

somefile.def : error LNK2001: unresolved external symbol _somesymbol
somepath\somefile.lib : fatal error LNK1120: 1 unresolved externals
gmake[2]: *** [somepath\somefile.dll] Error 1120

When I checked somefile.def generated in x86, it too had the same above symbol, difference being there it had double underscores ('__somesymbol'). Whats the reason behind this? The code contains both C & C++ files.

Can anyone help in resolving this issue preferably with elaborate explanation?

Thanks

Samanyu
  • 1
  • 1
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Mzzl Dec 01 '17 at 12:28
  • Identifiers do not get decorated in 64-bit code. Blissfully unnecessary, x64 does not have a boatload of calling conventions. Verify this with the linker's map file, ought to be plain `somesymbol` without a leading underscore. So you surely need to modify the .def file accordingly, we can't see it from here. Do favor the `__declspec(dllexport)` attribute. – Hans Passant Dec 01 '17 at 14:40
  • I see the .map file generated for x86 build. But not for x64 build. Also how do I actually modify the .def file, it gets generated on the fly. – Samanyu Dec 03 '17 at 06:59
  • Thanks Hans, I tweaked the make code to generate "somefile.def" with "__somesymbol" instead of "_somesymbol" and could successfully build my x64 bit library and dll files. – Samanyu Dec 05 '17 at 12:18

1 Answers1

0

Identifiers do not get decorated in 64-bit code. Blissfully unnecessary, x64 does not have a boatload of calling conventions. Verify this with the linker's map file, ought to be plain somesymbol without a leading underscore. So you surely need to modify the .def file accordingly, we can't see it from here. Do favor the __declspec(dllexport) attribute. – Hans Passant

I tweaked the make code to generate "somefile.def" with "__somesymbol" instead of "_somesymbol" and could successfully build my x64 bit library and dll files. – Samanyu

Armali
  • 18,255
  • 14
  • 57
  • 171