relationship between library files and cpp files etc. got links?

cpp Viet Nam
  • 9 years ago
    ive got to start making my own libraries and using them, but i have no idea where to start. i know a tiny bit about them, like theres one type of file with all the function paramaters, and one type of file with all the function definitions, and one type of file that may have main it it, but im confusing the c++ and c syntax between these and ive got to learn this stuff fast.

    can u point me in the right direction?
    anyone got any links?
    something for me to read?
    tutorial videos?

    any help would be greatly appreciated.
  • 9 years ago

     Hi chopficaro,

    You can create libraries(.lib files) or DLLs. In general you have declarations in header files and definitions in .cpp or .lib or .dll files.

    This concept is easy, then a simple search in google gives you good resources about that.

  • 9 years ago

    so, i got a project,

    main is in main.cpp

    i have a bunch of functions that are used everywhere, the declarations in func.hpp, and the definitions in func.cpp.

    at the top of main.cpp, and in func.cpp, i have #include "func"

    when i compile the project, there are only 2 files under the word "project": main.cpp and func.cpp, HOWEVER, i do have func.hpp in the same directory

    do i have it right so far?

    if so, heres my beef:

    in the past i have included other files such as iostream, but i have never had, under the word "project", the file iostream.cpp

  • 9 years ago

    Take it easy! there is just one thing, as you said : declarations are in .h file and definitions in .cpp files(or in a .lib or .dll file).

    A header file(.h) just declares somethings, but compiler needs definitions also. Then it'll search for that in .cpp(and also .h) and .lib files if you have included any of them in your project. If you've imported a func from a .dll file, compiler will get the definition at runtime from that dll. The file names should not be the same (for any type), since compiler will search all of files for definitions. There is no difference between .h and .cpp file contents, you can declare and define something in both, you can even include a .cpp file like this: #include "cppfile.cpp", but programmers separate declarations and definitions to manage their code easily. That was about declarations and definitions.

    But there is two kind of header files, as their locations : 1.in 'include' directory of the compiler   2.in your project folder

    1. The path is something like 'C:\Program Files\Microsoft Visual Studio 8\VC\include'(for VC++2005) and also others. These are headers for standard C++ libraries(like 'iostream'), then you should include them like this: #include <iostream>. Definitions for these libraries are in .lib files or the like, and will be used by the compiler when it compiles your code. Then you should just include the appropriate header file, and there is no .cpp file that you should include in your project, then you'll not see something like 'compiling iostream.cpp...' during compilation.

    2.You've added(or created and added) a header file to your project and also a .cpp file for definitions, then when you compile your project there is something like 'compiling cppfile.cpp...'.

  • 9 years ago

    thanx lol, guess i got confused 

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The generation of random numbers is too important to be left to chance.” - Robert R. Coveyou