Thread: FAQ example wont work!

  1. #1
    Useless Apprentice ryan_germain's Avatar
    Join Date
    Jun 2004
    Posts
    76

    FAQ example wont work!

    ok...i go to: "FAQ > How do I... (Level 2) > Multiple source files for one program (C++ example)"

    im using dev-c++, can compile other single .cpp files perfectly fine. But...I cant get this program to run. It says:

    program2.cpp: undefined reference to `myFunc(int &)'
    program2.cpp: undefined reference to `MyClass::setData(int)'
    program2.cpp: undefined reference to `MyClass::getData(void)'

    in the linker output when i try to compile program2. I copy pasted the code.

    Ive never worked on header files before (hence why im trying this program) so maybe im just doing something wrong there.

    What the hell am i doing wrong?

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    So you created a new project, and all of the cpp and h files are included?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Useless Apprentice ryan_germain's Avatar
    Join Date
    Jun 2004
    Posts
    76
    yeah exactly, all of them. You compile .h files eh? (i SAID i was a noob with headers)

  4. #4
    Useless Apprentice ryan_germain's Avatar
    Join Date
    Jun 2004
    Posts
    76
    cause when i try to compile any .h file the linker output conplains about:

    gcc: Compilation of header file requested
    gcc: file path prefix `C:\DEV-C_~1\Bin\' never used

    so i dunno...are you supposed to compile .h files? if so, why does this error occur?
    Thx

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    No you do not compile header files

  6. #6
    Useless Apprentice ryan_germain's Avatar
    Join Date
    Jun 2004
    Posts
    76
    Quote Originally Posted by XSquared
    So you created a new project, and all of the cpp and h files are included?
    why must the files be in a project? I know it wont work if they're not, but is there a reasoning behind this?

  7. #7
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Otherwise it won't know to link the object files together.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  8. #8
    Useless Apprentice ryan_germain's Avatar
    Join Date
    Jun 2004
    Posts
    76
    Thx for all the help...it works now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Redirect FAQ...
    By Queatrix in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 05-21-2007, 04:48 PM
  2. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM
  3. Why won't my OpenGL work?
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 11-26-2005, 11:53 AM
  4. Developers Wanted
    By Quasicom in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 08-24-2005, 12:46 AM
  5. Format of the FAQ Board
    By kermi3 in forum FAQ Board
    Replies: 0
    Last Post: 11-15-2001, 10:45 AM