Author Topic: Getting a specific compiler's ID  (Read 6230 times)

Offline stardust

  • Multiple posting newcomer
  • *
  • Posts: 55
    • http://www.hightec-rt.com
Getting a specific compiler's ID
« on: March 27, 2007, 02:01:19 pm »
SVN 3764, wx2.6.1

In a plugin I have to test the compiler that is active.

In an event handler I get the actual compiler's ID:

Code
    wxString compilerID;
    ... = CompilerFactory::GetCompiler(compilerID = target ? target->GetCompilerID() : project->GetCompilerID());

which I want to compare against the IDs of some fixed compilers:

Code
#include "../plugins/compilergcc/compilerGNUTRICORE.h"
...
    CompilerGNUTRICORE tricoreGcc;
    wxString tricoreGccID = tricoreGcc.GetID();

I can build the plugin, but when I try to install it the CompilerGNUTRICORE class (or constructor) symbol cannot be found.

The symbol/code is present in ./src/plugins/compilergcc/.libs/compiler.so but not in the codeblocks.so* in the install directory.

So where can I get these compilers from?

I added the ./src/plugins/compilergcc/.libs/compiler.so explicitely to the plugin's link options. With that I can install the plugin but then C::B crashes *badly*.

What can I do about that?

I tried it under MS-Win but under Windows it does not work either.

There are complains that the compiler ID already exists (I wonder why the Compiler::GetID() is not static).

Do you have any ideas to cope with that?

Thanks.




Own SVN builds (quite new) • SuSE Linux 10.0 • Linux kernel 2.6.13-15-default
gcc 4.0.2 (20050901)
wxGTK-2.6.1.0-4 • KDE 3.4.2b • gtk2 2.8.3-4

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4315
    • Code::Blocks IDE
Re: Getting a specific compiler's ID
« Reply #1 on: March 27, 2007, 02:43:23 pm »
OK, it seems you have confused a couple of concepts. Let's see...

Compiler ID: it is a unique identifier for each compiler registered with CompilerFactory. This ID is automatically assigned when the compiler is registered.
So, the following question is invalid (I hope you can see why):

Quote
I wonder why the Compiler::GetID() is not static

Let's move now to the other problem:

Quote
I want to compare against the IDs of some fixed compilers:
Code
#include "../plugins/compilergcc/compilerGNUTRICORE.h"
...
    CompilerGNUTRICORE tricoreGcc;
    wxString tricoreGccID = tricoreGcc.GetID();

This obviously won't work. First, compilers must never be created on the stack but rather on the heap. Second, this compiler is not registered with CompilerFactory and not even compiled in the compiler plugin (hence the missing symbols).
And this is not the correct way to do either because you 're tying your code to a specific compiler by hardcoding #include paths and files. A plugin should never rely on another plugin being loaded. You can get the pointer to another plugin if you want by using PluginManager's facilities. But that's not your problem here.
If all you want is to test against the ID of an existing compiler, then things are simple. IDs are simple strings and, unless specifically set in the compiler's constructor, they 're the same as the compiler's title converted to an XML-compliant format:
  • only allow a-z, 0-9 and _ (other characters are removed, except space)
  • any spaces are converted to underscores (_)
  • if it starts with a number, "cb" is prepended
  • finally it's always converted to lower-case


So, if you want to test if an ID refers to the "GNU GCC Compiler", a simple check id==_T("gcc") will do the trick. Just adapt for the specific compiler you want to check for.

I hope I didn't confuse you more :).
Be patient!
This bug will be fixed soon...

Offline stardust

  • Multiple posting newcomer
  • *
  • Posts: 55
    • http://www.hightec-rt.com
Re: Getting a specific compiler's ID
« Reply #2 on: March 27, 2007, 04:26:32 pm »
I hope I didn't confuse you more :).

I must disappoint you...

Second, this compiler is not registered with CompilerFactory and not even compiled in the compiler plugin (hence the missing symbols).

The symbols are in the compiler.so. I had to change the compilergcc/Makefile.am for that because this is the only way to get support for new compilers. nm shows that the needed symbols in fact are there.

I changed the linker to link against <INSTALL>/share/codeblocks/plugins/libcompiler.so

So the point is that I have to get the compilers registered with CompilerFactory? What is the trigger for the registration? I cannot even assume that a specific compiler is present on a system. But nevertheless it must be possible to get such a compiler's ID.

This obviously won't work. First, compilers must never be created on the stack but rather on the heap.
That does not help, it still aborts. I just need the compiler object to get the ID, so it's just a local variable that may die after I got the ID.

If all you want is to test against the ID of an existing compiler, then things are simple. IDs are simple strings and, unless specifically set in the compiler's constructor, they 're the same as the compiler's title converted to an XML-compliant format.
  • only allow a-z, 0-9 and _ (other characters are removed, except space)
  • any spaces are converted to underscores (_)
  • if it starts with a number, "cb" is prepended
  • finally it's always converted to lower-case
The purpose of all this is just to avoid magic constants all over the code, like the mentioned "gcc".

So you must allow the question why there is a ::GetID() if not to be used and hard coding it's results...

And if I understand your description correctly, then "GNU GCC Compiler" will map to "gnu_gcc_compiler".

Concerning the #include "../plugins..." I agree with you. That's a hack. But where else can I find the prototypes that I need (./src/plugins/compilergcc)?
« Last Edit: March 27, 2007, 04:59:20 pm by stardust »
Own SVN builds (quite new) • SuSE Linux 10.0 • Linux kernel 2.6.13-15-default
gcc 4.0.2 (20050901)
wxGTK-2.6.1.0-4 • KDE 3.4.2b • gtk2 2.8.3-4