Thread: "cannot find ld"

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    15

    "cannot find ld"

    Hi,
    I tried to compile and run this program, but I got only one error message that says "cannot find ld". It didn't say which line it was, so I can't really figure out where it went wrong.

    Code:
    #include <iostream>
    using std::cin;
    using std::cout;
    using std::endl;
    const int ARRAY_SIZE = 10;
    
    void search(const int a[], int first, int last,
                        int key, bool& found, int& location);
    //Precondition: a[first] through a[last] are sorted in increasing order.
    //Postcondition: if key is not one of the values a[first] through a[last],
    //then found == false; otherwise a[location] == key and found == true.
    
    int main( )
    {
        int a[ARRAY_SIZE];
        const int finalIndex = ARRAY_SIZE - 1;
    
        int i;
        for (i = 0; i < ARRAY_SIZE; i++)
            a[i] = 3*i;
        cout << "Array conatins:\n";
        for (i = 0; i < ARRAY_SIZE; i++)
            cout << a[i] << " ";
        cout << endl;
    
        int key, location;
        bool found;
        cout << "Enter number to be located: ";
        cin >> key;
        search(a, 0, finalIndex, key, found, location);
    
        if (found)
            cout << key << " is in index location "
                 << location << endl;
        else
            cout << key << " is not in the array." << endl;
    
        return 0;
    }
    
    void search(const int a[], int first, int last,
                              int key, bool& found, int& location)
    {
        int mid;
        if (first > last)
        {
            found = false;
        }
        else
        {
            mid = (first + last)/2;
    
            if (key == a[mid])
            {
                found = true;
                location = mid;
            }
            else if (key < a[mid])
            {
                search(a, first, mid - 1, key, found, location);
            }
            else if (key > a[mid])
            {
                search(a, mid + 1, last, key, found, location);
            }
        }
    }
    Any help would be appreciated. Thanks.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    ld is the linker, methinks. How are you compiling and linking the program?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    15
    Well I have no idea what the linker is, but I'm using Bloodshed to run and compile the program. Is there something i'm missing or something I need to change here?

  4. #4
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Did you create a project of some sort or did you just start with a new source file?
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    try putting the bin directory in the path.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    15
    It's a new source file. Not sure what you mean though, Rob...it's been a while since i've done programming.

  7. #7
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    Start Menu, right click My Computer, select advanced tab, select Enviornment Variables, At the bottom half you see system variables, find Path and make sure you see something like C:\dev-cpp\bin

    I think that's what robwhit is referring to.
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    It's a new source file.
    Use a Dev-C++ project.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Jan 2008
    Posts
    15
    Ok i've done that, but when I compile it, this is the error I get:

    C:\Dev-Cpp\Makefile.win [Build Error] [Project1.exe] Error 1

  10. #10
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    did you check to see if C:\Dev-Cpp\bin was in your "Path" Enviornment Variable like robwhit suggested?
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  11. #11
    Registered User
    Join Date
    Jan 2008
    Posts
    15
    Yes I changed it from the Java path to the Dev-cpp path as instructed but still the same error. If you were to copy the code onto your compiler, does it work properly?

  12. #12
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    it compiled no problems on my machine.

    also you wouldn't have to "change" from java path to dev-cpp path, you simply "add" C:\Dev-Cpp\bin to the end of the path list, notice how they are all separated by a semicolon.l
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

  13. #13
    Registered User
    Join Date
    Jan 2008
    Posts
    15
    Ok I've uninstalled the Java compiler...still won't work.

    Since I cannot get the output, could you enter the value of 28 for the input and then copy the output onto a wordpad file for me and e-mail it to me at [email protected] please? Thanks for all the help you're giving me, and that includes all of you.
    Last edited by dxfist; 02-21-2008 at 11:34 AM.

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Rats...this is probably why I shouldn't have installed both a Java compiler and a C++ compiler. Gonna try to uninstall the Java compiler and start over...
    I have a Java compiler and two C++ compilers on my computer and compile my Java and C++ programs without a problem (other than those that are entirely my fault, hehe).

    You can add directories to your system path.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #15
    Use this: dudeomanodude's Avatar
    Join Date
    Jan 2008
    Location
    Hampton, VA
    Posts
    391
    28 produces this output:
    Code:
    28 is not in the array.
    Ubuntu Desktop
    GCC/G++
    Geany (for quick projects)
    Anjuta (for larger things)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. could not find -lwsock32.lib
    By thomas_joyee in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2008, 12:28 PM
  3. How to find O of threads ?
    By jabka in forum C Programming
    Replies: 3
    Last Post: 03-11-2008, 12:25 PM
  4. how do u find 2nd largest number??
    By juancardenas in forum C Programming
    Replies: 8
    Last Post: 02-14-2003, 08:28 AM
  5. Q: Recursion to find all paths of a maze
    By reti in forum C Programming
    Replies: 7
    Last Post: 11-26-2002, 09:28 AM