how can I create a header file ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #31
    That is because neither a DLL nor a static library are programs so they are not executable.

    A DLL is a loadable image but it is loaded by a program. If you want to test your functions and debug them you will need to create a program that calls them.

    Look before you go any further how do you intend to achieve "can be later included in projects"? Do you intend to take the source files and just compile and link them into your later projects or do you intend to create a library with them and then link your later projects with this library.

    It makes a difference to what you do now.

    If you are going to create a library that you will link later projects with then you are on the right tracks already. To test your code you will need to create an application to call the library (it can be another project in the same workspace).

    If you intend to just compile and link the source code into future projects then there is little point you creating a library now as it would just result in you needing multiple projects as above. You may as well have a program that includes both your functions and the test code and main. Now unfortunately that would mean changing your project type again but the reason we have directed you to use a library project is that you have been resisting adding a main function to your code in order to make it a program. If you are going to do this we would of course advise putting the main function into a separate c file.

    Comment

    • scienceman88
      New Member
      • Aug 2009
      • 85

      #32
      I intend include "________.h "

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #33
        Including the .h file only gets the declarations into your future project.

        Like I say you seem to be very focused on the header source file but the actual code in in the code source file, the ____.c, that is where your functions are defined and without that code compiled and linked in your future project all that will happen when you include the _____.h and call the function is you will get a linker error along the lines of "unresolved external symbol" because you will have said that the symbol exists in the header file but you will not have actually defined it anywhere.


        You choices for getting the the code (___.c) into your project are
        • Compile and link the source code into a library. Link your future project with the library.
        • Compile the source code into an object now. Supply the object to your future project as and external object for the future project to include when linking.
        • Supply the future project with the ____.c so that it can be included into the project and compiled with the rest of the project source code.

        In all 3 cases you also supply the ____.h to the future project as well.

        The point is that the ____.h just contains the information required to know how to call the function, it does not contain the function itself that is in the ____.c but you seem to have lost sight or be unaware of that.

        Comment

        • scienceman88
          New Member
          • Aug 2009
          • 85

          #34
          should I make my own exe to test with as it doesn't work with the one provided to me as an option

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #35
            Yes and no, first you should decide how you intend to delieve the code to the future project.

            Although lumping everything into a simple little console application always gives you the opeion of creating a library later.

            Comment

            • scienceman88
              New Member
              • Aug 2009
              • 85

              #36
              basically I want it such that include "________.h calls the source instead of including the source file within the codes compiled with the project.

              Comment

              • Banfa
                Recognized Expert Expert
                • Feb 2006
                • 9067

                #37
                The _____.h has nothing to do with the object code produced by compiling the source. You can not include a function into you future project just by including the header, you have to do one of
                1. Link against a library created by compiling the source
                2. Link against an object file created by compiling the source
                3. Include the source file into the future project directly for it to compile itself


                Putting source code (function definitions) into header file is a source route to either disaster or massive code bloat.

                You have no choice about that you have to choose 1 of those 3 routes, there is no route where you can just have a header file. If there was there would be no need for the ____.c file at all in which case there would be no need for the function definition which implies that the compiler can create the code for your function given just the prototype which implies the compiler can create all code without any programmer input which is clearly nonsense.

                Comment

                • scienceman88
                  New Member
                  • Aug 2009
                  • 85

                  #38
                  when I debug it was asking for an exe to debug with I chose the one it allowed me to without typing but that doesn't work. How do I change it now ? second unless I have a code back to the header how am I going to test the code ? so do I connect it to the exe that I've now made then change the code to point towards the header and act on the codes ?

                  Comment

                  • Banfa
                    Recognized Expert Expert
                    • Feb 2006
                    • 9067

                    #39
                    This is because you created a DLL (dynamic link library) when you made a project that created a library (as opposed to a static library). The DLL needs to be launched by an EXE so the IDE needs an executable to use to in the debugger that will launch the DLL. Using the default program will not work because the default program neither calls nor links with the DLL so it doesn't launch the DLL and even if it did it doesn't call your function so there is no way to test it.

                    You could set-up a project for a test executable that links against the DLL you created and calls your function. However that is quite a lot of work if you do not intend to release the code as a DLL to the future project which is why I keep asking you how you intend to release your code to the future project so that you can make a sensible decision about how to go about testing and debug of your function now.

                    Comment

                    Working...