Compiling a module

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Not_a_Robot
:warning: Old Version Published before Godot 3 was released.

Hello!

When trying to compile a module I get:

In file included from core/object_type_db.h:33:0,
                 from core/object.h:714,
                 from core/reference.h:32,
                 from modules/mymodule/mymodule.h:4,
                 from modules/mymodule/MYMODULE.cpp:1:
core/method_bind.h: In instantiation of 'static T VariantCaster<T>::cast(const Variant&) [with T = char*]':
core/method_bind.inc:673:23:   required from 'Variant MethodBind1<P1>::call(Object*, const Variant**, int, Variant::CallError&) [with P1 = char*]'
modules/mymodule/MYMODULE.cpp:48:1:   required from here
core/method_bind.h:63:10: error: conversion from 'const Variant' to 'char*' is ambiguous
   return p_variant;
          ^
In file included from core/object.h:33:0,
                 from core/reference.h:32,
                 from modules/mymodule/mymodule.h:4,
                 from modules/mymodule/MYMODULE.cpp:1:
core/variant.h:202:2: note: candidate: Variant::operator CharType() const <near match>
  operator CharType() const;
  ^
core/variant.h:202:2: note:   no known conversion from 'CharType {aka wchar_t}' to 'char*'
core/variant.h:195:2: note: candidate: Variant::operator uint64_t() const <near match>
  operator uint64_t() const;
  ^
core/variant.h:195:2: note:   no known conversion from 'uint64_t {aka long unsigned int}' to 'char*'
core/variant.h:194:2: note: candidate: Variant::operator int64_t() const <near match>
  operator int64_t() const;
  ^
core/variant.h:194:2: note:   no known conversion from 'int64_t {aka long int}' to 'char*'
core/variant.h:192:2: note: candidate: Variant::operator unsigned char() const <near match>
  operator unsigned char() const;
  ^
core/variant.h:192:2: note:   no known conversion from 'unsigned char' to 'char*'
core/variant.h:191:2: note: candidate: Variant::operator signed char() const <near match>
  operator signed char() const;
  ^
core/variant.h:191:2: note:   no known conversion from 'signed char' to 'char*'
core/variant.h:190:2: note: candidate: Variant::operator short unsigned int() const <near match>
  operator unsigned short() const;
  ^
core/variant.h:190:2: note:   no known conversion from 'short unsigned int' to 'char*'
core/variant.h:189:2: note: candidate: Variant::operator short int() const <near match>
  operator signed short() const;
  ^
core/variant.h:189:2: note:   no known conversion from 'short int' to 'char*'
core/variant.h:188:2: note: candidate: Variant::operator unsigned int() const <near match>
  operator unsigned int() const; // this is the real one
  ^
core/variant.h:188:2: note:   no known conversion from 'unsigned int' to 'char*'
core/variant.h:187:2: note: candidate: Variant::operator int() const <near match>
  operator signed int() const;
  ^
core/variant.h:187:2: note:   no known conversion from 'int' to 'char*'
scons: *** [modules/mymodule/MYMODULE.x11.tools.64.o] Error 1
scons: building terminated because of errors.

How can I start solving this?

Any help is appreciated.

Thank you in advance!

:bust_in_silhouette: Reply From: Zylann

Looks like you tried to store a char* in a Variant, however there is no explicit conversion allowing that, or there are multiple ambiguous matches. If you intented to store a string, you can write it as L"Constant string" or String(L"Godot string"). L is required because Godot works in wchar_t when it comes to characters, instead of char.

If it doesn’t helps solving your problem, I would need to see what you are trying to do in MYMODULE.cpp.

Hi Zylann, thank you for your answer.

Do you have an example, please?

MYMODULE.cpp, requires strings as parameters in some methods like in the constructor.

Thank you!

Not_a_Robot | 2016-09-01 13:13

You just jave to write L in front of your strings, because in Godot you have to work with strings based on wchar_t, not char. By default, when you write "test", the compiler will understand it as a const char*. If you write L"test", it will understand it as a const wchar_t*.

But if you need to pass those strings as parameter to functions or store them somewhere, you should instead use the String class, for example:

class Test {
public:
	Test(String name) {
		m_name = name;
	}
private:
	String m_name;
};

Test test(L"Antonin Dvorak")

Zylann | 2016-09-01 19:04

Hi Zylann! Thank you very much for your example code!

I’m trying to make a C++ wrapper for a C library like you did with GitHub - Zylann/godot_opensimplex: [NO LONGER MAINTAINED] Open simplex noise module for Godot

I’m getting " undefined reference to [C FUNCTION HERE]" messages when compiling the module. I guess that’s because I’m including the C library incorrectly.

Do you have any tips for me to start looking to accomplish that, please?

Thank you for all your work done here helping me and others :slight_smile:

Not_a_Robot | 2016-09-02 21:50

So far I’ve only included librarie’s source code inside modules, I never tried to link to a prebuilt one.
If you get this error it means the linker didn’t found the implementation of the function. If the function is yours, maybe you mispelled it or forgot to implement it.
Are you including a prebuilt library or did you included the sources to your module?

Zylann | 2016-09-03 00:46