microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.98k stars 6.34k forks source link

[Lua] Windows build has mangled names. Linux build has unmangled names. Creates linking issues #23294

Closed ndl303 closed 2 years ago

ndl303 commented 2 years ago

Not sure if you consider this an error or not but when I use the Windows build of Lua I must not place extern "C" wrappers around the include files contrary to the the Lua user manual. On a Ubuntu build I must do the opposite and include the extern "C" wrappers around the include files, in agreement with the Lua user manual.

Failure to do so generates linking issues. I suspect this is linked to a "COMPILE_AS_CPP" flag within the CMake/Make system.

I assume the Windows build is incorrect as it disagrees with the Lua user manual. Its not a big problem for me as it is easily managed by a suitable macro in my code. But it is an annoying platform dependent behaviour that should be removed.

Cheney-W commented 2 years ago

Thanks for reporting this issue. Could you please elaborate on this issue, for example:

  1. Which triplet and feature did you install?
  2. How do you place extern "C" wrappers around the include files?
  3. What's the linking issue you got?
ndl303 commented 2 years ago

Hi Cheney-W,

I am now thoroughly confused as I can no longer replicate the issue although I am now working on my office machine rather than my home machine. I suspect my home machine may have had an older version of vpkg/lua installed than my office machine. As such I think the issue can be closed as it appears to be working normally on both my Windows and Linux builds.

Just for completeness and to confirm that I am not going crazy:

Windows Triplet: x64-windows-static-md Linux Triplet: x64-linux

Here is how I do the extern "C" in my project header files:

extern "C"
{
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}

Last Saturday when I was building on Windows on my home machine everything in my project using Lua functions compiled properly but the linker failed to find the Lua symbols. I checked the linker path in VS2019 with the Versbose:lib option and confirmed it was actually linking against the Lua library inside vcpkg. I used dumpbin to look at the symbols inside the lua libraries and they appeared to be name-mangled. I removed the extern"C" {} wrapper inside the header , rebuilt the code and everything linked properly on Windows. It then failed to build on Linux.

Today, Wednesday when I build on my Windows machine at work everything builds properly in Windows if I leave the extern"C" {} in the header file, which is the correct, expected behaviour.

My office machine has the following vcpkg version of Lua installed using vcpkg list

lua:x64-windows-static-md                          5.4.3#3          A powerful, fast, lightweight, embeddable script...
lua[cpp]:x64-windows-static-md                                      Builds Lua for C++ linkage
lua[tools]:x64-windows-static-md                                    Builds Lua compiler and interpreter

I suspect my home machine has an older version of vcpkg Lua installed.

Thanks for the help. I find vcpkg is a really useful tool and appreciate all the hard work you and your team put into this project.

Cheney-W commented 2 years ago

Thanks for your reply! We are honored that vcpkg can help you.