Search code examples
c++visual-c++linkertclnmake

Linker errors against custom built tcl85.lib, works against ActiveState distribution's tcl85.lib


We are building Tcl ourselves in order to distribute our own compiled binaries with an application. The application itself links against the Tcl library and uses the API internally.

To build Tcl we got the sources from http://sourceforge.net/projects/tcl/, we then navigate into the /win directory, change the buildall.vc.bat file to point to our MSVC installation and then we run that bat file. Building works as expected and outputs are produced in /win/Release_VC11. More specifically, tcl85.lib and tcl85.dll are produced.

When we link against this .lib from within our Qt C++ application, we get a bunch of linker errors. For example:

commands.obj : error LNK2019: unresolved external symbol __imp_Tcl_AppendResult 
referenced in function "int __cdecl CallQMessageBox(void *,struct Tcl_Interp *,
int,char * * const)" (?CallQMessageBox@@YAHPEAXPEAUTcl_Interp@@HQEAPEAD@Z)

However, when we link against the tcl85.lib file provided as part of the ActiveState Tcl distribution, the linker does not have any issues and builds fine. We verified that its the exact same version of Tcl in both cases.

We are using MSVC 2012 (Express Edition) to build Tcl, and the build command remains unmodified in buildall.vc.bat:

::set OPTS=threads
if not %SYMBOLS%.==. set OPTS=symbols
nmake -nologo -f makefile.vc release OPTS=%OPTS% %1

We've been trying all sorts of things with not luck.


Solution

  • Ok, figured it out:

    I was building Tcl as a 32bit binary instead of a 64bit one.

    Replacing

    call "D:\tools\Microsoft Visual Studio 11.0\VC\bin\vcvars32.bat"
    

    with

    call "D:\tools\Microsoft Visual Studio 11.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat"
    

    and adding AMD64 to the nmake command like this

    nmake -nologo -f makefile.vc release OPTS=%OPTS% %1 MACHINE=AMD64
    

    in buildall.vc.bat seems to have fixed it.