1

I recently began working with the PortAudio library for C++. To compile even the simplest example I have to link my project to 8 different libraries. I am working with code::blocks as an IDE. I would like to create a new project and tell the linker to link to the same 8 libraries so I don't have to enter them manually for each new project. Can this be done?

Andrés Marafioti
  • 819
  • 1
  • 7
  • 23
  • 1
    May be this helps: http://stackoverflow.com/questions/24715864/problems-importing-libraries-to-my-c-project-how-to-fix-this – πάντα ῥεῖ Feb 15 '15 at 16:23
  • That's interesting but I already know how to link all the libraries to compile successfully. What I want to know is if I can export my library setup to a new project. – Andrés Marafioti Feb 15 '15 at 16:46

2 Answers2

5

Contrary to what Mike Kinghan suggested, the feature you're looking for exists, and is called Project Templates.

Set up a project's compiler and build options (search and linker tabs, etc.), and save the project as a template from the file menu. It will show up under User Templates in the new project menu, and create a project setup just like the one the template was saved from.

Optionally, you can save the template with files you'd like included, and it will save a copy of those files to the template as well, and include them with each new project created by that template.

No need to setup a bunch of new compiler entries, that's not what it's for.

See the Code::Blocks docs page.

Community
  • 1
  • 1
jungletek
  • 91
  • 1
  • 8
1

What you are looking for is a Code::Blocks feature that would let you create a new project "based" on a previous one, meaning that all of the toolchain options would be copied from the previous project.

That would be nice, but it doesn't exist.

There's a reasonably painless workaround, however, thanks to the fact that C::B does allow you to define a new toolchain, based on an existing one.

You want to develop numeruous projects all around the PortAudio library. So, in the C::B IDE:

  • From the menu-bar, navigate Settings -> Compiler

  • You see the Selected Compiler. It's probably the one you want for your PortAudio work, and let's say it's GNU GCC Compiler 4.8. If the selected compiler happens not to be the one you want, then use the dropdown menu to select the one you do want.

  • Underneath the selected compiler, click the Copy button. You are prompted to Add a new compiler, and to enter the new compiler's name. Call it, say, GCC 4.8 for PortAudio, and click OK.

  • Next, you are prompted to update the toolchain executables page. Again click OK.

  • Now you see that the selected compiler is your new one, GCC 4.8 for PortAudio, and all of its settings are at your disposal. Right now, they are all exactly the same as for GCC 4.8.

  • Do not update the Toolchain executables, because you want to use the GCC 4.8 toolchain unchanged. But you do want to change the Linker settings ( and maybe the Search directories, maybe the Compiler settings.) Set up the Linker settings (etc.) just the way you have done in the PortAudio project(s) that you have already successfully configured, and save them.

Now, GCC 4.8 for PortAudio is a "virtual toolchain" that is basically GCC 4.8, but customized for PortAudio projects. When you want to create a new PortAudio project without re-entering all the common settings, just choose GCC 4.8 for PortAudio as the project's compiler when you're going through the project creation wizard, or else select it as the project's compiler from the project's Build options after you have created it.

Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
  • Thank you! Such a great answer. I just had the time to test this and it works nicely. It is basically what I want. Although it is not a 1-click solution, it is pretty straight forward and get the job done. Awesome! – Andrés Marafioti Feb 19 '15 at 00:53