Jump to content
dmitrybv

The C++ Project does not allow the use of Delphi units that contain the text '.VCL' in their name.

Recommended Posts

Hello.
I suspect that the C++ compiler does not allow using Delphi units from Delphi packages that contain the text ‘.VCL’ when creating VCL projects.
For example, my package contains the unit EhLib.VCL.pas
I use this package and the EhLib.VCL module in Delphi projects without any problems.
But when I try to use the EhLib.VCL package and module in C++ Builder, I get the following compilation error.


 

[bcc32c Error] Vcl.Buttons.hpp(68): reference to 'Vcl' is ambiguous
Vcl.Buttons.hpp(44): candidate found by name lookup is 'Vcl'
EhLib.VCL.hpp(48): candidate found by name lookup is 'Ehlib::Vcl'

I suspect that the statement

using namespace Vcl::Buttons;
using namespace Vcl;

from the file
Vcl.Buttons.hpp
And the statement

using namespace Ehlib::Vcl;
using namespace Ehlib;

from the file EhLib.VCL.hpp
somehow conflict with each other.

 

Do C++ Builder projects really have such limitations and how to bypass them?

 

image.thumb.png.b02d2a3af67c0675916439ab5550d2b3.png

Share this post


Link to post
9 hours ago, dmitrybv said:

I suspect that the C++ compiler does not allow using Delphi units from Delphi packages that contain the text ‘.VCL’ when creating VCL projects.

Yes, it does. You just have to be a little strategic with it.

9 hours ago, dmitrybv said:

I suspect that the statement


using namespace Vcl::Buttons;
using namespace Vcl;

from the file
Vcl.Buttons.hpp
And the statement


using namespace Ehlib::Vcl;
using namespace Ehlib;

from the file EhLib.VCL.hpp
somehow conflict with each other.

That is correct.  By default, Pascal-generated HPP headers bring their C++ namespaces into the namespace that is #include'ing the HPP file (which is usually the global scope).  And since both Vcl namespaces are in the same scope, the compiler doesn't know which one to use, hence the ambiguity error.

Quote

Do C++ Builder projects really have such limitations and how to bypass them?

If you look closer at the HPP files, you will notice that those 'using namespace' statements are wrapped in preprocessor blocks, eg:

#if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_VCL_BUTTONS)
using namespace Vcl::Buttons;
#endif
#if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_VCL)
using namespace Vcl;
#endif

To avoid the ambiguity, you can specify either DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE or the desired NO_USING_NAMESPACE_... conditional(s) in the "Conditional defines" section of your C++ project's settings.  Or, at least, simply #define them above the relevant #include statement(s) in your C++ code.

Edited by Remy Lebeau

Share this post


Link to post

In fact, this is likely the root culprit of your other issue, as you probably have multiple Fmx namespaces in the same scope that are interfering with each other.

 

In addition to what I mentioned above, another workaround would be to add {$HPPEMIT NOUSINGNAMESPACE} to your Pascal units to avoid any 'using namespace' statements in their generated HPP files.

 

Edited by Remy Lebeau

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×