dmitrybv 3 Posted Tuesday at 09:16 AM 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? Share this post Link to post
Remy Lebeau 1436 Posted Tuesday at 05:30 PM (edited) 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 Tuesday at 06:30 PM by Remy Lebeau Share this post Link to post
Remy Lebeau 1436 Posted Tuesday at 05:45 PM (edited) 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 Tuesday at 05:48 PM by Remy Lebeau Share this post Link to post