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

Issues Using on Windows #117

Closed
andrewM202 opened this issue Jul 16, 2023 · 10 comments
Closed

Issues Using on Windows #117

andrewM202 opened this issue Jul 16, 2023 · 10 comments

Comments

@andrewM202
Copy link

Hello! I have been trying to get FastNoise2 to work on Windows but am new to the C++ build process - I have been able to get it to successfully work on MacOS. Please let me know if my question is better asked on Discord or elsewhere. Currently I have been trying to use VSCode's build tools with FastNoise's precompiled binaries for Clang. The build tools as I have them setup generate this command that runs to build the executable:

g++ -std=c++17 -fdiagnostics-color=always -g -IC:\Users\hilfu\Desktop\Code\minecraft-opengl/dependencies/include -LC:\Users\hilfu\Desktop\Code\minecraft-opengl/dependencies/library_windows C:\Users\hilfu\Desktop\Code\minecraft-opengl/dependencies/library_windows/FastNoise.lib C:\Users\hilfu\Desktop\Code\minecraft-opengl/*.cpp C:\Users\hilfu\Desktop\Code\minecraft-opengl/glad.c -lglfw3dll -lFastNoise -lFastNoiseD -o C:\Users\hilfu\Desktop\Code\minecraft-opengl/app

However, this fails with many undefined reference errors, making me think the dlls or .lib files are not linking correctly:

C:/Users/hilfu/Desktop/Code/minecraft-opengl/dependencies/include/FastNoise/FastNoise.h:34: undefined reference to FastNoise::Add* FastSIMD::New<FastNoise::Add>(FastSIMD::eLevel, void* (*)(unsigned long long, unsigned long long))'

For reference, attached below is an image of my current file structure. I have also tried using the clang++ compiler instead of g++, but got different errors (which if needed I can try to reproduce again and attach here). If there is any additional information needed to help resolve this, or if there is anything obvious I missed in my inexperience, please let me know. I am hoping I won't have to use FastNoiseLite just for windows!
image

@Auburn
Copy link
Owner

Auburn commented Jul 17, 2023

You should use either -lFastNoise or -lFastNoiseD (debug) not both. Your library link folder also looks wrong it should be -LC:\Users\hilfu\Desktop\Code\minecraft-opengl\dependencies\library_windows

@andrewM202
Copy link
Author

Thank-you for the input! I have gotten rid of the debug file and fixed the link library folder so it only uses backslashes now, however I seem to still be getting the same undefined reference errors. I also tried forward slashes with no luck. Here is how the command looks now:

g++ -std=c++17 -fdiagnostics-color=always -g -IC:\Users\hilfu\Desktop\Code\minecraft-opengl\dependencies\include -LC:\Users\hilfu\Desktop\Code\minecraft-opengl\dependencies\library_windows C:\Users\hilfu\Desktop\Code\minecraft-opengl\dependencies\library_windows\FastNoise.lib C:\Users\hilfu\Desktop\Code\minecraft-opengl\*.cpp C:\Users\hilfu\Desktop\Code\minecraft-opengl\glad.c -lglfw3dll -lFastNoise -o C:\Users\hilfu\Desktop\Code\minecraft-opengl\app

In case it may help I've also dropped here the full error stack as a txt file when running the command. Thank-you for your help.
full_undefined_error.txt

@Auburn
Copy link
Owner

Auburn commented Jul 17, 2023

I assume you are using minGW? I don't think MSVC compiled libs are compatible with MinGW

@andrewM202
Copy link
Author

andrewM202 commented Jul 17, 2023

It looks like g++ is mingw, I see that would not work then. I was mostly hoping it would because g++ worked with the MacOS clang binaries, but it seems Clang is different from ClangCL. If I switch my project to use ClangCL (with the clang++ command) that should work with the binaries highlighted below then, right? If not I was thinking maybe I should try to port my code over to visual studio since the wiki example uses that and MSVC is used by Visual Studio from what I can tell
image

@Auburn
Copy link
Owner

Auburn commented Jul 17, 2023

That should work, you will have to use Clang++ outside of MinGW in order to be ABI compatible with the FastNoise2 libs. Alternatively you could compile FastNoise2 libs yourself for Clang on MinGW if you do want to go that route.

GCC MinGW is not supported: #69

@andrewM202
Copy link
Author

Thanks for the suggestion to compile on MinGW! It looks like it worked, I have some other errors in my code but I don't seem to be getting any undefined reference errors anymore, once I get my program fully working shortly and fix these seemingly unrelated errors I'll confirm it definitely worked.

I actually tried to compile the source before using the wiki, but I only noticed now by default it was compiling for Visual Studio (and thus likely for MSVC)! I used this command so it uses the GCC and G++ compilers/MinGW, and was able to get it to work for the project setup portion:

cmake -G "MinGW Makefiles" -S . -B build -D FASTNOISE2_NOISETOOL=OFF -D FASTNOISE2_TESTS=OFF -D BUILD_SHARED_LIBS=ON -D CMAKE_CXX_COMPILER="C:/Users/hilfu/Documents/mingw64/bin/g++.exe" -D CMAKE_C_COMPILER="C:/Users/hilfu/Documents/mingw64/bin/gcc.exe"

image

It may be useful to add a note to this wiki page (linked here) that you'll need to add -G "MinGW MakeFiles and the extra options for the CMAKE_CXX_COMPILER and CMAKE_C_COMPILER to compile it for mingw.

Thanks for your help again!

@andrewM202
Copy link
Author

andrewM202 commented Jul 18, 2023

Ah, unfortunately I misread and you are right - I got no linker errors compiling with g++ but the program crashes when ran with any FastNoise2 command that actually generates noise.

I have since tried using clang++ instead with the LLVM toolchain, and get no linker errors, but for some reason instead get this error when running program:
image

However, when compiling with clang I don't even get a libFastNoise.dll (image of resulting build files below) so not sure where that is coming from.

image

Here is also the updated command I am running to make my executable:

clang++ -std=c++17 -fdiagnostics-color=always -g -IC:\Users\hilfu\Desktop\Code\minecraft-opengl\dependencies\include -LC:\Users\hilfu\Desktop\Code\minecraft-opengl\dependencies\library_windows C:\Users\hilfu\Desktop\Code\minecraft-opengl\dependencies\library_windows\glfw3dll.lib C:\Users\hilfu\Desktop\Code\minecraft-opengl\dependencies\library_windows\FastNoiseD.lib C:\Users\hilfu\Desktop\Code\minecraft-opengl\*.cpp C:\Users\hilfu\Desktop\Code\minecraft-opengl\glad.c -lglfw3dll -lFastNoiseD -o C:\Users\hilfu\Desktop\Code\minecraft-opengl\app

On another note, for some reason when I compile the FastNoise2 source with clang I cannot get the release version only the debug version but I don't think that should matter. I might need to mess around with this a bit more to see if I can get this to work.
image

@Auburn
Copy link
Owner

Auburn commented Jul 18, 2023

When using CMake with a single config generator like MinGW you need to specify -D CMAKE_BUILD_TYPE=Release at the CMake generate stage (before you build). Make sure you clear out the CMake generated build folder before switching compilers/configs

@andrewM202
Copy link
Author

andrewM202 commented Jul 18, 2023

Aaahhhh! There we go! For some reason the terrain is see-through (will have to figure that one out lol some other weird windows bug Im sure) but it does look to be generating now with the FastNoise2 noise on windows hah. Thanks so much for all the help Auburn!
image

Just for reference, I was able to build FastNoise fully like you suggested in the release mode with this command:
cmake -G "Ninja" -S . -B build -D FASTNOISE2_NOISETOOL=OFF -D FASTNOISE2_TESTS=OFF -D BUILD_SHARED_LIBS=ON -D CMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" -D CMAKE_C_COMPILER="C:/Program Files/LLVM/bin/clang.exe" -D CMAKE_BUILD_TYPE=Release

I realized that libFastNoise.dll error was because I was building my project with -o app which built an app.exe with g++, but which only build an app file with clang++. So I was effectively running an old app.exe. After fixing that and rebuilding with the new DLLs it looks like it is working!

Before I close this, I wanted to ask if you would like me to create a pull request with this information on how to build for clang in the wiki. Thanks for all the help again!

@Auburn
Copy link
Owner

Auburn commented Jul 19, 2023

Thanks, I don't think you can PR stuff for the wiki, it's not part of the repo

@Auburn Auburn closed this as completed Jul 19, 2023
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

2 participants