Author Topic: Sharing .o files between opened projects  (Read 3555 times)

Offline robertoneto123

  • Single posting newcomer
  • *
  • Posts: 4
Sharing .o files between opened projects
« 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

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Sharing .o files between opened projects
« Reply #1 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7785
    • My Best Post
Re: Sharing .o files between opened projects
« Reply #2 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.
C Programmer working to learn more about C++ and Git.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline robertoneto123

  • Single posting newcomer
  • *
  • Posts: 4
Re: Sharing .o files between opened projects
« Reply #3 on: July 14, 2015, 04:57:24 pm »
Tks everyone!