Thread: Having trouble with llinker and Undefined reference errors

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by manasij7479
    What is a translation unit ?
    The definition is:
    Quote Originally Posted by C++03 Clause 2 Paragraph 1 (part)
    A source file together with all the headers and source files included via the preprocessing directive #include, less any source lines skipped by any of the conditional inclusion preprocessing directives, is called a translation unit.
    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

  2. #17
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    OK.. Suggest me something...
    I have multiple independent (*.h + *.cpp) pairs ...They are translation units if I understand the definition.
    All of them need to be combined into a single project..
    Till now ..I've been # including the headers in the main program...and then giving the compiler the *.cpp files together..
    Is there a better way to work with such distinct units ?

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by manasij7479
    I have multiple independent (*.h + *.cpp) pairs ...They are translation units if I understand the definition.
    All of them need to be combined into a single project..
    Till now ..I've been # including the headers in the main program...and then giving the compiler the *.cpp files together..
    Is there a better way to work with such distinct units ?
    That's a normal way of working: you have separate source files and include headers where you need them, then finally link the object files generated to form the final product.
    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

  4. #19
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Normally, all you do is add all the .cpp files to the project list of source files.

    The IDE generates a 'makefile' from this, and then make works out the minimum dependencies necessary to keep the executable up to date.
    Done well, if you edit only one source file, you only compile that source file and then run the linker to combine all the objects and libraries together.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #20
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    What is the difference between an IDE generated makefile and a manually made one ?...Is there some tech *magic* (!) involved so that the former one works better ?

  6. #21
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by manasij7479
    What is the difference between an IDE generated makefile and a manually made one ?...Is there some tech *magic* (!) involved so that the former one works better ?
    That depends on your makefile writing skills, methinks
    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

Popular pages Recent additions subscribe to a feed