c++fltkgmsh

FLTK library Link Error 2019 when compiling GMSH with GUI with (unresolved external symbol "main")


When trying to compile GMSH (https://gitlab.onelab.info/gmsh/gmsh/), I face this error:

fltkd.lib(fl_call_main.c.obj) : error LNK2019: unresolved external symbol main referenced in function WinMain [\gmsh.vcxproj] \gmsh.exe:

fatal error LNK1120: 1 unresolved externals [\gmsh.vcxproj]

The FLTK library is compiled directly from its repository (https://github.com/fltk/fltk/) without errors.

The compilations of both repositories are performed by MSVC in Windows.

I think the linker can't resolve the call to "main" in "fl_call_main.c".

Does anyone know what I can do to resolve this issue?

OS: Windows 11
Compiler: MSVC (VS 2022)


Solution

  • FLTK provides a standard Windows WinMain() entry point in fl_call_main.c, as you (@Saeid) found out, and this entry point eventually calls main(). In FLTK 1.4 (Git) "wide arguments" (i.e. Unicode characters outside the ASCII range) are converted inside this function to the appropriate UTF-8 encoding, which is exactly what the wmain() function of Gmsh would do. I'm not sure whether FLTK 1.3 is up-to-date with this conversion but you wrote that you compiled FLTK from git which is 1.4 by default.

    There should be no side effects if you let FLTK do the conversion job in its fl_call_main.c module (i.e. use #if 0 as you wrote in a comment) or if you don't use "Wide Character" arguments on the commandline. Note that under current Windows versions all characters on the commandline that are not in the ASCII character set (Unicode codepoints 0x00 to 0x7F), e.g. filenames, are represented by Windows Wide Characters and need this conversion.

    Note also that fl_call_main.c can only be used in static (and maybe in debug) builds (not sure about the latter).

    So far the details from the FLTK side. I can't help with Gmsh specific stuff though, for instance why and how wmain() would be compiled and called.