Hi, I'm trying to make my own library so that I know the names of the functions and can use them more simply. Also, I normally don't get the File I/O right so if I write the Library once, then I can use it over and over again (without having much trouble).


I can write functions and classes and know the syntax of the language, I just want to know where I have to place the files to get them to work with a #include <...> statement (the <> really matters because then I don't have to put the file in all of my projects).

I'm using Ubuntu 10.10 and g++

I would consider creating a DLL for commonly used functions.

ok, how can I do that. Also, are DLLs okay on Ubuntu? if not, what else can I use.

What format are the librarys like iostream or cmath in?

In Linux/Unix systems, a dll is called a shared library, and has a .so extension. Read the g++ and linker documentation (man pages) how to do this. It is quite simple to create a shared library with Linux. In any case, the compiler directive when creating the library is -shared. If you are creating a shared library from object (.o) files, then make sure you compile the object files with the -fPIC option. That generates what we call Position Independent Code (PIC), which is necessary for a shared library, since the functions may need to be relocated (different memory position) when they are loaded into the executable.

>>Also, are DLLs okay on Ubuntu?
I think rubberman answered that.

>>What format are the librarys like iostream or cmath in?
What format? They are just C++ header files, without the .h at the end. You can check it out for yourself, they are usually located in "/usr/include/c++/4.4/" (or /usr/local instead of just /usr, and that version 4.4 depends on the version of your GCC compiler).

>>the <> really matters because then I don't have to put the file in all of my projects.
The difference between "" and <> with the include of headers is just that with "" the compiler will look for the file first in the current directory of the file that is being compiled, and then, it will look in the include directories (the stuff you specify with -I in the command-line compilation) and finally, will look into the standard system-wide include directories (like /usr/include/..). With <>, the compiler will not look in the current directory of the file being compiled, but it will look in all the same directories after (as with ""). Basically, you typically use "" when it is a custom header (part of the software/library you are working on), and <> otherwise. But really, there is little difference between the two (mostly a convention, but note that some compilers could behave differently).

To add your library's include directory (where you have all the header files) to the system's include paths. On Linux, these paths are set with the environment variable CPLUS_INCLUDE_PATH, see these instructions.

You will have to do something similar when you place your shared or static libraries in the /usr/lib folder.

Thanks, that helped a lot :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.