Beef
Beef copied to clipboard
Unresolved external symbol for internal comptime generated method
BeefBuild -run
Scarab__.lib(Scarab_Core_CommandHandler.obj) : error LNK2019: Verweis auf nicht aufgel�stes externes Symbol ""public: static class bf::System::String * bf::Scarab::Commands::ListDirectories::Name" (?Name@ListDirectories@Commands@Scarab@bf@@2PEAVString@System@4@A)" in Funktion ""public: static bool __cdecl bf::Scarab::Core::CommandHandler::HandleBuildIn(class bf::Common::Args *,class bf::Scarab::Scarab *)" (?HandleBuildIn@CommandHandler@Core@Scarab@bf@@SA_NPEAVArgs@Common@4@PEAVScarab@34@@Z)".
c:\Users\b\Downloads\scarab\build\Debug_Win64\Scarab\Scarab.exe : fatal error LNK1120: 1 nicht aufgel�ste Externe
Execution Failed
ERROR: BUILD FAILED. Total build time: 1.03s
Attempting to build my current Project will throw this error, which seemingly occurs by it missing a comptime function. There is no visible syntax error in the IDE. This will always happen until the Name field is manually added once. After that it can be commented out and it will work as expected until clean is called.
I wasnt able to replicate this on a smaller scale.
Scarab.zip
Doing BeefBuild update and BeefBuild run should replicate this error message
Code explanation for faster understanding/debugging of this error
src/Commands/ScarabCommandAttribute.bf
[AttributeUsage(.Class)]
struct ScarabCommandAttribute : this(StringView Name), Attribute, IOnTypeInit
{
[Comptime]
public void OnTypeInit(Type type, Self* prev)
{
if (type.GetField("Name") case .Err)
Compiler.EmitTypeBody(type, scope $"public static String Name = \"{this.Name}\";");
Compiler.EmitAddInterface(type, typeof(IScarabCommand));
}
}
Create the Name field on a command via the attribute
scr/Core/CommandHandler.bf
for (var type in Type.TypeDeclarations)
{
if (!type.HasCustomAttribute<Scarab.Commands.ScarabCommandAttribute>())
continue;
if (!type.ResolvedType.ImplementsInterface(typeof(Scarab.Commands.IScarabCommand)))
continue;
var name = type.GetFullName(.. scope .());
func.Append(scope $"""
case {name}.Name:
return {name}.Call(parameters, instance);
""");
}
Create a function that maps this Name field to the switch statement cases