Author Topic: Working with 2 versions of a library  (Read 4879 times)

Offline ote

  • Single posting newcomer
  • *
  • Posts: 9
Working with 2 versions of a library
« on: February 28, 2012, 06:33:37 pm »
Hello,

I'm developing a plugin for a soft which has different versions and I need to make the plugin work for the 2 latest (say 1 and 2 for the simplicity). In order to do that, I've created 2 different build targets which have some difference in Project -> build options -> search directories -> compiler.

It works well, I can compile and execute my plugin for both versions, but when I'm developing and need to parse some headers files from the library provided by the soft, I haven't figure how to open the "good" header file depending on the current build target. What I would like, is when I'm working on the build target for version 1 and I have my curser on some types or variables and do search -> Goto Declaration, it opens the header from version 1 and the header of version 2 if I'm currently working on build target for version 2. Right now it works for the build target for version 1 (always opening header from version 1), but for the version 2, it is always opening the header from version 1, unless that class don't exist in version 1 (I have some #if #else #endif sections for some part of the code which needs different functions depending on the version, and by the way, is it possible to grey the irrelevant part of the code as I thought settings ->editor ->general settings -> other options -> interpret #if #else .. would do ?).

I was able to do that in eclipse with cdt, but the index was taking too much time to update every time I was switching from one build version to another, and it was really annoying. Is there a way to do that in C::B ?

I'm working with C::B Nightly build debugger branch SVN 7845

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Working with 2 versions of a library
« Reply #1 on: February 28, 2012, 10:11:53 pm »
[...] when I'm working on the build target for version 1 and I have my curser on some types or variables and do search -> Goto Declaration, it opens the header from version 1 and the header of version 2 if I'm currently working on build target for version 2.[...]
You can achieve that if instead of using targets you split into projects and then use a CC parser for each project. The "target" concept is more for stuff belonging to one "software", what you have is actually 2 software (versions). You can bundle the projects again using a workspace. Dependencies (to arrange the build order) are possible within a WS, too.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline ote

  • Single posting newcomer
  • *
  • Posts: 9
Re: Working with 2 versions of a library
« Reply #2 on: February 29, 2012, 12:36:59 pm »
Well creating 2 projects seems to be kind of hard to maintain to me. Every time I change something in one project (include, compiler option...), I have to do the same for the other project... And the class I'm coding is the same for the two projects except for a dozen of lines of code... So I add some modifications to the file in one project and had to do the same for the other. Or is there a way to have the same .cpp and .h files in two projects ?

Besides, I'm looking for a good long term solution as the new version hasn't been officially released yet (+ the time for my company to do the upgrade), and I'll have to develop for the two versions for at least 4/5 months.

Isn't there another way of doing what I want ?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: Working with 2 versions of a library
« Reply #3 on: February 29, 2012, 01:14:02 pm »
Or is there a way to have the same .cpp and .h files in two projects ?

Yes, you can you the same .cpp and .h files in two projects. You will need to use different target names to prevent the object files over writing each other. Or use some other method to keep the object files separate.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Working with 2 versions of a library
« Reply #4 on: February 29, 2012, 07:56:21 pm »
Isn't there another way of doing what I want ?
Another option is the use of global variables and build script(s). then, you can literally do whatever you want.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Working with 2 versions of a library
« Reply #5 on: February 29, 2012, 08:35:08 pm »
Or is there a way to have the same .cpp and .h files in two projects ?

Yes, you can you the same .cpp and .h files in two projects. You will need to use different target names to prevent the object files over writing each other. Or use some other method to keep the object files separate.

Tim S.

Just use different object output directories in the projects properties.

Offline ote

  • Single posting newcomer
  • *
  • Posts: 9
Re: Working with 2 versions of a library
« Reply #6 on: March 01, 2012, 01:17:02 pm »
thanks for your advice. Finally, the simplest way I find for doing what I want, is to create just on build target and made a bash script which parse the project.cbp and change the folder name of the include file depending on which version of the library I want to work with.

When I want to switch, I just have to call that script from a console and C::B ask me if I want to reload the project. Maybe not the more official way of doing, but very effective.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Working with 2 versions of a library
« Reply #7 on: March 01, 2012, 01:20:26 pm »
Here is the official way to do this: http://wiki.codeblocks.org/index.php?title=Global_compiler_variables
Seems better to me :)
(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!]