Godot Version
4.1
Question
I’m planning to experiment with the G’MIC image processing library (https://gmic.eu/ ) and am currently trying to add a module to access the library. I followed the steps in the documentation on how to link to external libraries (Binding to external libraries — Godot Engine (4.1) documentation in English ) and the setup seems correct and SCons does find the library and add it to the linker command, but I get errors about unresolved external symbols:
module_gmic.windows.editor.dev.x86_64.lib(godot_gmic.windows.editor.dev.x86_64.obj) : error LNK2019: unresolved external symbol "public: __cdecl gmic::~gmic(void)" (??1gmic@@QEAA@XZ) referenced in function "public: void __cdecl GMIC::test(void)" (?test@GMIC@@QEAAXXZ)
module_gmic.windows.editor.dev.x86_64.lib(godot_gmic.windows.editor.dev.x86_64.obj) : error LNK2019: unresolved external symbol "public: __cdecl gmic::gmic<float>(char const * const,struct gmic_library::gmic_list<float> &,struct gmic_library::gmic_list<char> &,char const * const,bool,float * const,bool * const)" (??$?0M@gmic@@QEAA@QEBDAEAU?$gmic_list@M@gmic_library@@AEAU?$gmic_list@D@2@0_NQEAMQEA_N@Z) referenced in function "public: void __cdecl GMIC::test(void)" (?test@GMIC@@QEAAXXZ)
Using nm -Cg libgmic.a
it looks to me that those symbols are present in the library:
0000000000000000 T gmic::gmic<float>(char const*, gmic_library::gmic_list<float>&, gmic_library::gmic_list<char>&, char const*, bool, float*, bool*)
[...]
00000000000c0260 T gmic::~gmic()
The directory setup is as follows:
modules/
|- gmic/
|- include/
| |- gmic.h
|- lib/
| |- libgmic.a
| |- [several .dll files needed by libgmic]
|- config.py
|- godot_gmic.cpp
|- godot_gmic.h
|- register_types.cpp
|- register_types.h
|- SCsub
The header file and the files in modules/gmic/lib are copied from latests version (3.4.0) of the C/C++ library download (https://gmic.eu/files/windows/gmic_3.4.0_lib_win64.zip ). I also tried compiling the library myself (G'MIC - GREYC's Magic for Image Computing: A Full-Featured Open-Source Framework for Image Processing - Download ), but the result is the same.
If I am not mistaken .lib files and .a files are both just archives containing compiled .o files, so I do not think that those are the wrong files. I also double checked that everything is using 64 bit.
The module only contains a simple test() method:
godot_gmic.cpp:
#include "godot_gmic.h"
#include "gmic.h"
void GMIC::_bind_methods() {
ClassDB::bind_method(D_METHOD("test"), &GMIC::test);
}
void GMIC::test() {
gmic_list<float> image_list;
gmic_list<char> image_names;
try {
gmic("testimage2d 512 output gmic_test.png", image_list, image_names);
} catch (gmic_exception &e) {
printf("GMIC ERROR: %s\n", e.what());
}
}
The linker error about the missing symbols for gmic() and ~gmic() dissappear when I remove the call to gmic() in the test() method. The constructors for the gmic_list instances seem to be linked just fine.
The SCsub file adds the library correctly:
# SCsub
Import('env')
env_gmic = env.Clone()
env_gmic.add_source_files(env.modules_sources, "*.cpp")
env_gmic.Append(CPPPATH=["include"])
if env.msvc:
env.Append(LIBS=[File('lib/libgmic.a')])
else:
env.Append(LIBPATH=["gmic"])
env.Append(LIBS=['gmic', 'cgmic'])
Am I missing a step or a configuration here?
If anyone encountered similar problems when linking to an external library, any inputs and tipps would be greatly appreciated!
Thanks in advance for any advice and best regards,
Patrick