I think I'm going mad! Please help [SOLVED]

BlitzMax Forums/Brucey's Modules/I think I'm going mad! Please help [SOLVED]

BODYPRINT(Posted 2014) [#1]
G'day guys.
I've spent 2 days straight going through the forums to get FreeImage to work and keep hitting one roadblock after another.

Can I please get some guidance.

I'm running Windows 8 x64.
BlitzMax 1.50
MaxIDE CE 2.01
I've tried so many different versions of MinGW it's not funny!

I'll go through step by step what I think I should do and please tell me why I can't get it to work.

Step 1. Install tdm-gcc-4.5.2
Step 2. Add MinGW Environment with value c:\MinGW32
Step 3. Check the path was created which it is... C:\MinGW32\bin
Step 4. Install BlitzMax 1.50
Step 5. Replace MaxIDE.exe with maxide.exe from CE
Step 6. Copy the lib and bin folders from blitmax_tdm452.rar into the Blitzmax directory overwriting any existing files.
Step 7. Run MaxIDE CE which creates the documentation. Quit.
Step 8. Place the Freeimage mod to C:\BlitzMax\mod\bah.mod\freeimage.mod
Step 9. Run MaxIDE CE again and select Build Modules...
Step 10. Select All and Threaded options.

It fails at...


Tried it with Single Threaded and still the same error.
MaxIDE opens up "cwchar" from the MinGW folder and highlights the following line which caused the error...

(wcstold)(const wchar_t * restrict, wchar_t ** restrict) throw ();

So then I open the original MaxIDE and try build modules and it too fails with...



Sorry for the long errors, just trying to provide as much information as possible.

Cheers.

[EDIT]
See step by step solution in my last post.
[/EDIT]


skidracer(Posted 2014) [#2]
you could try changing all uses of the word "restrict" in Conversion.cpp and Utilities.h and whatever else in FreeImage to _restrict as it seems to be a reserved word in mingw space


xlsior(Posted 2014) [#3]
I'm using gcc version 4.7.1 (tdm-1) myself...

FWIW:

- You also should copy ar.exe and ld.exe from MinGW\bin into blitzmax\bin
- note that there's two MinGW flavors: sjlj and dw2, I -think- you need the sljl version for things to compile properly.


BODYPRINT(Posted 2014) [#4]
@skidracer
Thanks for the suggestion.
There were no "restrict" words in Conversion.cpp, Conversion16_555.cpp or Utilities.h so no dice there.

So here are my next steps going on xlsior's suggestions...

1. uninstall tdm MinGW 4.5.2
2. uninstall Blitzmax and delete any left over folders from the install directory.
3. install tdm-gcc-4.8.1-3 (The latest tdm version available) and during install under version select MinGW Stable 4.7.2-1 (Not the dw2 option)
4. Check Environment variable... path = C:\TDM-GCC-32\bin and MinGW = C:\TDM-GCC-32
5. Install BlitzMax 1.50 and replace maxide with CE version. (should I go back to 1.48 or older here?)
6. Put freeimage.mod in the bah.mod folder.
7. Copy ar.exe and ld.exe from MinGW\bin to Blitmax\bin replacing the Max versions.
8. Run MaxIDE CE... Docs get built
9. Build Modules with All and Multi-Threaded selected
10. OK. So far so good :) Load Freeimage test01.bmx...

Building test_01
Compiling:test_01.bmx
Compile Error: Can't find interface for module 'bah.freeimage'
[C:/BlitzMax/mod/bah.mod/freeimage.mod/tests/test_01.bmx;13;1]
Build Error: failed to compile C:/BlitzMax/mod/bah.mod/freeimage.mod/tests/test_01.bmx
Process complete


On the line...

Local pix:TPixmap = LoadPixmap("logo.gif")


Sigh... what have I missed?

I'll keep at it and update any steps I make in case I get it to work. LOL.


BODYPRINT(Posted 2014) [#5]
This is with a Console and Non-Threaded build btw.


BODYPRINT(Posted 2014) [#6]
OK, so now I'll try Brucey's bmk.bmx v2.16

1. Loaded into MaxIDE CE
2. Select Threaded Build and Console
3. Build... All good.
4. Close MaxIDE
5. Backup original bmk.exe (rename to bmk.exe.bak)
6. Copy newly compiled bmk.exe to BlitzMax/bin
7. Run MaxIDE CE... Build Modules... All... Multi-Threaded
8. Finished in a flash with the following...

Building Modules
Archiving:blitz.debug.mt.win32.x86.a
Archiving:freeimage.debug.mt.win32.x86.a
Archiving:appstub.debug.mt.win32.x86.a
Archiving:audio.debug.mt.win32.x86.a
Archiving:audiosample.debug.mt.win32.x86.a
Archiving:bank.debug.mt.win32.x86.a
.
. etc etc
.
Archiving:opengl.release.mt.win32.x86.a
Archiving:stdc.release.mt.win32.x86.a
Archiving:win32.release.mt.win32.x86.a
Archiving:zlib.release.mt.win32.x86.a

Process complete


Obviously this is not good. But I'll still try Freeimage test01.bmx :)

Building test_01
Unrecognized app source file extension:bmx
Process complete



BODYPRINT(Posted 2014) [#7]
OK...

1. Copied the lib and bin folders from MinGW into the BlitzMax folder replacing any files.
2. Went back to original bmk.exe and built modules again.
3. Went to run Freeimage test01.bmx
4. Same error...

Building test_01
Compiling:test_01.bmx
Compile Error: Can't find interface for module 'bah.freeimage'
[C:/BlitzMax/mod/bah.mod/freeimage.mod/tests/test_01.bmx;13;1]
Build Error: failed to compile C:/BlitzMax/mod/bah.mod/freeimage.mod/tests/test_01.bmx
Process complete



xlsior(Posted 2014) [#8]
the 'can't find interface' means that it has no knowledge of that module.
from the command line, navigate to your blitzmax\bin folder, and type:

bmk makemods -a bah.freeimage
bmk makemods -a -h bah.freeimage

and the rebuild/reindex the blitzmax help and command sets, type:

makedocs


Alternatively, to rebuild ALL modules:

bmk makemods -a
bmk makemods -a -h (the -h does the threaded modules)


BODYPRINT(Posted 2014) [#9]
I feel like I'm getting close but still having so many errors...

Here's where I'm closest.

MinGW 4.5.2 with Brucey's replacement zip file.
FreeImage tests work but as soon as I change the line...

'Framework BaH.FreeImage

to

Import BaH.FreeImage

I get the following errors


Multithreaded Build
Building test_01
Compiling:test_01.bmx
flat assembler  version 1.69.14  (986915 kilobytes memory)
3 passes, 2988 bytes.
Linking:test_01.mt.exe
C:/BlitzMax/mod/pub.mod/oggvorbis.mod/oggvorbis.release.mt.win32.x86.a(vorbisfile.c.release.mt.win32.x86.o):vorbisfile.c:(.text+0x32a8): undefined reference to `__chkstk_ms'
C:/BlitzMax/mod/pub.mod/oggvorbis.mod/oggvorbis.release.mt.win32.x86.a(vorbisfile.c.release.mt.win32.x86.o):vorbisfile.c:(.text+0x32d4): undefined reference to `__chkstk_ms'
C:/BlitzMax/mod/pub.mod/oggvorbis.mod/oggvorbis.release.mt.win32.x86.a(vorbisfile.c.release.mt.win32.x86.o):vorbisfile.c:(.text+0x346c): undefined reference to `__chkstk_ms'
C:/BlitzMax/mod/pub.mod/oggvorbis.mod/oggvorbis.release.mt.win32.x86.a(vorbisfile.c.release.mt.win32.x86.o):vorbisfile.c:(.text+0x34a3): undefined reference to `__chkstk_ms'
C:/BlitzMax/mod/pub.mod/oggvorbis.mod/oggvorbis.release.mt.win32.x86.a(vorbisfile.c.release.mt.win32.x86.o):vorbisfile.c:(.text+0x3c9c): undefined reference to `__chkstk_ms'
C:/BlitzMax/mod/pub.mod/oggvorbis.mod/oggvorbis.release.mt.win32.x86.a(vorbisfile.c.release.mt.win32.x86.o):vorbisfile.c:(.text+0x3d53): more undefined references to `__chkstk_ms' follow
collect2: ld returned 1 exit status
Build Error: Failed to link C:/BlitzMax/mod/bah.mod/freeimage.mod/tests/test_01.mt.exe
Process complete

and

Not MultiThreaded
Building test_01
Compiling:test_01.bmx
flat assembler  version 1.69.14  (955247 kilobytes memory)
3 passes, 2988 bytes.
Linking:test_01.exe
c:/mingw32/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find C:/BlitzMax/mod/bah.mod/freeimage.mod/freeimage.release.win32.x86.a
collect2: ld returned 1 exit status
Build Error: Failed to link C:/BlitzMax/mod/bah.mod/freeimage.mod/tests/test_01.exe
Process complete

So I open a console and run
bmk makemods -a
or
bmk makemods -a -h
and I get the following errors...


I've tried different combinations of lib and bin files from the MinGW folder but still getting the same error.

I'll keep battling :(


Brucey(Posted 2014) [#10]
Hallo :o)

Sorry you're having so many issues. The information in that post is somewhat out of date. I will be revising it shortly.

In the meantime can you try the following :

Download and install tdm-gcc-4.7.1-2.exe from here : http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/Previous/1.1006.0/

Then create yourself this batch file :
@echo off
@set dirMinGW=c:\mingw
@set minGWVersionString=4.7.1
@set dirBlitzmax=c:\coding\BlitzMax

copy %dirMinGW%\bin\ar.exe %dirBlitzmax%\bin /Y
copy %dirMinGW%\bin\ld.exe %dirBlitzmax%\bin /Y

for /f "delims=" %%i in ('dir %dirBlitzmax%\lib /b') do (
copy "%dirMinGW%\lib\%%i" "%dirBlitzmax%\lib\%%i" /z /y
copy "%dirMinGW%\lib\gcc\mingw32\%minGWVersionString%\%%i" "%dirBlitzmax%\lib\%%i" /z /y
)


You'll need to set the paths as you have them on your PC - i.e. the location of MinGW, and the location of your BlitzMax dir.

Run the script to copy over all the files into your BlitzMax bin and lib folders.

Then try a rebuild of the modules, and see how you get on with that.


BODYPRINT(Posted 2014) [#11]
Thanks Brucey :)

Here goes... LOL.

Downloaded and installed tdm 4.7.1-2

Set the environment variable and check the path...
C:\MinGW32 and C:\MinGW32\bin

Install Max 1.50

Run my "MinGW Fix.bat" file :)



Go to bin dir
bmk makemods -a
and
bmk makemods -a -h

Both worked. This is with the default Max bmk.exe file, not your 2.16 version.
Quick question, is the makemods meant to Archive some files?
e.g.


OK, so load my program first (without the freeimage import) to see if it works... all good

Close MaxIDE and copy freeimage.mod over...

bmk makemods -a bah
and
bmk makemods -a -h bah
both work, again this is with the Max bmk.exe file. (Man your bmk is so fast in comparison with 8 cores!! ;P )

Run my program again without Import BaH.FreeImage... all good.
Run my program again with Import BaH.FreeImage... crashes (Windows "...stopped working" error) on this line...

tempImage = LoadImage(picFiles[imageIndex])


Check the FreeImage tests...

Framework BaH.FreeImage = all good
Import BaH.FreeImage causes
test_01.exe has stopped working... crash
test_01.debug.exe has stopped working... crash

So I try my program with...
Framework BaH.FreeImage
Import maxgui.drivers
Import brl.threads
Import brl.eventqueue
Import brl.glmax2d


and it worked!!

I'm not sure which built in mod is causing the crash when I Import Freeimage but this is working for my needs so far so I'm happy. :)

Thankyou so much for your help guys. I can't believe it's working to be honest! It wasn't that hard in the end was it!?! LOL. I still don't know why it didn't work in the past because I followed these steps in various forms from all the suggestions in the forums. Maybe I was using the wrong MinGW or adding too many steps or copied too many files.

Thanks again. :)

Brucey, any idea why Import causes the crash whilst Framwork doesn't?


Brucey(Posted 2014) [#12]
is the makemods meant to Archive some files?

An archive (.a) is just a collection of object (.o) files that the linker will use to create your final executable. Each .bmx file that is Imported (or in a module) will be compiled into an object file.

any idea why Import causes the crash whilst Framwork doesn't?

If you don't have *any* Framework, and import FreeImage, there's a chance you will get function collisions with BlitzMax's built-in PNG and JPG libraries - likely to cause a crash.
Without specifically using "Framework", all BRL and PUB modules are included in your final executable. Usually, you may not want all that extra stuff - and when you are using other modules which may have copies (but different versions) of the same libraries, you really don't want to mix them.

When you use "Framework", it doesn't have to be FreeImage, just some module that stops BlitzMax loading all of them in.