Cant compile godot c++ module with static library

Alex161Alex161 Posts: 4Member
edited January 12 in General Support

Hi community,
im programming a small game. There is a backend, written in C++ (server and stuff), which is quite complex. Now i want to integrate some stuff in an c++ module. The code works standalone.
So i wanted to import it as a static library, which is all in all easier for me. The library itself wont change that mutch, so a static library for me is ok.
I also was able to compile the tutorial-like summator-example. But when i add my code, i cant compile it anymore.
Im using godot 3.4.2 stable.

This is my folder structure:

Engine/modules/NetworkManager/lib/NetworkClientLibrary.lib
Engine/modules/NetworkManager/lib/NetworkClientLibrary.windows.tools.32.lib       #this didnt fix it
godot/modules/NetworkManager/config.py
godot/modules/NetworkManager/NetworkManager.cpp
godot/modules/NetworkManager/NetworkManager.h
godot/modules/NetworkManager/register_types.cpp
godot/modules/NetworkManager/register_types.h
godot/modules/NetworkManager/SCsub`

NetworkManager .h

     #ifndef NETWORKMANAGER_H
     #define NETWORKMANAGER_H
     #include "core/reference.h"
     #include"../../../Network/StarShooterNetwork/NetworkClient.h"
     #include"../../../Network/StarShooterNetwork/PhysicsManager.h"

    class NetworkManager : public Reference {
    GDCLASS(NetworkManager, Reference);
    int count;
    protected:
    static void _bind_methods();

    public:
    void add(int p_value);
     void reset();
    int get_total() const;

    NetworkManager();

    void update();

    private:
    NetworkClient networkClient;
    PhysicsManager physicsManager;
    }; 

NetworkManager.cpp //small portion of it

    void NetworkManager::_bind_methods() {
    ClassDB::bind_method(D_METHOD("add", "value"), &NetworkManager::add);
    ClassDB::bind_method(D_METHOD("reset"), &NetworkManager::reset);
    ClassDB::bind_method(D_METHOD("get_total"), &NetworkManager::get_total);
    ClassDB::bind_method(D_METHOD("update"), &NetworkManager::update);
    }

    void NetworkManager::update()
    {
    size_t maxMessages = 1000;
    networkClient.update(maxMessages);
    physicsManager.updatePhysics();
    }

SCONS

    Import('env')
    env_module = env.Clone()
    env_module.add_source_files(env.modules_sources, "*.cpp") # Add all cpp files to the build
    env_module.Append(CPPPATH=["../../../Network/asio/include", "../../../Network/StarShooterNetwork"])
    env.Append(LIBPATH=['lib'])
    env.Append(LIBS='NetworkClientLibrary') `

If i run scons --clean, and then scons p=windows tools=yes bits=32 -j4 this happens:

scons: Reading SConscript files ...
Configuring for Windows: target=debug, bits=32
Found MSVC version 14.2, arch x86, bits=32
Checking for C header file mntent.h... (cached) no
scons: done reading SConscript files.
scons: Building targets ...
[...]
[ 96%] Building compilation database compile_commands.json
[ 96%] Linking Program        ==> bin\godot.windows.tools.32.exe
[ 97%] ows.tools.32.lib'
[ 97%] scons: *** [bin\godot.windows.tools.32.exe] Error 1181
scons: building terminated because of errors.
[Time elapsed: 00:00:34.580]

If i change the includes to #include "NetworkClient.h" etc I get an Error

[100%] Linking Program        ==> bin\godot.windows.tools.32.exe
LINK : fatal error LNK1181: cannot open input file 'NetworkClientLibrary.windows.tools.32.lib'
scons: *** [bin\godot.windows.tools.32.exe] Error 1181
scons: building terminated because of errors.
[Time elapsed: 00:00:23.844]

I really dont know what to do, it will be a small error, but i cant find it. Has anybody an idea?
Greetings

Comments

  • TwistedTwiglegTwistedTwigleg Posts: 5,251Admin

    This discussion was caught in the moderation queue since you have not confirmed your account yet.

    Upon creating your account you should have received an account verification email. The confirmation email may have been incorrectly flagged as spam, so please also check your spam filter. Without confirming your account, future posts may also be caught in the moderation queue. You can resend a confirmation email when you log into your account if you cannot find the first verification email.

    (Note: You do not need to repost, the discussion has been moved out and is visible now)

    If you need any help, please let us know! You can find ways to contact forum staff on the Contact page. Thanks! :smile:

  • Alex161Alex161 Posts: 4Member
    edited January 14

    I found out, that the problem is probably related, that scons or the compiler/linker doesnt find my library. First, i didnt compile with -j parameter. This way i was able to read some more error messages.

    I changed my scons to
    # SCsub
    Import('env')

    env_module = env.Clone()
    env_module.add_source_files(env.modules_sources, "*.cpp") # Add all cpp files to the build
    env_module.Append(CPPPATH=["../../../Network/asio/include", "../../../Network/StarShooterNetwork"])
    
    #env.Append(LIBPATH=['lib'])
    #env_module.Append(LIBPATH=['#C:/Users/Adrian/Documents/Programmierprojekte/StarShooter/Engine/modules/NetworkManager/lib/'])
    #env_module.Append(LIBPATH=['lib'])
    
    env.Append(LIBS=[File('C:/Users/...../Engine/modules/NetworkManager/lib/PhysicsManager.windows.opt.tools.32.dll')])
    

    Using this configuration i got the error:
    *** [bin\godot.windows.opt.tools.32.mono.exe] Implicit dependency modules\NetworkManager\lib\PhysicsManager.windows.opt.tools.32.dll' not found, needed by targetbin\godot.windows.opt.tools.32.mono.exe'.

    Using just the env.Append(LIBPATH=['lib']), ill get
    LINK : fatal error LNK1181: cannot open input file 'PhysicsManager.windows.opt.tools.32.lib'

    The file is definetly present. I copied it in the bin folder, too and in the core folder.
    Has anybody an idea?
    Greetings

  • CalinouCalinou Posts: 1,140Admin Godot Developer
  • Alex161Alex161 Posts: 4Member
    edited January 21

    Thx Calinou for pointing this out. I think you are right. The problem is, the solution in this issue didn't help me.
    I found out, everything what is NOT in the module directory directly is automatically compiled as a static library, even when imported in SCONS with env_module.Append(CPPPATH="INSERT_REMOTE_PATH_HERE""]).

    After hours of compiling, i didn't get it to work. So I made a dirty solution, which is to temporary copy all files for compilation and then removing them after that. So its then just compiled as part of the module-object and not a seperated static library.
    This is a .bat file, so it's windows dependent, really nothing to be proud of, but wanted to share it with you, if someone has the similar issue. This works for me.

    compileEngine.bat

    xcopy /B /E EXTRA_PATH_TO_ENGINE_MODULE  Engine\modules\ENGINE_PLUGIN_NAME\
    xcopy /B /E OTHER_IMPORTS Engine\modules\ENGINE_PLUGIN_NAME\
    scons target=release_debug --clean
    scons platform=windows vsproj=yes tools=yes target=release_debug bits=32 -j4
    rd /s /q Engine\modules\ENGINE_PLUGIN_NAME\
    

    I hope this can help someone, for me this works reliably.

    Greetings

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file