Linking .dll to GDextension using scons

Godot Version

4.2.2

Question

I’m trying to build a godot extension that uses modules from OpenCV. Within my application folder I have the godot-cpp folder, a src folder containing the code for my extension node as well as register_types.cpp and register_types.h, an include folder which has an opencv2 subfolder that contains all of the opencv headers, and a lib folder that holds opencv_world490.dll and opencv_world490.lib.

I am encountering the error “fatal error C1083: Cannot open include file: ‘opencv2/core/mat.hpp’: No such file or directory” which makes me think scons is not recognizing the opencv headers even though I have listed the folder in the CPPPATH. I found the following post which seems like its trying to do something similar and added those lines to my scon file which is in the root directory.

https://www.reddit.com/r/godot/comments/1deoxn2/how_to_link_a_godot_extension_with_a_precompiled/

Here is my Scon File:

import os
import sys

env = SConscript("godot-cpp/SConstruct")

env.Append(CPPPATH=["src/", "include/"])
env.Append(LIBS=["opencv_world490"])
env.Append(LIBPATH=["lib/"])
sources = Glob("src/*.cpp")

if env["platform"] == "macos":
    library = env.SharedLibrary(
        "demoproject/bin/CalibratedCamera.{}.{}.framework/CalibratedCamera.{}.{}".format(
            env["platform"], env["target"], env["platform"], env["target"]
        ),
        source=sources,
    )
else:
    library = env.SharedLibrary(
        "demoproject/bin/CalibratedCamera{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
        source=sources,
    )

Default(library)

And my file structure with the include headers:

1 Like

have you found solution? does this method of including dlls work?

Yes it works great just had to change up how I added to dll to the bin, heres what worked for me.

env = SConscript("godot-cpp-godot-4.2.2-stable/SConstruct")

env.Append(CPPPATH=["src/", "include/"])
env.Append(LIBS=["opencv_world490"])
env.Append(LIBPATH=["lib/"])

sources = Glob("src/*.cpp")

if env["platform"] == "macos":
    library = env.SharedLibrary(
        "demoproject/bin/CalibratedCamera.{}.{}.framework/CalibratedCamera.{}.{}".format(
            env["platform"], env["target"], env["platform"], env["target"]
        ),
        source=sources,
    )
else:
    library = env.SharedLibrary(
        "demoproject/bin/CalibratedCamera{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
        source=sources,
    )

# Ensure the DLLs are copied to the target directory 
if env["platform"] == "windows":
    dlls = [
        "lib/opencv_world490.dll"
    ]
    for dll in dlls:
        env.Command(
            target=os.path.join("demoproject/bin/", os.path.basename(dll)),
            source=dll,
            action=Copy("$TARGET", "$SOURCE")
        )
Default(library)```
1 Like

when i write this two lines scons prints some currupted text to the console and exits with error.

what dll are you trying to use make sure you have the name spelled right and the dll included in the lib folder

I’m trying to use third party dll “tracy.dll”
When i do it like this then scons for some reason seeks a dll with added sufixes to it (like those that he adds to a compiling dll when compiling sources into one).

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.