Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. generating .obj files out of header files

generating .obj files out of header files

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tguzella
    wrote on last edited by
    #1

    hi there i have a project in visual c++ 7, with a main.cpp file, and 5 header files used by the main file. how do i get the compiler to generate a .obj file for each header file on the project?? right now it is creating just one for the entire project... Thanks

    G 1 Reply Last reply
    0
    • T tguzella

      hi there i have a project in visual c++ 7, with a main.cpp file, and 5 header files used by the main file. how do i get the compiler to generate a .obj file for each header file on the project?? right now it is creating just one for the entire project... Thanks

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      .obj files (called object files) are generated from .cpp files (source files), not .h files (header files). Header files are used to share declarations between two or more .cpp files. Here's an example header file, ClassA.h:

      class ClassA {
      public:
      ClassA();
      ~ClassA();
      int A;
      };

      and the corresponding source file, ClassA.cpp

      #include "ClassA.h"

      ClassA::ClassA()
      : A(0)
      {
      };

      ClassA::~ClassA()
      {
      };

      and the main program, Main.cpp

      #include "ClassA.h"

      int main(int argc,char *argv[])
      {
      ClassA An_A;
      //...
      }

      From this example, there would be two object files, ClassA.obj and Main.obj. ClassA.h is #include'd by both of them to ensure that they both agree on the declaration of ClassA.


      Software Zen: delete this;

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups