Code::Blocks Forums
User forums => Using Code::Blocks => Topic started by: gusfoca on April 13, 2011, 03:07:51 am
-
I've created some general-purpose classes I'd like to include in different projects. Problem is, it seems I have to include their files in every new project, which is undesirable, as I'm not going to edit them anymore. If I just set the search paths in the Build Options and add an "#include" on any file, it is considered undefined at compilation (it can't find the .cpp one, I suppose).
Is there a way I can #include those files in others but not in the project itself? Is it the case to build a library for them?
-
Is it the case to build a library for them?
Yes, use a library.
However, You'll always need to include the header file that describes the interface of the library. And there is no other solution possible. The compiler needs to know about interfaces, it surely cannot "guess". ;-)
-
The other option is to move those headers into your compilers main include folder, or some other place you wish to put included headers to be shared among all projects, and then modify the compiler settings you're using to always have that folder in the search path. That way you don't need to do this more than once.
-
Justin Brimm:
And what happens when you try to compile the project on different computer, os or compiler?
-
Well, any compiler settings you change will be unique to that copy of Codeblocks, unless you purposefully copy over your Codeblocks settings to the new computer/system or modify the settings on the new computer to match the settings you changed on your original version of Codeblocks (i.e. you'll need to add that path to the default search directory settings again). You'll also need to copy the headers into the directory on the new computer/system as well.
No matter what compiler or IDE you use, there is no way to get around this. Compilers must have the header files available during the linking stage of building an application. Building a library makes it so you no longer need to haul around all the source or object files (also hiding your source code in the process), but you'll still need to provide the appropriate headers, or the compiler will have no way to properly build the application during the linking stage.