Hey all!
I’m recently started to learn fortran and I’m still learning, so please bear with me. I want use the gmsh Fortran API and since I really like the user friendliness of fpm, I’m trying to set up my project with using gmsh-fpm. Sadly I run into various problem, some of which I think I found a solution. Here is a rundown of what I tried.
First I start a new project.
fpm new my_gmsh_project
next I added the dependency to the fpm.toml just like the github readme tells me
[dependencies]
gmsh-fpm = { git="https://github.com/gnikit/gmsh-fpm.git" }
I also downloaded the newest version of the gmsh sdk from here
Then I try to build the project the first time using
fpm build --link-flag "-LC:\Thomas\Programme\gmsh-4.11.1-sdk\lib"
But I get an error, while fpm is pulling the gmsh-fpm repository:
<ERROR> *cmd_build* Model error: Dependency name 'gmsh' found, but expected 'gmsh-fpm' instead
STOP 1
Kinda weird, but let’s try to change ‘gmsh-fpm’ to ‘gmsh’ in the .toml file and try again. This time fpm was succesful. In build/depedencies I can see the downloaded repository ‘gmsh’ (also the duplicate gmsh-fpm from the first try compiling. I deleted this one).
Seems like I’m almost done, however when I try to actually use the API, an error occures and I can’t figure out the reason. Here is my small program
program main
use, intrinsic :: iso_c_binding
use gmsh
implicit none
type(gmsh_t) :: gmsh
! Before using any functions in the Python API, Gmsh must be initialized:
call gmsh%initialize()
! This should be called when you are done using the Gmsh Python API:
call gmsh%finalize()
end program main
Just start and close gmsh. Nothing to fancy. And here is the error I get:
PS C:\Thomas\FortranTest\my_gmsh_project> fpm run --link-flag "-LC:\Thomas\Programme\gmsh-4.11.1-sdk\lib"
gmsh.f90 done.
libmy_gmsh_project.a done.
main.f90 done.
my_gmsh_project.exe failed.
[100%] Compiling...
C:/Program Files/gcc/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build\gfortran_50F62D7499E64B65\my_gmsh_project\libmy_gmsh_project.a(build_dependencies_gmsh_src_gmsh.f90.o): in function `__gmsh_MOD_gmshmodelmeshgetvisibility':
C:\Thomas\FortranTest\my_gmsh_project/build/dependencies/gmsh/src/gmsh.f90:7107: undefined reference to `gmshModelMeshGetVisibility'
C:/Program Files/gcc/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build\gfortran_50F62D7499E64B65\my_gmsh_project\libmy_gmsh_project.a(build_dependencies_gmsh_src_gmsh.f90.o): in function `__gmsh_MOD_gmshmodelmeshcomputerenumbering':
C:\Thomas\FortranTest\my_gmsh_project/build/dependencies/gmsh/src/gmsh.f90:6588: undefined reference to `gmshModelMeshComputeRenumbering'
C:/Program Files/gcc/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build\gfortran_50F62D7499E64B65\my_gmsh_project\libmy_gmsh_project.a(build_dependencies_gmsh_src_gmsh.f90.o): in function `__gmsh_MOD_gmshmodelgetentitiesforphysicalname':
C:\Thomas\FortranTest\my_gmsh_project/build/dependencies/gmsh/src/gmsh.f90:1550: undefined reference to `gmshModelGetEntitiesForPhysicalName'
collect2.exe: error: ld returned 1 exit status
<ERROR> Compilation failed for object " my_gmsh_project.exe "
<ERROR> stopping due to failed compilation
STOP 1
And with this error I’m stumped. It seems really weird, because I can find these procedures in the gmsh.f90 file of the dependecy, but somehow they are gone, when building? Or does the error occure, because fpm can’t find these references while linking to the gmsh sdk?
If you need additional information, let me know.