Python to C++ switch, folder structure confusion.

Hello,

To begin with, if you allow me, I'd like to let the readers know that I have done my search on search engines, this wonderful forum and also checked related examples through active open-source projects. Yet I couldn't find an answer nor a solution to my worry and hence the reason I am opening this thread.

About the situation:
I am a Python programmer. I have been so for quite some time and embraced what Python community calls as the "python way" or "pythonic" way of doing things.

Now I have been training in C++ and I am starting to port a Python application (Qt via PySide) to C++.

Bit of information:
In Python projects, there are "modules" which are widely embraced to structure one's application source code.

Easy object file or bundle of functions in a source code file can be, and is advised to be, placed in a related module where all related elements are bundled and accessed through Module's name.

Ex: All "sound" related classes and functions can be placed in a "module" folder called "sounds" and accessed through "import sounds" or "from sounds import class_name".

My problem:
The above explained way of structuring source code makes it very easy to find things and allows you to find your way through projects.

Instead of my Qt project's simple two-folder structure of "/Headers" and "/Sources", I would like to have sub folders for each related class group.

Example:

/MyApp
main.cpp
-SoundModule     <-Module Folder
--Headers
---Processor.h
--Sources   
---Processor.cpp
-CustomControls  <-Module Folder
--Headers
..
--Sources
..


etc.

I'm currently working on OS X and this application is to be build there first but then built on Windows and especially Linux.

I have read about "import problems" "compile import errors" etc.

I wish to have a well structed source code as explained above and do not wish to have import errors which could discourage people from building it or cause problems to my self building it on other platforms.

My question/request:

- Could you please explain [to me], how can I go on structuring my application this way?

- How can I perform imports from inside a module's source file to another and/or from main.cpp file?

- What things do I need to pay attention to?

- If I am [to have] this source code to be ported to more than on OS Platform, what do I need to do?


I hope I managed to explain myself.

Thank you for your time and kind answers in advance.
Last edited on
I have read about "import problems" "compile import errors" etc.
I'd guess that you confuse it with java.

- Could you please explain to my, how can I go on structuring my application this way?
There's no problem doing so.

- How can I perform imports from inside a module's source file to another and/or from main.cpp file?
the keyword in C/C++ is #include like so:

#include <SoundModule/Headers/Processor.h>


- To what things do I need to pay attention to?
you need to set the paths for includes and libraries properly in your IDE. This is usually obfuscated, unfortunately.

- If I am this source code to be ported to more than on OS Platform, what do I need to do?
Use platform independent libraries like boost:

http://www.boost.org/
@coder777,

Thank you for your fast response and quoting sentence for sentence for a clearer answers. If I understand you correctly, I shall have no issues going this way.

Could you clarify bit more though what you mean by IDE's "obfuscation" of Path settings? I'm specifically using Qt's IDE for now.

Would you suggest that I place all public headers in a sub folder on top of modules' where I'll be keeping the sources? (I've seen this approach suggested during research).

Thanks again!
helloworldcpp wrote:
Could you clarify bit more though what you mean by IDE's "obfuscation" of Path settings?
It's different for every IDE and/or compiler, making it really difficult to explain properly.
Could you clarify bit more though what you mean by IDE's "obfuscation" of Path settings? I'm specifically using Qt's IDE for now.
Well, in case of the Qt IDE you need to modify the *.pro file. So you need to know how to do that.


Would you suggest that I place all public headers in a sub folder on top of modules' where I'll be keeping the sources? (I've seen this approach suggested during research).
That's really a matter of taste. I usually put the header and implementation files in the same directory. But there're also good reasons to separate them especially if you want to make a library yourself
Topic archived. No new replies allowed.