How to specify the "ld" when make a binary using g++

This is a discussion on How to specify the "ld" when make a binary using g++ within the C++ Programming forums, part of the General Programming Boards category; I have 2 versions of ld in my machine. Suppose I want to specify /usr/bin/ld as the linker to make ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    How to specify the "ld" when make a binary using g++

    I have 2 versions of ld in my machine.
    Suppose I want to specify /usr/bin/ld as the linker to make a binary. How should I write the Makefile?
    Thanks.

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    284
    Here is the Makefile

    Code:
    main : main.o                                                                   
            g++ main.o                                                              
    main.o : main.cc                                                                
            g++ -c main.cc
    Seems no where to indicate "ld" ?

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I would set your PATH so that the ld you want is found first, unless you plan to switch back and forth a lot (why you would I don't know).

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There isn't any way to specify which "ld" to use on the gcc command line.

    There are some things you can use for gcc to tell it where things are:
    1. the -B switch, which tells gcc the base directory to use for the subcomponents.
    2. -specs=FILE to give gcc a new "specs" file. Although I'm not sure if this actually allows you to specify the path of the linker, it's where I think it COULD be done. Syntax is definitely not straight forward!

    Edit: To clarify: The solution by Tabstop is probably the right way to do it.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trying to make a KenGen ( for a game tool )
    By lonewolfy in forum C# Programming
    Replies: 4
    Last Post: 03-28-2007, 08:23 AM
  2. Binary Tree, couple questions
    By scoobasean in forum C Programming
    Replies: 3
    Last Post: 03-12-2005, 08:09 PM
  3. binary search and search using binary tree
    By Micko in forum C++ Programming
    Replies: 9
    Last Post: 03-18-2004, 09:18 AM
  4. binary
    By webturtle0 in forum A Brief History of Cprogramming.com
    Replies: 52
    Last Post: 12-05-2002, 01:46 AM
  5. Array, Linked List, or Binary Tree?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 01-05-2002, 09:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21