Source Codes in Projects

4

If I have 10 projects in NetBeans, these 10 projects will use a Logging system, this system will contain a Log.h and a Log.c. Since all projects will have to use these two log files to generate logs, I will need to copy the two files for each project. But this causes a problem, for example: if I will change Log.c I will have to change in all the projects. In this case, is there any way to include these two files in all projects without having to copy the two files for each project?

    
asked by anonymous 17.06.2015 / 15:44

2 answers

5

I can not comment and as I do not know which compiler you are using I will put a general answer here.

You will need to create a static library. Let's suppose that it is called liblog.a in your compiler you will have to add the -llog flag, that is, -l replaces the lib (you must always have lib in the name!).

In addition you must have a header file containing the prototypes of your functions so you can invoke them in your program, in this case Log.h.

To make life easier for you, you can put the static library in the default LIBRARY_PATH of your compiler and its header file Log.h in the default INCLUDE_PATH of your compiler, they are usually lib and include the name of these directories.

Or you can create your own directories to place your libraries and headers, but you will always have to indicate your location to the compiler.

    
26.06.2015 / 13:16
1

Create a folder with the files you want to share between the various projects. Then open the project you want and right click on the project and select Adicionar Item Existente da Pastas... add the desired folders and click add. The folders will be indexed to the project.

To include in other projects just repeat the steps in the projects you want. Surgeri do this with folders because it is easier for the organization, the same can be done by files, the only difference is that you have to select the Adicionar Item Existente... option.

After adding the files or folder in the desired projects just change the files in common since all projects will have access to change. I used this netbeans functionality only in Java and C but I believe that there is support for all programming languages.

    
13.07.2015 / 04:10