Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: robertoneto123 on July 14, 2015, 12:49:49 pm

Title: Sharing .o files between opened projects
Post by: robertoneto123 on July 14, 2015, 12:49:49 pm
Hello,

(sorry, I feel that is a silly question, but Google did not help me on that...)

I have two projects: master and child.

Master has tons of source files that are working.

Child has basically one main.cpp that uses some of the Mater's sources.

How can I do it without copying the files from one project to another?

I was thinking of some solutions, but could not implement them:

1) Is there a way to directly add the .o files from Master to the Child project? (external resource)

or

2) Is there a way to compile the Master into a library (it is still a Console App, but maybe a new build target that compiles as a library?)

or

3) Is it possible to change the startup file of a project (I could add the Child's main to Master project)? Where I configure that?


I really thank any lights on this issue!!!!

Roberto
Title: Re: Sharing .o files between opened projects
Post by: oBFusCATed on July 14, 2015, 01:05:53 pm
1. Yes, you can do it (I think), but it is not a good idea. Because you'll have strange problem if you can the original sources, but don't update the .o files.
2. This is the best idea. You can create a target, a new project with some targets, but it is up to you which you feel is better for your project.
3. There is no such thing as startup file. All source files are compiled and then linked to a executable or library. If you've built an executable then you must have a  function named main, which is the entry point to your program. Different OSes have different requirements for the main function.
Title: Re: Sharing .o files between opened projects
Post by: stahta01 on July 14, 2015, 04:16:32 pm
1. Yes, you can do it (I think), but it is not a good idea. Because you'll have strange problem if you can the original sources, but don't update the .o files.
2. This is the best idea. You can create a target, a new project with some targets, but it is up to you which you feel is better for your project.
3. There is no such thing as startup file. All source files are compiled and then linked to a executable or library. If you've built an executable then you must have a  function named main, which is the entry point to your program. Different OSes have different requirements for the main function.

I agree option 2 is the best.
I would create a project with 3 targets
1. a static library with the shared code.
    In some cases a shared library would be better; but, shared library requires significantly more work and is much harder to do correctly.
2. the master code target
3. the child code target

You could also create 3 projects; but, that would be slightly more work to maintain normally.

Tim S.
Title: Re: Sharing .o files between opened projects
Post by: robertoneto123 on July 14, 2015, 04:57:24 pm
Tks everyone!