[Problem] Composition aka Writing programs in multiple files
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: [Problem] Composition aka Writing programs in multiple files

  1. #1
    Join Date
    Sep 2012
    Posts
    10

    [Problem] Composition aka Writing programs in multiple files

    So lately I've been writing multiple header and cpp files and I would always the same error when I finally #include headers in my main.cpp. This error
    Code:
    undefined reference to `...`
    On Youtube videos I see people doing this and their work magically compiles correctly. I found out that when I #include the headers' cpp files instead, my programs would compile. I use Code::Blocks with GNU GCC compiler. Looking for someone with this problem and has solved it to give me some tips for this matter.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,239

    Re: [Problem] Composition aka Writing programs in multiple files

    The problem is not with the headers, but that you are not linking to the object files generated from compiling the various source files that correspond to those headers. With Code::Blocks, this means that you probably did not put those source files in the project.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Mar 2009
    Location
    Riga, Latvia
    Posts
    128

    Re: [Problem] Composition aka Writing programs in multiple files

    You have to options, either track dependencies on your own (write Makefile etc.) or rely on your IDE.

    Review extern and static keywords. Also don't forget about include guards or #pragma once.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center