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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Including cpp files?

Including cpp files?

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 3 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.
  • D Offline
    D Offline
    Dominik Reichl
    wrote on last edited by
    #1

    Hello, is it possible to include .cpp files using the #include directive? I want to include an external library into my project, but the library has many files and so I would have to add all cpp-files to my project by hand. Is something like the following allowed?

    #include <extfile1.h>
    #include <extfile1.cpp>
    #include <extfile2.h>
    #include <extfile2.cpp>

    etc... :confused: -Dominik


    _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;)

    P J 2 Replies Last reply
    0
    • D Dominik Reichl

      Hello, is it possible to include .cpp files using the #include directive? I want to include an external library into my project, but the library has many files and so I would have to add all cpp-files to my project by hand. Is something like the following allowed?

      #include <extfile1.h>
      #include <extfile1.cpp>
      #include <extfile2.h>
      #include <extfile2.cpp>

      etc... :confused: -Dominik


      _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;)

      P Offline
      P Offline
      Peter Hancock
      wrote on last edited by
      #2

      I'm pretty sure you can.... as long as the library that you are linking in excludes the same cpp files from its build. Otherwise you'll end up with multiply defined functions and classes in the obj file. Why can't you just compile and link the library, and include only the headers? And they still ran faster and faster and faster, till they all just melted away, and there was nothing left but a great big pool of melted butter "I ask candidates to create an object model of a chicken." -Bruce Eckel

      1 Reply Last reply
      0
      • D Dominik Reichl

        Hello, is it possible to include .cpp files using the #include directive? I want to include an external library into my project, but the library has many files and so I would have to add all cpp-files to my project by hand. Is something like the following allowed?

        #include <extfile1.h>
        #include <extfile1.cpp>
        #include <extfile2.h>
        #include <extfile2.cpp>

        etc... :confused: -Dominik


        _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;)

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        Yes and No. I assume you want to import the source files not an external library, which you would just add though your projects settings (make file) and then include the header files in your code. 1) If you just want to add the code/source files to your project then just add them to your work space and include the headers to the code files that access them. 2) If you realy want (or need) to include the code/source files via #include then you do not need to include the header files before those code/source files, since the headers should have been included in the source files them selfs. The 2 problems with including code/source files with #include, (1) you can only include them in only one source file and then use the headers in all other files which may need to access them, (2) you may get multiple definitions because header files in the included files may not have been coded to prevent it. (alright there could be more that 2 problems) 3) Think about it. Basicaly what the preprocessor does is creates 1 big file and then compiles it. This is simplistic, but what it means is that the preprocessor combines your file and the included files in to 1 file before it passes it to the compiler. Therefore, if you include code/source files in each of the files that use them then it is the same as cutting and pasting the contains of those files in to each of those files. Trust in the code Luke. Yea right!

        D 1 Reply Last reply
        0
        • J John R Shaw

          Yes and No. I assume you want to import the source files not an external library, which you would just add though your projects settings (make file) and then include the header files in your code. 1) If you just want to add the code/source files to your project then just add them to your work space and include the headers to the code files that access them. 2) If you realy want (or need) to include the code/source files via #include then you do not need to include the header files before those code/source files, since the headers should have been included in the source files them selfs. The 2 problems with including code/source files with #include, (1) you can only include them in only one source file and then use the headers in all other files which may need to access them, (2) you may get multiple definitions because header files in the included files may not have been coded to prevent it. (alright there could be more that 2 problems) 3) Think about it. Basicaly what the preprocessor does is creates 1 big file and then compiles it. This is simplistic, but what it means is that the preprocessor combines your file and the included files in to 1 file before it passes it to the compiler. Therefore, if you include code/source files in each of the files that use them then it is the same as cutting and pasting the contains of those files in to each of those files. Trust in the code Luke. Yea right!

          D Offline
          D Offline
          Dominik Reichl
          wrote on last edited by
          #4

          Thank you, I will think about it :-D -Dominik


          _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;)

          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