HelloWorld on Windows

Hello guys,

I'm initiating this thread to ask for a point in the right direction when trying to do the HelloWorld for Kludge in Windows. I assume my installation of Scons and my version of Visual Studio (2015, community) are correct. I gather this from reading the related thread http://forums.fabricengine.com/discussion/990/is-compiling-the-dll-in-windows-with-msvc-ok#latest.

On a side note, I can reproduce the HelloWorld using Ubuntu on Windows (using g++ and scons). But this produces no Windows dlls, hence not useful for me.

Here is what I am doing:
1. Create a project in Visual Studio, with Tutorial.cpp and Tutorial.hpp, as described in the tutorial. Compile a x64 dll of this code named: libTutorial.dll.
2. I have Tutorial.hpp, Tutorial.cpp and libTutorial.dll in the same folder and run Kludge's discover process: everything works fine.
3. I run Kludge's generate process: everything works fine.
4. I run the scons' construct and get the following Link error:
Compiling Tutorial.cpp
Tutorial.cpp
SharedLibrary Tutorial-Windows-x86_64.dll
Creating library Tutorial-Windows-x86_64.lib and object Tutorial-Windows-x86_64.exp
Tutorial.obj : error LNK2019: unresolved external symbol "int __cdecl AddTwoInts(int,int)" (?AddTwoInts@@YAHHH@Z) referenced in function Tutorial_AddTwoInts_c03059fc730d732cfde6e83950379548
Tutorial-Windows-x86_64.dll : fatal error LNK1120: 1 unresolved externals
scons: *** [Tutorial-Windows-x86_64.dll] Error 1120
scons: building terminated because of errors.

I have very little C++ knowledge so pardon me if I am doing something stupid.

Best,
Gustavo

Tagged:

Comments

  • scaronscaron Fabric for Houdini Posts: 171

    Did you add the lib to the kludge file?

    http://docs.fabric-engine.com/FabricEngine/2.5.0/HTML/Kludge/tutorial-hello-world.html

    You will see that the extension cannot be loaded because there is a symbol error. This is because kludge generate needs to be told that the library the extension depends on must be loaded. Do this by adding the following lines anywhere in Tutorial.kludge.py:

    ext.add_lib_dir('.')
    ext.add_lib('Tutorial')
    This is one of the reasons that kludge discover and kludge generate are separate steps: it’s not possible to know from the C++ header files what libraries are needed to compile and link the extension. For more information on methods that affect compilation, see KludgeADLCompMethods.

    Regenerate and rebuild the extension, and then run KL again:

  • JeffDJeffD Posts: 20

    Hi @Gustavo Boehs,

    If @scarons suggestion doesn't fix things, your initial compile of the .hpp & .cpp may be off.

    When I did this tutorial I used the visual c++ x64 native command prompt (Build Tools version since I don't have visual studio installed, but there's a visual studio version of this command prompt too)

    Things you need to do when using a visual C++ prompt that are not mentioned in tutorial.

    Read in environment.bat from your FE install

    Instead of the line:
    g++ -fPIC -shared Tutorial.cpp -o libTutorial.so

    Do this these two commands:
    cl /LD Tutorial.cpp // Do this first, creates the .dll and .obj
    lib /OUT:Tutorial.lib Tutorial.obj // and then this, creates the .lib

    When you go to run the test instead of:
    FABRIC_EXTS_PATH=. kl test.kl

    Do this:
    SET "FABRIC_EXTS_PATH=%FABRIC_EXTS_PATH%;<the path where test.kl is located>"
    cd to the directory where test.kl is located if not there already
    kl test.kl

    Also remember kludge generate will overwrite Tutorial.cpp, so if things don't work after you done a generate remember you need restore it if you want go through the tutorial again.

    -Jeff

  • Gustavo BoehsGustavo Boehs Posts: 66 ✭✭

    Thanks for the tip @scaron, but this didn't seem to resolve my specific link problem.

    @JeffD Thank you for the detailed suggestions. I am now running all my commands in VS x64 Native Tools Prompt + FE2.6 environment. It is far simpler to compile the code using the command line in the way you suggest. But I still get the same problematic output when running the scons command:
    scons -f Tutorial.SConstruct

    I have also tried to compile my code using the following commands:
    cl /LD /Fo: libTutorial.obj Tutorial.cpp
    lib libTutorial.obj

    I have done so in order to more accurately reproduced what is in the tutorial, and also because scons will build its own Tutorial.obj, overwriting the first obj if it bears that name. Still... the same output:
    scons: Reading SConscript files ...
    Running SCons with -j1
    scons: done reading SConscript files.
    scons: Building targets ...
    SharedLibrary Tutorial-Windows-x86_64.dll
    Creating library Tutorial-Windows-x86_64.lib and object Tutorial-Windows-x86_64.exp
    Tutorial.obj : error LNK2019: unresolved external symbol "int __cdecl AddTwoInts(int,int)" (?AddTwoInts@@YAHHH@Z) referenced in function Tutorial_AddTwoInts_c03059fc730d732cfde6e83950379548
    Tutorial-Windows-x86_64.dll : fatal error LNK1120: 1 unresolved externals
    scons: *** [Tutorial-Windows-x86_64.dll] Error 1120
    scons: building terminated because of errors.

  • JeffDJeffD Posts: 20

    Hmmm, what versions of Python & scons are you running?

    I'm using Python 2.7.13 & scons 2.5.1. if your versions are lower than that I'd definitely upgraded them.
    if you need to upgrade scons, and it fails make sure you have the wheel module(version 0.29.0 or higher)installed. You might also need to upgrade setuptools.

    My knowledge of this stuff is modest at best, so if that's not the issue, I'm pretty much out of ideas.

    -Jeff

  • Gustavo BoehsGustavo Boehs Posts: 66 ✭✭

    Hey @JeffD, same versions as you here. But thanks for going out of your way in trying to help.

    Best,
    Gustavo

  • Gustavo BoehsGustavo Boehs Posts: 66 ✭✭

    Hello guys, just bumping this thread in case anybody else would have helpful suggestions.

    Cheers

  • HelgeHelge Moderator, Fabric Employee Posts: 315 Fabric Employee

    Hey Gustavo,

    can you share the source code for the lib? My assumption is that either the symbol is not defined as a DLL export or there is a name clash. Both libraries are called "Tutorial" - so I assume that might be causing the issue. Either way please post the code so we can follow.

    Thanks!

    Research Engineer @ Fabric Software

  • Gustavo BoehsGustavo Boehs Posts: 66 ✭✭

    Hello @Helge, thanks for looking into this.

    The source for my lib are the cpp and hpp files as stated in the tutorial.
    Tutorial.cpp:
    #include "Tutorial.hpp"
    int AddTwoInts(int lhs, int rhs)
    {
    return lhs + rhs;
    }

    Tutorial.hpp:
    #pragma once
    int AddTwoInts(int lhs, int rhs);

    I create the DLL and LIB files as libTutorial, trying to mimic what is in the tutorial.

    Here is a video of the whole process, I hope it is ok to post this here.

  • HelgeHelge Moderator, Fabric Employee Posts: 315 Fabric Employee

    So the tutorial is the issue then. You need to mark the functions as extern symbols - otherwise it won't build.

    https://msdn.microsoft.com/en-us/library/dabb5z75(VS.80).aspx

    The tutorial has been tested on linux - so I think that's the issue here. The __declspec stuff is windows specific.

    Let me know if you need any further help.

    Research Engineer @ Fabric Software

  • Gustavo BoehsGustavo Boehs Posts: 66 ✭✭

    Thanks @Helge, that was it :smiley:

    So I have only changed the code in the Tutorial.hpp file when building Scons to:
    #pragma once
    __declspec(dllexport) int AddTwoInts(int lhs, int rhs);

    It was important to do this only during the scons phase, because Kludge does not know what to do with __declspec and throws an error.

    Now onto the more challenging examples in the tutorials, and maybe some real work...
    Thanks once again!

  • scaronscaron Fabric for Houdini Posts: 171

    Odd, I am pretty sure the API I have wrapped with kludge uses that dllexport option. They have it wrapped in macro though, maybe the kludge parser handles that better?

Sign In or Register to comment.