vmagnin / gtk-fortran

A GTK / Fortran binding. The documentation is in the Wiki tab.
GNU General Public License v3.0
251 stars 43 forks source link

fpm and Plplot with gtk3/4: "multiple definition of `main'" error (support needed) #284

Open lllaxmatist opened 3 months ago

lllaxmatist commented 3 months ago

When try to compile project with PLplot support i get errors both on windows and on Linux. (without inclusion of Plplot project runs perfect)

Errors on MSYS2:
lllax@LAPTOP-KVC9DPIV UCRT64 /home/FPMprojects/circle_fpm
$   fpm run --flag "$(pkg-config --cflags --libs plplot plplot-fortran)"
circle_fpm.f90                         done.
circle_fpm.exe                         failed.
[100%] Compiling...
D:/Programs/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build\gfortran_B17540FEB7ADF59B\circle_fpm\app_circle_fpm.f90.o
:circle_fpm.f90:(.text+0x1254): multiple definition of `main'; D:/Programs/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../lib/libmingw32.a(lib64_libmingw
32_a-crtexewin.o):C:/M/B/src/mingw-w64/mingw-w64-crt/crt/crtexewin.c:23: first defined here
D:/Programs/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: D:/Programs/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2
.0/../../../../lib/libmingw32.a(lib64_libmingw32_a-crtexewin.o): in function `main':
C:/M/B/src/mingw-w64/mingw-w64-crt/crt/crtexewin.c:67:(.text.startup+0xbd): undefined reference to `WinMain'
D:/Programs/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build\gfortran_0913D9F560CF5CAD\circle_fpm\libcircle_fpm.a(buil
d_dependencies_gtk-fortran_src_gtk-draw-hl.f90.o):gtk-draw-hl.f9:(.text+0x507): undefined reference to `gdk_cairo_set_source_pixbuf'
D:/Programs/MSYS2/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: build\gfortran_0913D9F560CF5CAD\circle_fpm\libcircle_fpm.a(buil
d_dependencies_gtk-fortran_src_gtk-draw-hl.f90.o):gtk-draw-hl.f9:(.text+0x663): undefined reference to `gdk_pixbuf_get_from_surface'
collect2.exe: error: ld returned 1 exit status
<ERROR> Compilation failed for object " circle_fpm.exe "
<ERROR> stopping due to failed compilation
STOP 1

If i exclude all plplot from code (comment out, only usage of plplot remain) the erors keeps in code.

p.s. : On Linux i get different errors (ill paste it as i get to my PC in next post).

p.p.s. : I do need only simple 2d plots, maybe there is alternative lib to use instead?

vmagnin commented 3 months ago

Concerning using plplot with fpm and gtk-fortran see: https://github.com/vmagnin/gtk-fortran/wiki/Tutorial-5

In that tutorial, I used single quotes:

$  fpm run --flag '$(pkg-config --cflags --libs plplot plplot-fortran)'

Can you try with single quotes? (to avoid the expansion of $() before it is transmitted to the compiler)

For alternative plotting programs, see: https://github.com/vmagnin/gtk-fortran/wiki/Alternatives-to-gtk-fortran Maybe ogpf?

lllaxmatist commented 3 months ago

Double quotes is MSYS2 thing, because winfows dislike single ones much.

vmagnin commented 3 months ago

MSYS2 offers you a bash environment and single/double quotes have the same behaviour as in Linux. This is what I obtain in MSYS2:

$ echo '$(pkg-config --cflags --libs plplot plplot-fortran)'
$(pkg-config --cflags --libs plplot plplot-fortran)

$ echo "$(pkg-config --cflags --libs plplot plplot-fortran)"
-ID:/Logiciels/MSYS2/ucrt64/include/plplot -ID:/Logiciels/MSYS2/ucrt64/lib/fortran/modules/plplot -ID:/Logiciels/MSYS2/ucrt64/include/pango-1.0 -ID:/Logiciels/MSYS2/ucrt64/include/cairo -ID:/Logiciels/MSYS2/ucrt64/include/pixman-1 -ID:/Logiciels/MSYS2/ucrt64/include/fribidi -ID:/Logiciels/MSYS2/ucrt64/include/harfbuzz -ID:/Logiciels/MSYS2/ucrt64/include/freetype2 -ID:/Logiciels/MSYS2/ucrt64/include/libpng16 -ID:/Logiciels/MSYS2/ucrt64/include/glib-2.0 -ID:/Logiciels/MSYS2/ucrt64/lib/glib-2.0/include -DQT_CORE_LIB -ID:/Logiciels/MSYS2/ucrt64/include/QtCore -DQT_GUI_LIB -ID:/Logiciels/MSYS2/ucrt64/include/QtGui -DQT_PRINTSUPPORT_LIB -ID:/Logiciels/MSYS2/ucrt64/include/QtPrintSupport -DQT_WIDGETS_LIB -ID:/Logiciels/MSYS2/ucrt64/include/QtWidgets -DQT_SVG_LIB -ID:/Logiciels/MSYS2/ucrt64/include/QtSvg -DHPDF_DLL -ID:/Logiciels/MSYS2/ucrt64/lib/wx/include/msw-unicode-3.2 -ID:/Logiciels/MSYS2/ucrt64/include/wx-3.2 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__ -DUNICODE -D_UNICODE -lplplotfortran -lplplot -lpangocairo-1.0.dll -lpango-1.0.dll -lgobject-2.0.dll -lglib-2.0.dll -lintl.dll -lharfbuzz.dll -lcairo.dll -lgd.dll -lpng.dll -lz.dll -ljpeg.dll -ltcl.dll -ltk.dll -pipe -Wl,--subsystem,windows -mwindows -lwx_baseu-3.2.dll -lwx_mswu_core-3.2.dll -lhpdf.dll -lgdi32 -lcomdlg32 -lcomctl32 -lshp.dll -lfreetype.dll -lQt5Core.dll -lQt5Gui.dll -lQt5PrintSupport.dll -lQt5Widgets.dll -lQt5Svg.dll -lcsirocsa -lcsironn -lqhull -lqsastime -lstdc++.dll -LD:/Logiciels/MSYS2/ucrt64/lib/gcc/x86_64-w64-mingw32/13.2.0 -lpthread.dll -ladvapi32 -lshell32 -luser32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lkernel32

As you can see, nothing is evaluated in a single quotes string. With double quotes, the $(...) expression is expanded.

Be sure that on your keyboard you use the vertical single quote.

lllaxmatist commented 3 months ago

But with single ones i get:

`
lllax@LAPTOP-KVC9DPIV UCRT64 /home/FPMprojects/circle_fpm
$   fpm run --flag '$(pkg-config --cflags --libs plplot plplot-fortran)'
plplot_extra.f90                       failed.
gdk-auto.f90                           failed.
gdk-pixbuf-auto.f90                    failed.
glib-auto.f90                          failed.
cairo-auto.f90                         failed.
[ 19%] Compiling...
gfortran: error: unrecognized command-line option '--cflags'
gfortran: error: unrecognized command-line option '--libs'; did you mean '--libs='?
gfortran: error: unrecognized command-line option '--cflags'
gfortran: error: unrecognized command-line option '--libs'; did you mean '--libs='?
gfortran: error: unrecognized command-line option '--cflags'
gfortran: error: unrecognized command-line option '--libs'; did you mean '--libs='?
gfortran: error: unrecognized command-line option '--cflags'
gfortran: error: unrecognized command-line option '--libs'; did you mean '--libs='?
gfortran: error: unrecognized command-line option '--cflags'
gfortran: error: unrecognized command-line option '--libs'; did you mean '--libs='?
<ERROR> Compilation failed for object " build_dependencies_gtk-fortran_src_cairo-auto.f90.o "
<ERROR> Compilation failed for object " build_dependencies_gtk-fortran_src_gdk-auto.f90.o "
<ERROR> Compilation failed for object " build_dependencies_gtk-fortran_src_gdk-pixbuf-auto.f90.o "
<ERROR> Compilation failed for object " build_dependencies_gtk-fortran_src_glib-auto.f90.o "
<ERROR> Compilation failed for object " build_dependencies_gtk-fortran_src_plplot_extra.f90.o "
<ERROR> stopping due to failed compilation
STOP 1
`
vmagnin commented 3 months ago

GFortran should not receive those flags:

gfortran: error: unrecognized command-line option '--cflags'
gfortran: error: unrecognized command-line option '--libs'; 

which are flags of the pkg-config command. Have you installed that package? https://packages.msys2.org/package/pkgconf?repo=msys

Does that command work?

$ pkg-config --cflags --libs plplot plplot-fortran
lllaxmatist commented 3 months ago

It does something (wall of text).

$ pkg-config --cflags --libs plplot plplot-fortran
-ID:/Programs/MSYS2/ucrt64/include/plplot -ID:/Programs/MSYS2/ucrt64/lib/fortran/modules/plplot -ID:/Programs/MSYS2/ucrt64/include/pango-1.0 -ID:/Programs/MSYS2/ucrt64/incl
ude/cairo -ID:/Programs/MSYS2/ucrt64/include/pixman-1 -ID:/Programs/MSYS2/ucrt64/include/fribidi -ID:/Programs/MSYS2/ucrt64/include/harfbuzz -ID:/Programs/MSYS2/ucrt64/incl
ude/freetype2 -ID:/Programs/MSYS2/ucrt64/include/libpng16 -ID:/Programs/MSYS2/ucrt64/include/glib-2.0 -ID:/Programs/MSYS2/ucrt64/lib/glib-2.0/include -DQT_CORE_LIB -ID:/Pro
grams/MSYS2/ucrt64/include/QtCore -DQT_GUI_LIB -ID:/Programs/MSYS2/ucrt64/include/QtGui -DQT_PRINTSUPPORT_LIB -ID:/Programs/MSYS2/ucrt64/include/QtPrintSupport -DQT_WIDGETS
_LIB -ID:/Programs/MSYS2/ucrt64/include/QtWidgets -DQT_SVG_LIB -ID:/Programs/MSYS2/ucrt64/include/QtSvg -DHPDF_DLL -ID:/Programs/MSYS2/ucrt64/lib/wx/include/msw-unicode-3.2
 -ID:/Programs/MSYS2/ucrt64/include/wx-3.2 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXMSW__ -DUNICODE -D_UNICODE -lplplotfortran -lplplot -lpangocairo-1.0.dll -lpango-1.0.dl
l -lgobject-2.0.dll -lglib-2.0.dll -lintl.dll -lharfbuzz.dll -lcairo.dll -lgd.dll -lpng.dll -lz.dll -ljpeg.dll -ltcl.dll -ltk.dll -pipe -Wl,--subsystem,windows -mwindows -l
wx_baseu-3.2.dll -lwx_mswu_core-3.2.dll -lhpdf.dll -lgdi32 -lcomdlg32 -lcomctl32 -lshp.dll -lfreetype.dll -lQt5Core.dll -lQt5Gui.dll -lQt5PrintSupport.dll -lQt5Widgets.dll
-lQt5Svg.dll -lcsirocsa -lcsironn -lqhull -lqsastime -lstdc++.dll -LD:/Programs/MSYS2/ucrt64/lib/gcc/x86_64-w64-mingw32/13.2.0 -lpthread.dll -ladvapi32 -lshell32 -luser32 -
lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lkernel32
vmagnin commented 3 months ago

So pkg-config works. Its role is to pass to the compiler and linker all those parameters and flags concerning the needed libraries installed in your system, and to save you a lot of work!

vmagnin commented 3 months ago

I have made a test in MSYS2 with a fpm project depending on gtk-fortran and PLplot and had the same errors as you with the single quotes. It was better with double quotes, but finally the compilation failed, with the same kind of errors that occur when I try to build gtk-fortran with PLplot examples in MSYS2.

As you can see Issue https://github.com/vmagnin/gtk-fortran/issues/269 it started to fail somewhere in 2022 (it was working before), but I have never find a solution.

vmagnin commented 3 months ago

I have finally fixed the issue https://github.com/vmagnin/gtk-fortran/issues/269 on my system and can now compile programs using PLplot (with CMake in gtk-fortran).

vmagnin commented 3 months ago

But with fpm, it still fails.