Can't compile code from Linux to Windows

92 views
Skip to first unread message

Семен Ястребов

unread,
Nov 17, 2024, 8:39:32 AM11/17/24
to fltk.general

Hello friends! For a long time now I have been trying to compile code from Linux to Windows on my own. I'm using x86_64-w64-mingw32-g++ and FLTK 1.3.9. I compile as follows x86_64-w64-mingw32-g++ main.cxx -o my_app.exe `fltk-config --cxxflags` `fltk-config --ldflags --use-images`

I get the following error:
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lXrender: Нет такого файла или каталога
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lXcursor: Нет такого файла или каталога
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lXfixes: Нет такого файла или каталога
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lXext: Нет такого файла или каталога
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lXft: Нет такого файла или каталога
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lfontconfig: Нет такого файла или каталога
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lXinerama: Нет такого файла или каталога
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lX11: Нет такого файла или каталога
collect2: ошибка: выполнение ld завершилось с кодом возврата 1
I tried to remove unnecessary flags but the errors remained:
x86_64-w64-mingw32-g++ main.cxx -o my_app.exe -I/usr/local/include -I/usr/local/include/FL/images -L/usr/local/lib -lfltk -lfltk_images
Error:
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cc9OjQsV.o:main.cxx:(.text+0x49): undefined reference to `Fl_Group::end()'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cc9OjQsV.o:main.cxx:(.text+0x55): undefined reference to `Fl_Window::show()'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cc9OjQsV.o:main.cxx:(.text+0x5a): undefined reference to `Fl::run()'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cc9OjQsV.o:main.cxx:(.text$_ZN8MyWindowC1EiiPKc[_ZN8MyWindowC1EiiPKc]+0x2f): undefined reference to `Fl_Window::Fl_Window(int, int, char const*)'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cc9OjQsV.o:main.cxx:(.text$_ZN8MyWindow4drawEv[_ZN8MyWindow4drawEv]+0x14): undefined reference to `Fl_Window::draw()'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cc9OjQsV.o:main.cxx:(.text$_ZN8MyWindowD1Ev[_ZN8MyWindowD1Ev]+0x22): undefined reference to `Fl_Window::~Fl_Window()'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cc9OjQsV.o:main.cxx:(.rdata$_ZTV8MyWindow[_ZTV8MyWindow]+0x28): undefined reference to `Fl_Window::handle(int)'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cc9OjQsV.o:main.cxx:(.rdata$_ZTV8MyWindow[_ZTV8MyWindow]+0x30): undefined reference to `Fl_Window::resize(int, int, int, int)'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cc9OjQsV.o:main.cxx:(.rdata$_ZTV8MyWindow[_ZTV8MyWindow]+0x38): undefined reference to `Fl_Window::show()'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cc9OjQsV.o:main.cxx:(.rdata$_ZTV8MyWindow[_ZTV8MyWindow]+0x40): undefined reference to `Fl_Window::hide()'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cc9OjQsV.o:main.cxx:(.rdata$_ZTV8MyWindow[_ZTV8MyWindow]+0x60): undefined reference to `Fl_Window::flush()'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cc9OjQsV.o:main.cxx:(.rdata$.refptr.fl_graphics_driver[.refptr.fl_graphics_driver]+0x0): undefined reference to `fl_graphics_driver'
collect2: ошибка: выполнение ld завершилось с кодом возврата 1
When I used g++ with the same flushes, everything was ok:
g++ main.cxx `fltk-config --cxxflags` `fltk-config --ldflags --use-images`

Best regards, Semen

Albrecht Schlosser

unread,
Nov 17, 2024, 9:21:37 AM11/17/24
to fltkg...@googlegroups.com
On 11/17/24 13:46 Семен Ястребов wrote:

Hello friends! For a long time now I have been trying to compile code from Linux to Windows on my own. I'm using x86_64-w64-mingw32-g++ and FLTK 1.3.9.

OK, just for other readers: this is called cross-compiling.


I compile as follows x86_64-w64-mingw32-g++ main.cxx -o my_app.exe `fltk-config --cxxflags` `fltk-config --ldflags --use-images`

I see the issue. For more info see below.


When I used g++ with the same flushes, everything was ok:
g++ main.cxx `fltk-config --cxxflags` `fltk-config --ldflags --use-images`

Best regards, Semen

The issue is that you are using `fltk-config` of your Linux system which is presumable "installed" in a standard location that is found by this simple command.

To solve your problem you must do two things:

(1) Build FLTK with the cross-compiler
(2) Use the `fltk-config` script that has been generated by step (1)

No matter if you built FLTK yourself or you are using a system package, you need to cross-compile FLTK yourself (1) first.

(1) You can do this either with configure/make which is kinda "easy" but can only build in-source which is not recommended. To do it, run these commands:
make disclean
autoconf
./configure --host=x86_64-w64-mingw32
make -k [ -j3 ]

I tried it and it works but it *will* issue a lot of errors when it tries to build the test programs that use fluid. That's why I suggest '-k'. You can ignore these errors as long as the build finishes. The optional '-jN' flag is to use parallel builds with N jobs.

As a test you can run `wine test/hello.exe` which should run FLTK's hello-world program using `wine` (which you need to have installed to do this).

I suggest to use CMake to cross-build FLTK for your Windows target system instead. This is described in 'README.CMake.txt' in the FLTK root directory. It looks a little more complicated at a first glance but once you did it you can reuse it in the future and build out-of-source, i.e. in a build folder of your choice.

BTW: to avoid error messages in your own language (Russian?)  I suggest to precede your build commands with `LC_ALL=C LANG=C LANGUAGE=C` so the error messages are in English to post here, for instance like
$ LC_ALL=C LANG=C LANGUAGE=C make -k -j3

(2) Run your command above with the full path to 'fltk-config' created by your cross-build of FLTK. This ought to work.

Please let us know if you need more help.

Семен Ястребов

unread,
Nov 18, 2024, 7:38:41 AM11/18/24
to fltk.general
Did everything step by step, but result is not enjoy. After build lib, by your commands, i have this problem:

make[1]: Target "all" was not rebuilt due to errors.
make[1]: exit from the directory “/home/kirill/fltk-1.3.9/test”
make: *** [Makefile:22: all] Error 1

Whew try to open hello.exe:

$ wine test/hello.exe  
011c:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\kirill\\fltk-1.3.9\\test\\hello.exe") not found
011c:err:module:loader_init Importing dlls for L"Z:\\home\\kirill\\fltk-1.3.9\\test\\hello.exe" failed, status c0000135

Viewing the lib dir, i see *.a libs and thought that i can try to build programm, but result was the same:

$ x86_64-w64-mingw32-g++ main.cxx -o my_app.exe -I/home/kirill/fltk-1.3.9/ -L/home/kirill/fltk-1.3.9/lib/
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/ccdtpK7w.o:main.cxx:(.rdata$.refptr.fl_graphics_driver[.refptr.fl_graphics_driver]+0x0): undefined reference to `fl_graphics_driver'
Collect2: error: Execution of ld failed with return code 1

What should i do next? Start to learn cmake?

Best regards, Semen
понедельник, 18 ноября 2024 г. в 00:21:37 UTC+10, Albrecht-S:

imm

unread,
Nov 18, 2024, 8:49:54 AM11/18/24
to fltkg...@googlegroups.com
On Mon, 18 Nov 2024 at 12:38, Семен Ястребов wrote:
>
> Did everything step by step, but result is not enjoy. After build lib, by your commands, i have this problem:
>
> make[1]: Target "all" was not rebuilt due to errors.
> make[1]: exit from the directory “/home/kirill/fltk-1.3.9/test”
> make: *** [Makefile:22: all] Error 1

I think that's normal when cross-compiling mingw code on Linux (the
build tries to run some Windows exes - e.g. flud.exe - without
invoking Wine, so those stages fail)


>
> Whew try to open hello.exe:
>
> $ wine test/hello.exe
> 011c:err:module:import_dll Library libstdc++-6.dll (which is needed by L"Z:\\home\\kirill\\fltk-1.3.9\\test\\hello.exe") not found
> 011c:err:module:loader_init Importing dlls for L"Z:\\home\\kirill\\fltk-1.3.9\\test\\hello.exe" failed, status c0000135

That, I think is a mingw issue.

If this were "real" Windows you can duck that (in a quick hack way) by
copying the mingw libstdc++-6.dll into the hello.exe folder so that
the exe finds it at runtime. I'm not sure if Wine is a sloppy as
Windows though about DLL resolution so am not sure if this works...

The better way to fix this is to add "-static-libgcc
-static-libstdc++" to the linker commands when building hello.exe (and
the other exes) and then the necessary parts of mingw will be linked
in and you will not need that DLL at runtime.


>
> Viewing the lib dir, i see *.a libs and thought that i can try to build programm, but result was the same:
>
> $ x86_64-w64-mingw32-g++ main.cxx -o my_app.exe -I/home/kirill/fltk-1.3.9/ -L/home/kirill/fltk-1.3.9/lib/
> /usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/ccdtpK7w.o:main.cxx:(.rdata$.refptr.fl_graphics_driver[.refptr.fl_graphics_driver]+0x0): undefined reference to `fl_graphics_driver'
> Collect2: error: Execution of ld failed with return code 1

You need to specify the fltk libs to use - you heave not done so, so
the link fails. I'd guess, at a minimum, you'd need to add at
something like:

-static-libgcc -static-libstdc++
/home/kirill/fltk-1.3.9/lib/libfltk.a -lgdiplus -lole32 -luuid
-lcomctl32 -lws2_32 -lwinspool

To the end of your command (and that assumes that the mingw
cross-compiler resolves it's own libs correctly, i.e. the -lgdiplus
-lole32 -luuid -lcomctl32 -lws2_32 -lwinspool parts!)

>
> What should i do next? Start to learn cmake?

There's no harm in learning cmake, I'm sure, but the issues here are
probably not related to that so much!
> --
> You received this message because you are subscribed to the Google Groups "fltk.general" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/fltkgeneral/1cac0770-234e-49bd-9b5e-ccd7843e0b05n%40googlegroups.com.

Семен Ястребов

unread,
Nov 19, 2024, 8:07:10 AM11/19/24
to fltk.general
Code to compile:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>

int main(int argc, char const *argv[]) {
    Fl_Window win(600, 600);
    win.show();
    return Fl::run();
}

I really doesnt know what to do, Im discuss with chatgpt for an two hours, but without results. 
Im rebuild lib and try different variants to compile:
$ x86_64-w64-mingw32-g++ -o my_program.exe main.cxx -I/home/kirill/fltk-1.3.9/ -static-libgcc -static-libstdc++ -L/home/kirill/fltk-1.3.9/lib/libfltk_z.a -L/home/kirill/fltk-1.3.9/lib/libfltk.a -lgdiplus -lole32 -luuid -lcomctl32 -lws2_32 -lwinspool
$ x86_64-w64-mingw32-g++ -o my_program.exe main.cxx -I/home/kirill/fltk-1.3.9/ -L/home/kirill/fltk-1.3.9/lib/libfltk_z.a -L/home/kirill/fltk-1.3.9/lib/libfltk.a
$ x86_64-w64-mingw32-g++ -o my_program.exe main.cxx -I/home/kirill/fltk-1.3.9/ -L/home/kirill/fltk-1.3.9/lib/libfltk_z.a -L/home/kirill/fltk-1.3.9/lib/libfltk.a
$ x86_64-w64-mingw32-g++ -o my_program.exe main.cxx -I/home/kirill/fltk-1.3.9/ -L/home/kirill/fltk-1.3.9/lib/libfltk.a

But error is one:
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cce6RRhV.o:main.cxx: (.text+0x3c): undefined reference to `Fl_Window::Fl_Window(int, int, char const*)'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cce6RRhV.o:main.cxx: (.text+0x48): undefined reference to `Fl_Window::show()'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cce6RRhV.o:main.cxx: (.text+0x4d): undefined reference to `Fl::run()'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cce6RRhV.o:main.cxx: (.text+0x5c): undefined reference to `Fl_Window::~Fl_Window()'
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: /tmp/cce6RRhV.o:main.cxx: (.text+0x6f): undefined reference to `Fl_Window::~Fl_Window()'

Collect2: error: Execution of ld failed with return code 1

when use:
$x86_64-w64-mingw32-g++ -o my_program.exe main.cxx -I/home/kirill/fltk-1.3.9/ -L/home/kirill/fltk-1.3.9/lib/libfltk.a -lfltk

error:
/usr/lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lfltk: No such file or directory
collect2: error: ld execution failed with return code 1

Are there other compilers for build under Windows?

понедельник, 18 ноября 2024 г. в 23:49:54 UTC+10, Ian MacArthur:

Ian MacArthur

unread,
Nov 19, 2024, 9:03:33 AM11/19/24
to fltk.general
On Tuesday, 19 November 2024 at 13:07:10 UTC astrebov.. wrote:
Code to compile:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>

int main(int argc, char const *argv[]) {
    Fl_Window win(600, 600);
    win.show();
    return Fl::run();
}

I really doesnt know what to do, Im discuss with chatgpt for an two hours, but without results. 

chatgpt doesn't *know* anything...
 
Im rebuild lib and try different variants to compile:
$ x86_64-w64-mingw32-g++ -o my_program.exe main.cxx -I/home/kirill/fltk-1.3.9/ -static-libgcc -static-libstdc++ -L/home/kirill/fltk-1.3.9/lib/libfltk_z.a -L/home/kirill/fltk-1.3.9/lib/libfltk.a -lgdiplus -lole32 -luuid -lcomctl32 -lws2_32 -lwinspool

This command is malformed, so will not work.
For example, what do you think the "-L" option does? You are not using it appropriately.
In essence it tells the linker the name of a directory to look in for libs.
But if you are giving the full path to the .a file, you should not use the -L, so your command should be something more like:

x86_64-w64-mingw32-g++ -o my_program.exe main.cxx -I/home/kirill/fltk-1.3.9/ -static-libgcc -static-libstdc++   /home/kirill/fltk-1.3.9/lib/libfltk_z.a   /home/kirill/fltk-1.3.9/lib/libfltk.a  -lgdiplus -lole32 -luuid -lcomctl32 -lws2_32 -lwinspool

(assuming your cross-compiler finds it's own libs reliably, that is!)

A command in that form works for me, FWIW. Indeed I think that is what I showed in my previous post, too.

 
Are there other compilers for build under Windows?

If you are cross-compiling, then no, not really. (Well, there are options, but they are all pretty much are variations on the mingw theme...)
If you have a Windows system available then there are all sorts of options you might try.
 

Семен Ястребов

unread,
Nov 20, 2024, 7:54:47 AM11/20/24
to fltk.general
[SOLVED]
Im finally did that.

My solution for this was compile programm under fltk dir which was build under Windows compile.
$ ./fltk-config --use-images --use-forms --compile /home/kirill/cpp-book/12/1/main.cxx

Its equal:
$ x86_64-w64-mingw32-g++ -I. -I./png -I./zlib -I./jpeg -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -o 'main' '/home/kirill/cpp-book/12/1/main.cxx' -mwindows ./lib/libfltk_images.a ./lib/libfltk_png.a ./lib/libfltk_z.a ./lib/libfltk_jpeg.a ./lib/libfltk_forms.a ./lib/libfltk.a -lole32 -luuid -lcomctl32

Than i add a "-static" flags:
$ x86_64-w64-mingw32-g++ -static -static-libgcc -static-libstdc++ -lpthread -I. -I./png -I./zlib -I./jpeg -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -o '/home/kirill/projects/ruller/ruller-windows-app1.exe' '/home/kirill/projects/ruller/main.cxx' -mwindows ./lib/libfltk_images.a ./lib/libfltk_png.a ./lib/libfltk_z.a ./lib/libfltk_jpeg.a ./lib/libfltk_forms.a ./lib/libfltk.a -lole32 -luuid -lcomctl32

Thank everybode fo help.

Best regards, Semen


среда, 20 ноября 2024 г. в 00:03:33 UTC+10, Ian MacArthur:

Ian MacArthur

unread,
Nov 22, 2024, 4:01:29 AM11/22/24
to fltk.general
On Wednesday, 20 November 2024 at 12:54:47 UTC astrebov... wrote:
[SOLVED]
Im finally did that.

Than i add a "-static" flags:
$ x86_64-w64-mingw32-g++ -static -static-libgcc -static-libstdc++ -lpthread -I. -I./png -I./zlib -I./jpeg -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -o '/home/kirill/projects/ruller/ruller-windows-app1.exe' '/home/kirill/projects/ruller/main.cxx' -mwindows ./lib/libfltk_images.a ./lib/libfltk_png.a ./lib/libfltk_z.a ./lib/libfltk_jpeg.a ./lib/libfltk_forms.a ./lib/libfltk.a -lole32 -luuid -lcomctl32

Thank everybode fo help.

You are welcome. Glad that you got it sorted.

A few notes about your working command line:

- Whilst the "-static-libgcc -static-libstdc++" stanza is necessary here, I do not think the "-static" is actually needed (or at least, I do not use it, anyway!)
- Are you sure you want the "-lpthread" library there? In general, programs compiled for Windows should try to use WIN32 threading rather than pthreads.
- You may not need the "./lib/libfltk_forms.a" either - it provides support for the legacy Forms Library, but is largely deprecated now and you probably do not need it.
- The include paths you are defining for the image libraries, i.e. " -I./png -I./zlib -I./jpeg" should not be pointing to the local directory (with "./") but should give the full path to the respective directories in the FLTK build tree, e.g. "-I /home/kirill/projects/..whatever../fltk-1.3.10/png" etc.
- Similarly the library refs should give the full paths, e.g. "./lib/libfltk_jpeg.a" becomes "/home/kirill/projects/..whatever../fltk-1.3.10/lib/libfltk_jpeg.a" and so on.

FWIW, although I know a lot of people do it, I don't generally find cross-compiling to Windows from Linux all that convenient. I usually find it easier to either use an actual Windows machine (you do not need anything very powerful for FLTK) or to spin up a VM with Windows. In either case I then just use the Msys (or Msys2) toolchain to build natively and that is generally simpler and more reliable then the cross-compile option.

 
Reply all
Reply to author
Forward
0 new messages