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/       #this didnt fix it

NetworkManager .h

     #include "core/reference.h"

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

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


    void update();

    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;


    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(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\
[ 97%]'
[ 97%] scons: *** [bin\] 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\
LINK : fatal error LNK1181: cannot open input file ''
scons: *** [bin\] 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?


  • TwistedTwiglegTwistedTwigleg Posts: 5,344Admin

    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

    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"])

    Using this configuration i got the error:
    *** [bin\] Implicit dependency modules\NetworkManager\lib\' not found, needed by targetbin\'.

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

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

  • CalinouCalinou Posts: 1,384Admin 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.


    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.


Leave a Comment

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