Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unresolved external symbol for internal comptime generated method #2210

Open
Booklordofthedings opened this issue Apr 3, 2025 · 0 comments

Comments

@Booklordofthedings
Copy link
Contributor

 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant