Forums > Dev

minGW, external problem

June 2, 2006 | 12:25 am

I’m trying to use the Bloodshed IDE (which compiles with minGW 3.4.2) to whip up a couple of the externals provided as examples in the SDK. I can get everything imported okay, and it compiles with no errors. However, I put it in my externals folder, and it doesn’t work. I type in the object name and get "invalid external [name], undefined main". I would assume this refers to the main function of the ext, which I did not change. Given that it compiled with no errors, I find this rather befuddling.
Anyone else have a similar problem with this or any other dev env? Anyone had success using minGW? I’ve spent several hours on this and it’s getting quite frustrating. I know there are some lite versions of MSVS available, but I would really rather use Bloodshed.

Thanks all,
Mike


June 2, 2006 | 12:33 am

If you searchthe jitter-dev forum for cygwin development, you may get
some ideas there. Otherwise, I have no idea.

best,
wes


June 2, 2006 | 1:15 am

On Jun 1, 2006, at 5:25 PM, Mike Sayre wrote:

>
> I’m trying to use the Bloodshed IDE (which compiles with minGW
> 3.4.2) to whip up a couple of the externals provided as examples in
> the SDK. I can get everything imported okay, and it compiles with
> no errors. However, I put it in my externals folder, and it
> doesn’t work. I type in the object name and get "invalid external
> [name], undefined main". I would assume this refers to the main
> function of the ext, which I did not change. Given that it
> compiled with no errors, I find this rather befuddling.

It might be possible that it’s not exporting a main function (needs
to happen, and is defined in the .def file provided as input to the
linker). Or possibly the file is being compiled with C++ and the main
function is somehow decorated, though the former sounds more likely
to me. Make sure that the GCC command being executed for linking is
something like the following (with the appropriate .def file):

gcc -shared -mno-cygwin -o minimum.mxe minimum.o minimum.def -L../../
c74support/max-includes -lMaxAPI

> Anyone else have a similar problem with this or any other dev
> env? Anyone had success using minGW?

I was able to have success with cygwin/mingw/gcc from the command
line and the basic steps are documented in the Cygwin_gcc_HowTo.rtf
distributed with the windows SDK. Compare the GCC commands BloodShed
generates with those from this document, and perhaps it will shed
some light.

> I would really rather use Bloodshed.

Sounds promising, but you might be he first to wrestle with building
a Max object with this IDE. Please share your findings so that others
who wish to use bloodshed won’t have to suffer as you have.

Best of luck.

-Joshua


June 2, 2006 | 1:03 pm

On Thu, 1 Jun 2006, Joshua Kit Clayton wrote:

> decorated, though the former sounds more likely to me. Make sure that the GCC
> command being executed for linking is something like the following (with the
> appropriate .def file):
>
> gcc -shared -mno-cygwin -o minimum.mxe minimum.o minimum.def
> -L../../c74support/max-includes -lMaxAPI

I used cygwin to compile rtcmix~ for windows which draws upon a mixed
C/C+ library. Depending on what functions/objects you call, you may not
be able to use the -mno-cygwin flag easily… and then you have tto drag
around the cygwin1.dll lib. I’m looking into using just the mingw
compiler, or possibly the free MS compiler instead.

I also found this article on the web:

http://www.delorie.com/howto/cygwin/mno-cygwin-howto.html

I haven’t read through it closely yet, but it looks like it contains some
good information.

brad

http://music.columbia.edu/~brad


June 2, 2006 | 2:15 pm

Everyone,
Thanks for the good suggestions. I will try them this afternoon after I get out of class (yay for summer school!) and get back to you with my findings. Some preliminary things I have found already:
I can’t seem to find a way through the IDE to set the struct alignment to 2 bytes. It seems to already be set to this – at least when I open the project in MSVS. I must confess I’m a little fuzzy on the topic in the first place. Is this a compiler flag? Linker flag? I can put it in manually, I suppose, but I don’t know the syntax or where it goes using minGW.
The other major complication was finding the right libraries. In order to compile with minGW, I had to download the objective C libraries, which I found here:

http://wiki.codeblocks.org/index.php?title=MinGW_installatio n

Happy Max’ing
Mike


June 2, 2006 | 5:38 pm

for struct alignment you might want to try

#pragma pack(2)
typedef struct _twoByteAlignedStruct {
short foo;
char fooc;
short bar;
float foo;
} twoByteAlignedStruct;

#pragma pack()

the final pack pragma is to reset the struct packing to the default.

The default struct packing should be whatever is most efficient to
make sure that all 32 bit types are 32 bit aligned and 64 bit types
are 64 bit aligned.
There seem to be drastic performance penalties (or errors) for most
architectures when this isn’t the case.

_Mark


June 2, 2006 | 6:47 pm

On Jun 2, 2006, at 7:15 AM, Mike Sayre wrote:

> I can’t seem to find a way through the IDE to set the struct
> alignment to 2 bytes. It seems to already be set to this – at
> least when I open the project in MSVS. I must confess I’m a little
> fuzzy on the topic in the first place. Is this a compiler flag?
> Linker flag? I can put it in manually, I suppose, but I don’t know
> the syntax or where it goes using minGW.

This as Mark specified can be set using compiler #pragma directives.
We now have this in place for the standard MaxMSP headers where it’s
necessary, so this requirement is no longer necessary to setup for
your project.

> The other major complication was finding the right libraries.
> In order to compile with minGW, I had to download the objective C
> libraries, which I found here:
>
> http://wiki.codeblocks.org/index.php?title=MinGW_installatio n

Are you writing your object in Obj C? Great language, but I don’t
know that many people using it outside the Macintosh community. This
might also be introducing some complications if you’re not
appropriately decorating things which should have C style exports.

I would suggest you approach the problem systematically:

1. download latest gcc, and mingw libraries together through cygwin’s
setup utility as described in the Cygwin_gcc_HowTo.rtf

2. try to get the minimum object SDK example file compiling from the
command line and loading in MaxMSP

3. try to resolve any issues with BloodShed and the minimum project

4. try to resolve any problems with your own extern in BloodShed

-Joshua


June 5, 2006 | 12:56 am

HAH! Success!
I followed your suggestions and first compiled the min external with cygwin – worked like a charm. Then I tried moving it into Bloodshed and got frustrated by an idiotic problem for a while. When Bloodshed builds, it writes its own makefiles and .def files. I looked at the def file it was generating, and sure enough, it wasn’t exporting anything at all. When I tried to change the makefile to make it use my def file and told Bloodshed to use a custom def file, it overwrote my makefile AND my def file! I couldn’t get it to use the .def file supplied in the SDK.
However, I dug around on the documentation; you are NOT supposed to add the def file to your project – it won’t hurt anything if you do, so long as you don’t try to include it in the linking process (I did that, and then I got duplicate definition errors between it and the generated def file)and there’s a linker flag you can specify, "–def defFile.def". And then it works. By default, Bloodshed includes quite a few funky other flags for the compiler and linker that seemed unncessary, so I just deleted them.
So, it took a crapload of extra work, but it now works. Hopefully people will be able to use this info – always great to use free tools! I would upload the files, but the forum is being stubborn.
Thanks to everyone who helped – now I can get started on my custom externals. I’m sure that I’ll be back with lots of questions…

Cheers,
Mike


Viewing 8 posts - 1 through 8 (of 8 total)