User forums > Using Code::Blocks

Using classes across projects

<< < (2/3) > >>

kerui:

--- Quote ---The idea is to put source file of shared modules to a common directory and include them in all dependent projects directly without explicit creation of a library.
--- End quote ---

How can I do that in Code::Blocks?

As I mentioned, I tried giving the project the required "search directories" for the headers and object files, but I still get a linking error. I got rid of the linking error by specifying each object file individually using the "Linker" settings but I don't understand why this should be necessary just because the object files are in a separate directory.

Why can't the compiler link objects in different directories when I have specified the directories to search?

oBFusCATed:
If you don't make a library you'll have to:
1. add all cpp files in both projects, which will compile them n-times
2. add the .o files to the link additional linker options (I've never tried this because it is a hack), this approach is not recommended, because to get the proper setup you'll have to setup the correct external dependencies, so the project is correctly relinked if the .o files change.

If you don't want to bother with static lib go for solution 1. It is the easiest and safer approach. Then is your build starts to take too long, invest some time and separate the code in a static library.
If you go the number 2 route sooner or later you'll switch to number 1 or the static library.

kerui:

--- Quote ---1. add all cpp files in both projects, which will compile them n-times
--- End quote ---

Okay. Say I was building a game, and I had classes for "AI", "Graphics", "Game Entities", "Players" etc. If I put those class files all together in one directory, could Code::Blocks help me organise the "Class View Hierarchy" in the IDE so that classes could be placed in these components?

Is this when the "virtual folder" feature is used?

(It wouldn't be viable to create "Game Entities" or "Players" as libaries because a class in the "AI" component of the game requires an array of "game entities".)

MortenMacFly:

--- Quote from: kerui on November 29, 2011, 01:41:27 am ---Is this when the "virtual folder" feature is used?

--- End quote ---
Yes.

oBFusCATed:

--- Quote from: kerui on November 29, 2011, 01:41:27 am ---Is this when the "virtual folder" feature is used?

--- End quote ---
Why don't you use real folders in the file system?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version