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

Windows 10 Visual Studio 2015 build: LNK2019 with WrappedMethod1, register_class, and register_method. #12

Closed
willnationsdev opened this issue Jun 21, 2017 · 11 comments

Comments

@willnationsdev
Copy link
Contributor

willnationsdev commented Jun 21, 2017

Context:

Windows 10
Visual Studio 2015 Community Edition
All command line operations executed using "Visual Studio x64 Native Tools Command Prompt"

Issue:

Got all the way through the tutorial on the README.md up to the clang operations. Built a VS project for DLLs and got to the Linker stage, but started running into issues.

Reproducible Steps:

  1. Initial Directory Structure
    . (Current folder)
    = godot (the actual godot engine fork)
    == bin
    = gdtest (the "test" folder we'll be operating in)
    == cpp_bindings (just cloned)
    == godot_headers (just cloned)
    == lib (empty)
    == src (empty)

  2. Go into cpp_bindings, open SConstruct file, change the godot_bin_path and godot_lib_path variables to each have as their value: "../../godot/bin/"

  3. From the cpp_bindings (executes successfully, creating godot_cpp_core.lib/.exp/.dll in cpp_bindings/bin):

    $ scons p=windows

  4. From the cpp_bindings (executes successfully, creating godot_cpp_bindings.lib/.exp/.dll in cpp_bindings/bin):

    $ scons p=windows target=bindings generate_bindings=yes

  5. Open visual studio. File > New > Project... . Select Win32 Application, project name gdtestdll, location is the gdtest directory. Checkbox "Create directory for solution". Select "Next" in the Win32 Application Wizard. Select DLL. Click the "Empty Project" checkbox. Click "Finish".

  6. Right Click "Source Files" in Solution Explorer, Add.. > New item. C++ source file called "init.cpp" to be placed in the project directory (gdnative/gdtestdll/gdtestdll). Copy/Paste the contents of the GitHub version into the file.

  7. Right Click "gdtestdll" in the Solution Explorer, Properties. Ensure that you are using All Configurations and All Platforms at the top.

  • VC++ Directories > Include Directories. Add the path at "gdtest/cpp_bindings/include" and "gdtest/godot_headers"
  • VC++ Directories > Library Directories. Add the path at "gdtest/cpp_bindings/bin"
  • Linker > Input > Additional Dependencies. Add "godot_cpp_code.lib" and "godot_cpp_bindings.lib"
  1. Update various path differences
  • Godot.hpp: lines 10, 11, 12, and 16 need "core/" prepended to the include. That is CoreTypes, Variant, Ref, and GodotGlobal.
  • Object.hpp: lines 17 and 18 need "core/" prepended to the include. That is CoreTypes and Ref.
  • Reference.hpp: lines 17 and 18 need "core/" prepended to the include. That is CoreTypes and Ref.
  1. Remove warnings:
  • transform2d.hpp: line 21, "class Rect2" changed to "struct Rect2" to maintain consistency with previous declaration.
  • transform2d.hpp: line 23, "struct GD_CPP_CORE_API Transform2D {" changed to a class with a "public:" placed right underneath it (for visibility) to maintain consistency with previous declaration.
  1. Change build target to be Debug x64 instead of Debug x86. Removes half of the linker errors.

Remaining errors in the Visual Studio Output:

Error	LNK2019	unresolved external symbol __imp_godot_variant_new_nil referenced in function "public: static struct godot_variant __cdecl godot::_WrappedMethod1<class SimpleClass,class godot::Variant,class godot::Variant>::__wrapped_method(void *,void *,void *,int,struct godot_variant * *)" (?__wrapped_method@?$_WrappedMethod1@VSimpleClass@@VVariant@godot@@V23@@godot@@SA?AUgodot_variant@@PEAX00HPEAPEAU3@@Z)	gdtestdll	D:\Source\GitHub\gdtest\gdtestdll\gdtestdll\init.obj	1	
Error	LNK2019	unresolved external symbol __imp_godot_script_register_class referenced in function "void __cdecl godot::register_class<class SimpleClass>(void)" (??$register_class@VSimpleClass@@@godot@@YAXXZ)	gdtestdll	D:\Source\GitHub\gdtest\gdtestdll\gdtestdll\init.obj	1	
Error	LNK2019	unresolved external symbol __imp_godot_script_register_method referenced in function "void __cdecl godot::register_method<class godot::Variant (__cdecl SimpleClass::*)(class godot::Variant)>(char *,class godot::Variant (__cdecl SimpleClass::*)(class godot::Variant),enum godot_method_rpc_mode)" (??$register_method@P8SimpleClass@@EAA?AVVariant@godot@@V23@@Z@godot@@YAXPEADP8SimpleClass@@EAA?AVVariant@0@V20@@ZW4godot_method_rpc_mode@@@Z)	gdtestdll	D:\Source\GitHub\gdtest\gdtestdll\gdtestdll\init.obj	1	
Error	LNK1120	3 unresolved externals	gdtestdll	D:\Source\GitHub\gdtest\gdtestdll\x64\Debug\gdtestdll.dll	1	
@willnationsdev
Copy link
Contributor Author

gdtest.zip

@willnationsdev
Copy link
Contributor Author

I'm GUESSING the cause of the issue comes from the need for step 8 in the first place...? I tried re-generating the bindings and they result in content that is naturally positioned at the wrong #include path. Either that's just a separate bug, or it's causing issues in the linking somehow(?).

@RameshRavone
Copy link
Contributor

RameshRavone commented Jun 21, 2017

Well as for me I thing this happens with .dll don't a thing about windows 😜 ,since when @karroffel announced GDNative the StarterKit contained a .lib

Linux rules 🐧

@willnationsdev
Copy link
Contributor Author

willnationsdev commented Jun 21, 2017

godot_cpp_starter_kit.zip
But there are 2 .dll files sitting in the top directory...? What's more, the binding occurs through a dynamically-linked library which on windows is done via a .dll (I think Linux has .so or something). Without a .dll, you aren't dynamically linking anything. You just have an import table in the .lib and header files all without the actual implementations.

@RameshRavone
Copy link
Contributor

RameshRavone commented Jun 21, 2017

Well I was taking about these guys, didn't look at the root..! and are you including godot.windows.opt.tools.64 to the linking..!

screenshot from 2017-06-21 10-42-59
since those functions are implemented only in the gdnative module's, and when i look into Sconstruct file it is included at line 38

@karroffel
Copy link
Contributor

Hey @willnationsdev , thanks for trying this out!

  1. is a problem with your 7). You need to add cpp_bindings/include and cpp_bindings/include/core to the include path.

Furthermore you need to place the dlls (at least the ones from the c++ bindings) in the project root. That's because of a limitation in windows. In Linux it can access dependent dlls in a subdirectory with no sweat, windows doesn't have this feature.

@willnationsdev
Copy link
Contributor Author

willnationsdev commented Jun 21, 2017

Okay, so I put godot_headers, cpp_bindings/include and cpp_bindings/include/core to the include path and it caused me to not have to do step 8, as you predicted (makes sense).

I then added both gdtest/gdtestdll (where the .sln is) and gdtest/gdtestdll/gdtestdll (where my init.cpp is) to my library path and tried building with all 6 files (.lib/.dll/.exp for core/bindings) either in one directory or the other. Neither of them worked.

Do I need to have the godot.windows.opt.tools.64.lib thing? Because the SConstruct in my cpp_bindings directory never mentions it.

@karroffel
Copy link
Contributor

I think you only need to link the .lib files. All three of them though.

For "just get it running" you could dump everything in the project root, all the dll and lib files and see if it works.

@willnationsdev
Copy link
Contributor Author

willnationsdev commented Jun 21, 2017

Yeah, that's what I did.

I tried it with the project root (where my .sln is) and the source root (where my .cpp is). In each location, I had the following files:

godot_cpp_core.dll
godot_cpp_core.exp
godot_cpp_core.lib
godot_cpp_bindings.dll
godot_cpp_bindings.exp
godot_cpp_bindings.lib

I tried it first one way, and then the other way (I never had all 6 files in both locations at once).

There are not 3 .lib files though. Nowhere during my process is a godot.windows.opt.tools.64.lib file ever generated. How am I supposed to get that aside from just stealing the one in the starter kit?

Edit:
When I try copy/pasting the starter kit version of the godot.windows.opt.tools.64.lib file into the given directory (again, I tried it with all of them in both places), it still doesn't link successfully.

@willnationsdev
Copy link
Contributor Author

willnationsdev commented Jun 21, 2017

Ah! It finally worked! I accidentally didn't add godot.windows.opt.tools.64.lib to my Linker > Input > Additional Dependencies properties.

I ended up having everything placed directly into gdtest/gdtestdll/gdtestdll alongside my init.cpp file.

However, we still need to make it clear how someone is supposed to get that .lib aside from just downloading it from the starter kit. Shouldn't it be retrievable or generatable from the cpp_bindings repo?

I'm going to tinker around with actually getting it included and running in a Godot project and update you all.

@karroffel
Copy link
Contributor

@willnationsdev that starter kit is ouuuuutdated by the way, don't use it 😄

This will be a lot easier once we have a version we can agree on and distribute binaries.

BastiaanOlij pushed a commit to BastiaanOlij/godot-cpp that referenced this issue Sep 4, 2021
mashumafi pushed a commit to mashumafi/godot-cpp that referenced this issue Feb 3, 2023
pattlebass pushed a commit to pattlebass/grafic-gdextension that referenced this issue May 10, 2024
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

3 participants