Advertisement

Source files placement

Started by December 24, 2010 07:09 PM
3 comments, last by Aardvajk 14 years, 1 month ago
How do you place those source files? Im writing a static library, and Im placing .h files in SRC folder, and .cpp in CPP folder, But how do you guys do it? Just want to know, Oh and what do you suggest? making it DLL or simple static library?
Maybe like

Sources: .cpp, .cc, .cxx, etc. in ./src/<name_of_module>/
Headers: .h, .hh, etc. in ./src/include/

Now, maybe some people and development software prefers the headers and source in the same dir, but I don't think that's very tidy.

Try and dl some open source programs, to see how they do it.

Use DLL library, as you don't want to load a huge library, if you only use a small part.

But in the end, I guess it's a balancing act between conforming to established best practices, and doing it so it makes sense for the developers/users of the code.
It is I, the spectaculous Don Karnage! My bloodthirsty horde is on an intercept course with you. We will be shooting you and looting you in precisely... Ten minutes. Felicitations!
Advertisement
Thx Don, I guess I will follow what you said. And I saw SDL library, yet they're written in C (no class, only structs) and OpenAL is same...I havent looked at true C++ library, or projects, so I want to know how they manage their source files.....
If its a piece of software people will be compiling without editing it, such as the source distribution of some OSS, its conventional have a source structure like this:

lib/src/include/bin/


When compiled, binaries such as DLL's go into bin, .lib / .a files go into lib/ headers go into include/ and implementation files like cpp c cxx etc. go into src.

The reasons for this are simple; first, people after building the source need to be able to add your include dir to their include path, as well as adding libs as their linker paths. dll's or executables need to be seperate so you can add them to your OS's path variable.

However, when you are working on a piece of application software, there is no need to do this; furthermore, headers and impl files are often used together, included into an IDE, opened and edited, copied into another folder, etc. It makes sense when you are editing a large number of files to arrange them logically. For this reason, I go with the following structure:

/src--/somenamespace----/someclass.cpp----/someclass.h----/someotherclass.cpp----/someotherclass.h--/someothernamespace
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!
For static libs for my own use (maybe missing the point), I have the following:

Library--Include--Lib--WhateverLibrary--AwesomeGraphicsLibrary// etc


all within my Projects folder.

I create my project in its own folder within the Library folder as per the two silly examples above. I then move the .h file from the project folder into the Include folder and re-add it to the solution.

I set the solution up to output its .lib file to the Lib folder.

VS is set up on my own machine to reference the Include and Lib folders automatically. Then I can modify a library project and build it to automatically update the correct files in the correct locations.

This is a good approach if I was planning to distribute a binaries only version of the lib, I guess less useful for an open source distro.

This topic is closed to new replies.

Advertisement