You are not logged in.

#1 2016-05-17 06:02:38

kudykennedy
Member
Registered: 2015-04-11
Posts: 21

CodeBlocks+MinGW86_64 Cross Compiler: ld returns 1 exit status.

Hello, I am creating a GUI for my science project, using FLTK.
The CodeBlocks default "GNU GCC Compiler" works fine.
Then I wanted to compile exe for my program for Windows use.
Add new compiler... check
Directories set to /usr/x86_64-w64-mingw32/include (compiler), /usr/x86_64-w64-mingw32/lib (linker) and /usr/x86_64-w64-mingw32/include (resource compiler)
Toolchains executables set to x86_64-w64-mingw32-gcc, x86_64-w64-mingw32-g++, x86_64-w64-mingw32-g++, x86_64-w64-mingw32-g++.
Rebuild...from no error to

||=== Build: Debug in cap2_gui (compiler: cross_windows) ===|
../../../../../home/kudy/Downloads/fltk-1.3.3/FL/Fl_Widget.H||In member function ‘void Fl_Widget::callback(void (*)(Fl_Widget*, long int), long int)’:|
../../../../../home/kudy/Downloads/fltk-1.3.3/FL/Fl_Widget.H|576|warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]|
../../../../../home/kudy/Downloads/fltk-1.3.3/FL/Fl_Widget.H||In member function ‘void Fl_Widget::argument(long int)’:|
../../../../../home/kudy/Downloads/fltk-1.3.3/FL/Fl_Widget.H|598|warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]|
../../../../../home/kudy/Downloads/fltk-1.3.3/FL/Fl_Widget.H||In member function ‘void Fl_Widget::do_callback(Fl_Widget*, long int)’:|
../../../../../home/kudy/Downloads/fltk-1.3.3/FL/Fl_Widget.H|848|warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]|
../../../../../home/kudy/Downloads/fltk-1.3.3/FL/Fl_Menu_Item.H||In member function ‘void Fl_Menu_Item::callback(void (*)(Fl_Widget*, long int), long int)’:|
../../../../../home/kudy/Downloads/fltk-1.3.3/FL/Fl_Menu_Item.H|243|warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]|
../../../../../home/kudy/Downloads/fltk-1.3.3/FL/Fl_Menu_Item.H||In member function ‘void Fl_Menu_Item::argument(long int)’:|
../../../../../home/kudy/Downloads/fltk-1.3.3/FL/Fl_Menu_Item.H|267|warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]|
../../../../../home/kudy/Downloads/fltk-1.3.3/FL/Fl_Menu_Item.H||In member function ‘void Fl_Menu_Item::do_callback(Fl_Widget*, long int) const’:|
../../../../../home/kudy/Downloads/fltk-1.3.3/FL/Fl_Menu_Item.H|397|warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]|
ld||unrecognized option '-z'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 6 warning(s) (0 minute(s), 3 second(s)) ===|

They are mostly warning from FLTK.
But THIS:

ld||unrecognized option '-z'|
||error: ld returned 1 exit status|

stops me from rebuilding it, thus cannot have EXE file.
What is this? Searching gives me no answer.

Offline

#2 2016-05-17 06:24:30

kudykennedy
Member
Registered: 2015-04-11
Posts: 21

Re: CodeBlocks+MinGW86_64 Cross Compiler: ld returns 1 exit status.

Some more info: the rebuild code from codeblocks:

x86_64-w64-mingw32-g++ -I/usr/include/freetype2 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fvisibility-inlines-hidden -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -g -I../../../../../home/kudy/Downloads/fltk-1.3.3 -I/usr/x86_64-w64-mingw32/include -c /media/DATA/Projects/FLTK/cap2_gui/main.cpp -o obj/Debug/main.o

the sucessful default rebuild (before cross compiling):

g++ -I/usr/include/freetype2 -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fvisibility-inlines-hidden -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -g -I../../../../../home/kudy/Downloads/fltk-1.3.3 -c /media/DATA/Projects/FLTK/cap2_gui/main.cpp -o obj/Debug/main.o
g++ -L../../../../../home/kudy/Downloads/fltk-1.3.3/lib -o bin/Debug/cap2_gui obj/Debug/main.o  -Wl,-O1,--sort-common,--as-needed,-z,relro -lGL -lGLU -Wl,-O1,--sort-common,--as-needed,-z,relro -lGL -lGLU  ../../../../../usr/lib/libfltk_images.so ../../../../../usr/lib/libfltk_gl.so ../../../../../usr/lib/libfltk.so ../../../../../usr/lib/libfltk_forms.so

Other linker options:

`fltk-config --ldstaticflags`
-lGL -lGLU

remove these lines clears ld||unrecognized option '-z'| but still returns 1.

Last edited by kudykennedy (2016-05-17 06:55:02)

Offline

#3 2016-05-17 12:12:34

kudykennedy
Member
Registered: 2015-04-11
Posts: 21

Re: CodeBlocks+MinGW86_64 Cross Compiler: ld returns 1 exit status.

Using GNU GCC COMPILER, compile success:

g++ -O2 -s -g  -c /media/DATA/Projects/FLTK/cap2_gui/main.cpp -o obj/Debug/main.o
g++  -o bin/Debug/cap2_gui obj/Debug/main.o   /lib/libfltk.so /lib/libfltk_forms.so /lib/libfltk_gl.so /lib/libfltk_images.so /lib/libGL.so
Output file is bin/Debug/cap2_gui with size 292.44 KB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))

THEN USING CROSS COMPILER MINGW:

i686-w64-mingw32-g++ -O2 -s -g -DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -DSTRICT -DHAVE_W32API_H -D__WXMSW__ -D__WINDOWS__ -I/usr/i686-w64-mingw32/include -I/home/kudy/Downloads/fltk-1.3.3 -c /media/DATA/Projects/FLTK/cap2_gui/main.cpp -o obj/Debug/main.o
i686-w64-mingw32-g++ -L/usr/i686-w64-mingw32/lib -o bin/Debug/cap2_gui obj/Debug/main.o   /lib/libGL.so /lib/libfltk.so /lib/libfltk_forms.so /lib/libfltk_gl.so /lib/libfltk_images.so
/lib/libGL.so: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 2 second(s))
1 error(s), 0 warning(s) (0 minute(s), 2 second(s))

IT KEEPS SAYING THOSE .SO LIBRARIES I LINKED WAS IN WRONG FORMAT.
They compile just fine with GNU GCC COMPILER!
What is the difference ?!?!?

Last edited by kudykennedy (2016-05-17 13:51:13)

Offline

#4 2016-05-17 12:49:24

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: CodeBlocks+MinGW86_64 Cross Compiler: ld returns 1 exit status.

First, please calm down.  All caps and excessive punctuation/exclamation points are not needed.

Second, you are linking to ELF shared objects for a win32 build.  You need to use the win32 dlls provided by the mingw packages.

Also, is this any different from your other post or are you just cross posting the same problem?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2016-05-17 12:58:23

kudykennedy
Member
Registered: 2015-04-11
Posts: 21

Re: CodeBlocks+MinGW86_64 Cross Compiler: ld returns 1 exit status.

Ok, sorry. Changed to x86_64 mingw. Sill the same problem. My g++ is 64, all of my so are 64, still wrong format.
This only happens with those I need libraries. For a simple Hello World, no error, and .exe is created.
Even .so files in usr/lib64 won't work. So you are saying, I have to link to dll files, instead of those .so files ?

x86_64-w64-mingw32-g++ -O2 -s -g -DWINVER=0x0400 -D__WIN95__ -D__GNUWIN32__ -DSTRICT -DHAVE_W32API_H -D__WXMSW__ -D__WINDOWS__ -I/usr/x86_64-w64-mingw32/include -I/home/kudy/Downloads/fltk-1.3.3 -c /media/DATA/Projects/FLTK/cap2_gui/main.cpp -o obj/Debug/main.o
x86_64-w64-mingw32-g++ -L/usr/x86_64-w64-mingw32/lib -L/home/kudy/Downloads/fltk-1.3.3/lib -o bin/Debug/cap2_gui obj/Debug/main.o   /lib64/libGL.so /lib64/libfltk.so /lib64/libfltk_forms.so /lib64/libfltk_gl.so /lib64/libfltk_images.so
/lib64/libGL.so: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

Offline

#6 2016-05-17 13:20:02

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: CodeBlocks+MinGW86_64 Cross Compiler: ld returns 1 exit status.

kudykennedy wrote:

So you are saying, I have to link to dll files, instead of those .so files?

Yes.  i686 vs x86_64 is not the issue.  Windows does not use the same ELF format that linux does, so you cannot use linux *.so files, you need to link to windows libs which are .dll files.

The mingw compiler handles this for you for the standard libraries, that's why your hello-world example worked fine.  But as soon as you include other libs, you need to give the linker the path to the dlls.  In most cases you can use mingw's pkg-config to help with this, so just like in a linux build you could specify LDFLAGS from `pkg-config --libs <lib1> <lib2>` you can use mingw's pkg-config the same way.  I forget the exact path and name of mingw's pkg-config but it follows similar naming conventions as the compilers.

You would actually be fine with the i686 build though as any Windows system can still run Win32.  Not long ago 32-bit builds seemed to be the norm and encouraged as they could run on any windows system while win64 could only run on 64 bit systems.  This is still true, but 32 bit windows systems may be less common now.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2016-05-17 13:34:32

kudykennedy
Member
Registered: 2015-04-11
Posts: 21

Re: CodeBlocks+MinGW86_64 Cross Compiler: ld returns 1 exit status.

Thanks, great. Some more questions though.
1. I have to look for 32 bit / 64 .dll files for FLTK and LIBGL. Do you have a good source for these?
2. What if I do not have Windows, can makefiles alone generate dll instead of .so? And how to achieve it?

Offline

#8 2016-05-17 13:41:29

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,441
Website

Re: CodeBlocks+MinGW86_64 Cross Compiler: ld returns 1 exit status.

1) The mingw group in the AUR, or the mingw repository.  I don't see fltk there though, so you might need to build that yourself.  See any of the hundreds of other mingw PKGBUILDs for a template on how to build it.  But in general, installing dependencies for mingw builds is just like installing dependencies for linux builds.  If you'd build a package for linux using gcc and libABC, then to build for windows you'd need mingw-gcc and mingw-libABC.  You cannot mix and match: your libraries must match the system targetted by the compiler.

2) The dlls are the windows equivalent of .so files, you should not need to "generate" them, they are in the mingw packages for that lib - fltk again may be an exception, but you don't need to do anything special to generate the dlls, just build and install a mingw fltk package.  A makefile alone cannot generate anything, but a makefile with a mingw cross compiler does compile for windows, that's it's whole purpose.

I can't give a complete step-by-step as I'm no longer cross compiling on this system, but frankly I think you may need to take a step back and start a bit smaller.  Use libs that are available already for mingw to get used to cross compiling.  Then once you get used to it, making PKGBUILDs for other libs like fltk will be trivial.  You could also just download the windows dlls from fltk's upstream source and just drop them in your build directory - but this would seem a bit messy to me.  EDIT: maybe not, fltk does not seem to distribute a windows build from what I can (quickly) find, just the source code.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#9 2016-05-17 13:59:10

kudykennedy
Member
Registered: 2015-04-11
Posts: 21

Re: CodeBlocks+MinGW86_64 Cross Compiler: ld returns 1 exit status.

Thank you wholeheartedly, not only saying where I'm wrong but also clearing my head on the whole cross-compiling issue.
Marked solved. Long way to go until I can fully get rid of using Windows. Again, thanks.

Offline

#10 2016-05-17 15:08:04

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: CodeBlocks+MinGW86_64 Cross Compiler: ld returns 1 exit status.

Moderator:  As far as I can tell, you had two threads going on the same topic.  Even if the threads were different issues, the overreaching issue seemed to be cross compile link errors in a particular IDE  I think this is of narrow interest, so I went ahead and merged the threads to keep things tidy.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

Board footer

Powered by FluxBB