Compiling Elmer in Windows 10 using Visual Studio

Discussion about building and installing Elmer
Post Reply
elmer_n00b
Posts: 3
Joined: 17 Mar 2024, 19:27
Antispam: Yes

Compiling Elmer in Windows 10 using Visual Studio

Post by elmer_n00b »

I am trying to use MS Visual Studio 2019 (windows 10) to edit & compile the source code. (I am not extremely software-savvy, so please correct me if i'm using incorrect terminology or if i'm misunderstanding something.)

TLDR;
Having trouble compiling Elmer in MSVS using the Mingw64-Debug configuration. Seems like some header files can't be found or there is some other issue surrounding the header files. Has anyone been able to compile the source code in Visual Studio? If so, what steps are required to make this work? If this is not possible or very difficult, why?

I've been successful in following the compilation instructions, using MSYS2 terminal with MinGW to compile the source code. (https://github.com/ElmerCSC/elmerfem/bl ... s-msys2.md)
I am trying to replicate the compilation process in MSVS 2019 since I plan to edit the source code and would rather do this in an IDE that can run Elmer in debug mode.

When i attempt to "build all" in Visual Studio, using the Mingw64-Debug configurations, I get many errors. Among them, I am getting 16 errors in matc\src\matrix.c saying that some math functions are undeclared:

Code: Select all

Error	G0DAE3095	'exp' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	554
Error	G162405AE	'acos' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	548
Error	G18A1A76C	'atan2' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	550
Error	G220463D1	'log10' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	556
Error	G46E5BD8D	'floor' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	559
Error	G485019DD	'sqrt' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	557
Error	G48F04A0C	'asin' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	547
Error	G5E2AEEE4	'atan' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	549
Error	G5FA84A0A	'ceil' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	558
Error	GAAA2AA8B	'log' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	555
Error	GBA859120	'tanh' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	553
Error	GBA8D9121	'sinh' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	551
Error	GBD558E68	'cosh' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	552
Error	GF2BD9120	'tan' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	546
Error	GF2C59121	'sin' undeclared (first use in this function); did you mean 'sign'?	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	544
Error	GF58D8E68	'cos' undeclared (first use in this function)	D:\elmerfem\out\build\Mingw64-Debug\elmerfem	D:\elmerfem\matc\src\matrix.c	545
Has anyone faced this same issue and been able to resolve?

I have tried modifying the CMakeSettings.JSON file to match the commands used in MSYS2, but I'm not confident about how i've done this (file attached).

In some cases, i also get this error message when attempting to build:

Code: Select all

Error (active)	E1696	cannot open source file "unistd.h"	libmatc.dll (matc\src\libmatc.dll) - Mingw64-Debug	D:\elmerfem\matc\src\elmer\matc.h	41	
I thought that maybe matc.h (which must be included in matrix.c, where these errors occur), is not able to find unistd.h. I also figured that if unistd.h cannot be found, then maybe matc.h also has difficulty finding the other included header files that should be in the same location (sorry if using incorrect / layman terminology). Because of this, I tried copying the following header files from my MinGW64 include folder (C:\msys64\mingw64\include) to the matc.h directory (D:\elmerfem\matc\src\elmer), where they can definitely be found regardless of my PATH variables:
- Ctype.h
- Math.h
- Setjmp.h
- Signal.h
- Stdarg.h
- Stdio.h
- Stdlib.h
- String.h
- Time.h
- Unistd.h
- Sys\types.h

Doing this changes nothing - i still get the same errors.
In case it helps, here are the other errors that i get (at the same time as the "undeclared" errors, above):

Code: Select all

Error (active)	E0018	expected a ')'	ElmerGrid.exe (elmergrid\src\ElmerGrid.exe) - Mingw64-Debug	C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\stdlib.h	722
Error (active)	E0020	identifier "pack" is undefined	ElmerGrid.exe (elmergrid\src\ElmerGrid.exe) - Mingw64-Debug	C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\limits.h	16
Error (active)	E0020	identifier "size_t" is undefined	ElmerGrid.exe (elmergrid\src\ElmerGrid.exe) - Mingw64-Debug	C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_wstdio.h	95
Error (active)	E0020	identifier "FILE" is undefined	ElmerGrid.exe (elmergrid\src\ElmerGrid.exe) - Mingw64-Debug	C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_wstdio.h	107
Error (active)	E0065	expected a ';'	ElmerGrid.exe (elmergrid\src\ElmerGrid.exe) - Mingw64-Debug	C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\vadefs.h	61
Error (active)	E0172	external/internal linkage conflict with previous declaration at line 110 of "C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt\stdio.h"	ElmerGrid.exe (elmergrid\src\ElmerGrid.exe) - Mingw64-Debug	C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt_wstring.h	161
Error (active)	E0757	variable "uintptr_t" is not a type name	ElmerGrid.exe (elmergrid\src\ElmerGrid.exe) - Mingw64-Debug	C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt.h	366
Error (active)	E0757	variable "__int64" is not a type name	ElmerGrid.exe (elmergrid\src\ElmerGrid.exe) - Mingw64-Debug	C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt.h	594
I actually get 199 occurrences of error code E0020 (identifier "___" is unidentified), where the blank is _MaxCount, _String, FILE, pack, size_t, or uintptr_t.
I have 22 errors with code E0018 ( expected a ')' ) and 53 errors with code E0065 ( expected a ';' ).
I also have 163 errors with code E0757 (variable "___" is not a type name), where the blank is __int64, size_t, or uintptr_t.

If there is any part of this that anyone understands or knows how to resolve, please let me know! I'm sure that i didn't provide all necessary information, so please ask for more info where needed.

Thanks!
Attachments
CMakeSettings.json
(4.51 KiB) Downloaded 6 times
Masahiro_Akizuki
Posts: 16
Joined: 27 Feb 2024, 00:09
Antispam: Yes

Re: Compiling Elmer in Windows 10 using Visual Studio

Post by Masahiro_Akizuki »

Compiling on Windows may be challenging. If you have sufficient RAM, the Linux environment in WSL (Windows Subsystem for Linux) is comfortable. I created a Elmer WSL distribution based on Debian 12, so I believe the quickest way is to customize it by adding the necessary features.

https://www.elmerfem.org/forum/viewtopic.php?t=8195
elmer_n00b
Posts: 3
Joined: 17 Mar 2024, 19:27
Antispam: Yes

Re: Compiling Elmer in Windows 10 using Visual Studio

Post by elmer_n00b »

Thanks Kevin. I saw that and already tried following some steps (replacing unistd.h with io.h) with no luck. I don't really understand how to implement some of the other suggestions or don't know if they're related to my issue - if any are, and i should try them, please let me know (along with any tips you can provide) and I'll definitely give that a try.
elmer_n00b
Posts: 3
Joined: 17 Mar 2024, 19:27
Antispam: Yes

Re: Compiling Elmer in Windows 10 using Visual Studio

Post by elmer_n00b »

Masahiro_Akizuki wrote: 18 Mar 2024, 09:59 Compiling on Windows may be challenging. If you have sufficient RAM, the Linux environment in WSL (Windows Subsystem for Linux) is comfortable. I created a Elmer WSL distribution based on Debian 12, so I believe the quickest way is to customize it by adding the necessary features.

https://www.elmerfem.org/forum/viewtopic.php?t=8195
Thank you Masahiro. I have a couple questions about that:
(1) can i easily compile EXE for Windows through WSL?
(2) I want to be able to run the source code (after I make edits) using a debugger, which is why i wanted to use Visual Studio. Is there any such solution if i use WSL?
(3) do i even need to be able to run the code in debug mode? or do many people who work on Elmer just compile and run the program without debug mode?
Masahiro_Akizuki
Posts: 16
Joined: 27 Feb 2024, 00:09
Antispam: Yes

Re: Compiling Elmer in Windows 10 using Visual Studio

Post by Masahiro_Akizuki »

1. WSL allows you to compile Linux binaries.
2. I recall that the previous Elmer Virtual Machine (based on Fedora 37) had a compilation script with debugging capabilities. This could serve as a useful reference.
3. In the current version, this buildelmer script disables debugging mode by commenting out line 45: “#PRECACHE="$BASE/debug.cmake”. So, Debug mode appears to be used infrequently.

Best Regards, masahiro
Attachments
buildelmer.sh_Ubunt22.txt
from Elmer VM
(4.57 KiB) Downloaded 7 times
Post Reply