Strange error while compiling library

I’ve been getting some practice by writing a small, simple library.
I don’t intend to actually use it, it’s just for practice as mentioned.
I’ve run into an error I don’t understand, while ‘verifying’ in the Arduino IDE, related to a line in my *.cpp file.

First I get a Windows message:- “ld.exe has encountered a problem and needs to close. We are sorry for the inconvenience”

Then the message in the Arduino compiler output window is:-

collect2.exe: error: ld returned 5 exit status
Error compiling.

I’m pretty sure there’s nothing wrong with my actual code, so I’m at a loss here.

I’m running Windows XP SP3, using Arduino V1.6.5

The code:-

void MyServo::move(int pulselength, int ms) // Pulse length in uS and number
{                                           // of milliseconds to move for.

   float cycleTimemS = 20+(pulselength/1000);

   int cycles = ms/(int)cycleTimemS;   // This line produces the error.
    // (It's what I need to do.)
 
// int cycles = ms/21;                 // This produces the error too.

// int cycles=ms;              // This compiles fine.

   for(int i=0; i<cycles; i++)
   {
        digitalWrite(SigPin,1);
        delayMicroseconds(pulselength);
        digitalWrite(SigPin,0);
        delay(20);
   }
}

I’d be grateful for any help with this. I’m puzzled.
… Steve

Edit: I’ve seen where this sort of problem can be cured by installing an earlier version of ld.exe. Is this a good idea? (From memory, that was a recommendation for ‘Processing’, not Arduino.)

I can not reproduce your error on WIN7 1.6.5, the code just compiles fine,
so I can not help you in that respect.

But I have some notes regarding your code.

You are using ints for milli- and microseconds, may I suggest using unsigned longs instead?
(32,8 ms is a pretty small usable range for the microseconds...)

Why are you computing the float cycleTimemS just do convert it back to int?
It could just be defined as unsigned long directly, couldn't it?

Whandall:
I can not reproduce your error on WIN7 1.6.5, the code just compiles fine,
so I can not help you in that respect.

As I expected, it's an XP issue then. That was the situation, (in Processing, I think), where an earlier version of ld.exe was recommended.

But I have some notes regarding your code.

You are using ints for milli- and microseconds, may I suggest using unsigned longs instead?
(32,8 ms is a pretty small usable range for the microseconds...)

Why are you computing the float cycleTimemS just do convert it back to int?
It could just be defined as unsigned long directly, couldn't it?

Ha. Unclear thinking. :slight_smile:

The result will almost always be a fraction, so I reached for a 'float' without thinking. Of course, you're right.
I was concentrating so hard on other aspects that I overlooked this.
It's not causing my problem though, unfortunately. Just in case it would work, I just altered the *.cpp file, recompiled and still got the same error.

Well, I'm not sure if it was a good idea or not, and would like further advice on this, but I just downloaded Arduino V1.0.6, renamed my original ld.exe, then replaced it with the one from the earlier Arduino version and now the sketch using my library compiles just fine.

Are there likely to be repercussions???

Maybe I should start a new thread to ask that question, with a link back to this thread?