Unresolved external symbol while building command.c

   1794   5   1
User Avatar
Member
209 posts
Joined: March 2018
Offline
Hey guys!
I encounter with an error in linking stage when building command.c HDK example.
The problem is a linker error in CMD_Manager.h header file says:
command.C.obj:-1: error: LNK2019: unresolved external symbol “private: static class CMD_Manager * CMD_Manager::theManager” (?theManager@CMD_Manager@@0PEAV1@EA) referenced in function “public: static class CMD_Manager * __cdecl CMD_Manager::getContext(void)” (?getContext@CMD_Manager@@SAPEAV1@XZ)
I use Microsoft Build Tools 2017 v 15.9.18 and CMake as build system generator.
If I use Houdini Command Line Tool and build the example with hcustom everything's just working fine but when I use Visual Build Tools I get the linker error.
Can anyone help?
Thank you so much!
User Avatar
Member
806 posts
Joined: Oct. 2016
Offline
Hi, guy,

without having tried this one myself, experience says that MS tools tend to have some machine selection (x86 vs. x64 etc) set wrongly when using cmake (without paying EXTREME caution to all options).
Also, make sure you're not mixing debug and release versions (another “goodie” that I encounter every other compile run).

Maybe this helps?

Marc
---
Out of here. Being called a dick after having supported Houdini users for years is over my paygrade.
I will work for money, but NOT for "you have to provide people with free products" Indie-artists.
Good bye.
https://www.marc-albrecht.de [www.marc-albrecht.de]
User Avatar
Member
209 posts
Joined: March 2018
Offline
malbrecht
Hi, guy,

without having tried this one myself, experience says that MS tools tend to have some machine selection (x86 vs. x64 etc) set wrongly when using cmake (without paying EXTREME caution to all options).
Also, make sure you're not mixing debug and release versions (another “goodie” that I encounter every other compile run).

Maybe this helps?

Marc

Dear Marc thank you so much!
Let me show you what I've done:
CMakeLists.txt:
# Specify the minimum required version of CMake to build the project. cmake_minimum_required( VERSION 3.6 ) project( My_HDK_Project ) list( APPEND CMAKE_PREFIX_PATH "E:/Softwares/Houdini/toolkit/cmake" ) find_package( Houdini REQUIRED ) # Add a library with two source files. set( library_name CMD ) add_library( ${library_name} SHARED command.C ) target_link_libraries( ${library_name} Houdini ) houdini_configure_target( ${library_name})
command.C:
/*
 * Copyright (c) 2020
 *	Side Effects Software Inc.  All rights reserved.
 *
 * Redistribution and use of Houdini Development Kit samples in source and
 * binary forms, with or without modification, are permitted provided that the
 * following conditions are met:
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. The name of Side Effects Software may not be used to endorse or
 *    promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
 * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *----------------------------------------------------------------------------
 */

#include <string.h>
#include <malloc.h>
#include <math.h>
#include <UT/UT_DSOVersion.h>
#include <CMD/CMD_Args.h>
#include <CMD/CMD_Manager.h>

// NOTE: Please consider extending HOM rather than hscript

static void
cmd_args(CMD_Args &args)
{
    // Command callback
    int		i;
    if (args.found('e'))
    {
    args.err() << "Found -e option with: " << args.argp('e') << "\n";
    args.showUsage();
    }
    else
    {
    args.out() << "Arguments:\n";
    for (i = 1; i < args.argc(); i++)
        args.out() << i << ":  " << args(i) << "\n";
    }
}

void
CMDextendLibrary(CMD_Manager *cman)
{
    // Extend the hscript command language by adding a simple command which
    // prints the arguments.
    cman->installCommand("args",	"e:",	cmd_args);
}

The result of running CMake:
-- The C compiler identification is MSVC 19.16.27035.0 -- The CXX compiler identification is MSVC 19.16.27035.0 -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done -- Generating done CMake Warning: Manually-specified variables were not used by the project: QT_QMAKE_EXECUTABLE -- Build files have been written to: C:/Users/Nima Nolan/Desktop/HDK Sample/build-HDK-Desktop_Qt_5_14_1_MSVC2017_64bit-Release
The result of building command.C after CMake stage:
15:49:59: Running steps for project My_HDK_Project... 15:49:59: Starting: "E:\Softwares\CMake\bin\cmake.exe" --build . --target all [1/2 0.1/sec] Building CXX object CMakeFiles\CMD.dir\command.C.obj cl : Command line warning D9025 : overriding '/W3' with '/W1' [2/2 0.2/sec] Linking CXX shared library "C:\Users\Nima Nolan\Documents\houdini18.0\dso\CMD.dll" FAILED: C:/Users/Nima Nolan/Documents/houdini18.0/dso/CMD.dll C:/Users/Nima Nolan/Documents/houdini18.0/dso/CMD.lib cmd.exe /C "cd . && E:\Softwares\CMake\bin\cmake.exe -E vs_link_dll --intdir=CMakeFiles\CMD.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100177~1.0\x64\mt.exe --manifests -- C:\PROGRA~2\MICROS~1\2017\BUILDT~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\CMD.rsp /out:"C:\Users\Nima Nolan\Documents\houdini18.0\dso\CMD.dll" /implib:"C:\Users\Nima Nolan\Documents\houdini18.0\dso\CMD.lib" /pdb:"C:\Users\Nima Nolan\Documents\houdini18.0\dso\CMD.pdb" /dll /version:0.0 /machine:x64 /INCREMENTAL:NO && cd ." LINK: command "C:\PROGRA~2\MICROS~1\2017\BUILDT~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe /nologo @CMakeFiles\CMD.rsp /out:C:\Users\Nima Nolan\Documents\houdini18.0\dso\CMD.dll /implib:C:\Users\Nima Nolan\Documents\houdini18.0\dso\CMD.lib /pdb:C:\Users\Nima Nolan\Documents\houdini18.0\dso\CMD.pdb /dll /version:0.0 /machine:x64 /INCREMENTAL:NO /MANIFEST /MANIFESTFILE:C:\Users\Nima Nolan\Documents\houdini18.0\dso\CMD.dll.manifest" failed (exit code 1120) with the following output: Creating library C:\Users\Nima Nolan\Documents\houdini18.0\dso\CMD.lib and object C:\Users\Nima Nolan\Documents\houdini18.0\dso\CMD.exp command.C.obj : error LNK2019: unresolved external symbol "private: static class CMD_Manager * CMD_Manager::theManager" (?theManager@CMD_Manager@@0PEAV1@EA) referenced in function "public: static class CMD_Manager * __cdecl CMD_Manager::getContext(void)" (?getContext@CMD_Manager@@SAPEAV1@XZ) C:\Users\Nima Nolan\Documents\houdini18.0\dso\CMD.dll : fatal error LNK1120: 1 unresolved externals ninja: build stopped: subcommand failed. 15:50:12: The process "E:\Softwares\CMake\bin\cmake.exe" exited with code 1. Error while building/deploying project My_HDK_Project (kit: Desktop Qt 5.14.1 MSVC2017 64bit) The kit Desktop Qt 5.14.1 MSVC2017 64bit has configuration issues which might be the root cause for this problem. When executing step "CMake Build" 15:50:12: Elapsed time: 00:13.I'm using Qt Creator as an IDE for doing this.
The interesting thing is if I define:
CMD_Manager* CMD_Manager::theManager = nullptr;
The linker error will be gone!
Any help will be appreciated!
User Avatar
Member
806 posts
Joined: Oct. 2016
Offline
Hi,

the one thing popping out immediately is:

The kit Desktop Qt 5.14.1 MSVC2017 64bit has configuration issues which might be the root cause for this problem

Obviously, if you create the missing object (a CMD_Manager) yourself, the missing object from a *.lib won't matter, but you don't know if the object is getting filled (e.g. from an overloaded instance), so if your compiled version with the “hack” doesn't work, you might need to check what else gets linked in by default when you use hcustom. Docs say, that “-e” lists the current configuration:

-e Echo the compiler and linker commands run by this script.
(this is for hcustom), maybe you give that a try and check if you are missing a static .lib that would normally be linked?

But, again, my suspicion would be that something about your Qt config is different to what hcustom uses …

Apologies for not being able to pinpoint it, consider my response “moral support” :-)
Marc
---
Out of here. Being called a dick after having supported Houdini users for years is over my paygrade.
I will work for money, but NOT for "you have to provide people with free products" Indie-artists.
Good bye.
https://www.marc-albrecht.de [www.marc-albrecht.de]
User Avatar
Member
209 posts
Joined: March 2018
Offline
malbrecht
Hi,

the one thing popping out immediately is:

The kit Desktop Qt 5.14.1 MSVC2017 64bit has configuration issues which might be the root cause for this problem

Obviously, if you create the missing object (a CMD_Manager) yourself, the missing object from a *.lib won't matter, but you don't know if the object is getting filled (e.g. from an overloaded instance), so if your compiled version with the “hack” doesn't work, you might need to check what else gets linked in by default when you use hcustom. Docs say, that “-e” lists the current configuration:

-e Echo the compiler and linker commands run by this script.
(this is for hcustom), maybe you give that a try and check if you are missing a static .lib that would normally be linked?

But, again, my suspicion would be that something about your Qt config is different to what hcustom uses …

Apologies for not being able to pinpoint it, consider my response “moral support” :-)
Marc

Finally I solved it.
The problem was solved by changing CMakeLists.txt as follow:
# Specify the minimum required version of CMake to build the project. cmake_minimum_required( VERSION 3.6 ) project( My_HDK_Project ) list( APPEND CMAKE_PREFIX_PATH "E:/Softwares/Houdini/toolkit/cmake" ) find_package( Houdini REQUIRED ) # Add a library with two source files. set( library_name CMD ) add_library( ${PROJECT_NAME} SHARED command.C ) target_link_libraries(${PROJECT_NAME} Houdini ) houdini_configure_target(${PROJECT_NAME})
User Avatar
Member
806 posts
Joined: Oct. 2016
Offline
ah … looks reasonable! So it *was* a missing linked library after all :-)

Thanks for publishing your solution, that will help others running into the same wall!


Marc
---
Out of here. Being called a dick after having supported Houdini users for years is over my paygrade.
I will work for money, but NOT for "you have to provide people with free products" Indie-artists.
Good bye.
https://www.marc-albrecht.de [www.marc-albrecht.de]
  • Quick Links