[Gmsh] Build the mesh in my own program

Christophe Geuzaine cgeuzaine at ulg.ac.be
Wed Oct 6 21:26:47 CEST 2010

On 04/10/10 07:32, Mikhail Artemiev wrote:
> Hi everybody once more!
> Now I am ready to share my experience to use Gmsh functions in my own
> program.
> Thank to Mikhail Titov's advice I found in utils/api_demos the examples
> of using Gmsh API.
> Then I found in Gmsh reference manual this text:
> <<Finally, to use Gmsh at the third level (i.e., to link the Gmsh
> library with your own code),
> you will need to learn the internal Gmsh Application Programming
> Interface (API). No
> complete documentation of this API is available yet; a good starting
> point is Section C.2
> [Source code structure], page 185, which gives a short introduction to
> Gmsh's internal source
> code structure. Then have a look e.g. at the examples in the
> 'utils/api_demos/' directory
> in the source code. Due to the many possible configuration options (and
> associated external
> dependencies), we currently do not distibute precompiled versions of the
> Gmsh library.
> To build the library see the instructions in the top-level 'README.txt'
> file in the source
> distribution.>>
> Ok, cmake was downloaded and after some torture Gmsh.exe, Gmsh.dll and
> Gmsh.lib was created.
> Then I included Gmsh.lib in my Visual Studio project
> (Properties->Linker->Input->Additional Dependencies) where I had only
> one cpp-file (mainSimple.cpp from utils\api_demos):
> #include <stdio.h>
> #include <gmsh/Gmsh.h>
> #include <gmsh/GModel.h>
> #include <gmsh/MElement.h>
> int main(int argc, char **argv)
> {
> GmshInitialize(argc, argv);
> //GmshSetOption("Mesh", "Algorithm", 5);
> GModel *m = new GModel();
> m->readGEO("../../tutorial/t5.geo");
> //GmshMergeFile("../../tutorial/t5.geo"); // will also set the bbox
> m->mesh(3);
> for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); ++it){
> GRegion *r = *it;
> printf("volume %d contains %d elements:\n", r->tag(),
> r->getNumMeshElements());
> for(unsigned int i = 0; i < r->getNumMeshElements(); i++)
> printf(" %d", r->getMeshElement(i)->getNum());
> printf("\n");
> }
> m->writeMSH("test.msh");
> m->writeUNV("test.unv");
> delete m;
> GmshFinalize();
> }
> After compilation I have 1225 errors like these:
> Description File Project
> Error 1 error LNK2001: unresolved external symbol "public: static int
> __cdecl Fl::check(void)" (?check at Fl@@SAHXZ) Gmsh.lib delme
> Error 5 error LNK2001: unresolved external symbol "void __cdecl
> fl_alert(char const *,...)" (?fl_alert@@YAXPBDZZ) Gmsh.lib delme
> et cetera

Hi Mikhail - Then for some reason cmake detected that you had the fltk 
lib installed, but fails to get symbols from it.

I suggest to configure the gmsh lib with a minimal set of dependencies 
(uncheck all the optional packages in the cmake config), and see if this 

> If I delete Gmsh.lib from 'Additional Dependencies', after compilation I
> have 8 errors like these:
> Description File Project
> Error 4 error LNK2001: unresolved external symbol "public: int
> __thiscall GModel::mesh(int)" (?mesh at GModel@@QAEHH at Z) main.obj delme
> Error 7 error LNK2001: unresolved external symbol "int __cdecl
> GmshFinalize(void)" (?GmshFinalize@@YAHXZ) main.obj delme
> et cetera
> In first case I tried to include a fltk library (I thought that 'Fl'
> means a part of 'fltk'), but I miscarried.
> Because of <<no complete documentation of this API is available yet>>
> can anybody help me?
> Thanks
> Mikhail Artemiev, PhD student, NSTU
>> Mikhail Titov:
>> I would suggest to communicate with Gmsh using network. Take a look at
>> the
>> source code. It has a couple of nice examples in utils/solvers
>> subfolder. It
>> will definitely save some time since you can reuse existing instance
>> instead
>> of launching new process every time.
>> IMHO it would be the last resort to link gmsh code in.
>> Mikhail
> _______________________________________________
> gmsh mailing list
> gmsh at geuz.org
> http://www.geuz.org/mailman/listinfo/gmsh

Prof. Christophe Geuzaine
University of Liege, Electrical Engineering and Computer Science