[lustre-discuss] Compile a C++ app. using the Lustre API

Dilger, Andreas andreas.dilger at intel.com
Wed Mar 22 05:12:01 PDT 2017


On Mar 21, 2017, at 15:53, François Tessier <ftessier at anl.gov> wrote:
> 
> Hi Andreas,
> 
> I removed the "static_cast" and casted the __u16 to an enum
> changelog_rec_flags as suggested. It seems to work (see patch attached).
> Do you have a test to run to try this out?

Hi François,
thanks for the patch.

Could you please submit it directly to Gerrit?  Instructions for this are at:
https://wiki.hpdd.intel.com/display/PUB/Using+Gerrit
https://wiki.hpdd.intel.com/display/PUB/Commit+Comments

Please feel free to ask here if you have any questions.  Note that you need to add a
Signed-off-by: line for contributions to Lustre and other open source projects.

Once the patch is submitted to Gerrit, it will automatically be built on a variety of
distros and kernels, and if that passes it will be tested with several configs as well.

Since this is just a patch that affects the building of the code and not any functionality,
please add the following line to your commit comment, just before the Signed-off-by: line:

Test-Parameters: trivial

so that it will only do minimal testing.

Cheers, Andreas

> On 03/19/2017 12:35 PM, Dilger, Andreas wrote:
>> Unfortunately, that is not something we could include into the C header, since it would break compilation. 
>> 
>> What about just casting the __u16 to an enum changelog_rec_flags as needed, and declaring the local variables as the enum instead of an int?  
>> 
>> Failing that, if you don't need the ChangeLog support, we could #ifdef out that section of the header when compiling with __cplusplus so that at least the rest of the header is usable.  
>> 
>> Cheers, Andreas
>> 
>>> On Mar 16, 2017, at 09:17, François Tessier <ftessier at anl.gov> wrote:
>>> 
>>> Here is the workaround I found (based on static_cast<>()):
>>> 
>>> - make a local copy of lustre_user.h and lustreapi.h
>>> - apply the attached patch on lustre_user.h
>>> - add an include parameter in your CXXFLAGS pointing to these files
>>> - compile with CC
>>> 
>>> It's clearly not the best solution but it's a working temporary band-aid...
>>> 
>>> ++
>>> 
>>> François
>>> 
>>> 
>>>> On 03/16/2017 07:44 AM, François Tessier wrote:
>>>>> On 03/15/2017 05:50 PM, Dilger, Andreas wrote:
>>>>>> On Mar 15, 2017, at 15:22, François Tessier <ftessier at anl.gov> wrote:
>>>>>> I get the same errors with g++ (v. 6.3). I can't find what kind of compiler flag I can use to be able to compile this. It clearly comes from how C++ deals with enum. The solutions I've found consist in "static_casting" the int values... Modifying my local version of lustre_user.h is probably not the best idea :-)
>>>>> Have you tried adding the standard wrappers at the start and end of the lustre_user.h header:
>>>>> 
>>>>> #ifdef __cplusplus
>>>>> extern "C" {
>>>>> #endif
>>>>> :
>>>>> <rest of header>
>>>>> #ifdef __cplusplus
>>>>> }
>>>>> #endif
>>>>> 
>>>>> I thought we had added those long ago, but I don't see them in the header today.  If that fixes your problem, please file an LU ticket at https://jira.hpdd.intel.com/ (and ideally a patch at https://review.whamcloud.com/ too) and we can get this added to the header.
>>>>> 
>>>>> In the meantime, you could also wrap your "#include <lustre/lustre_user.h>" similarly.
>>>> It doesn't fix the problem. I tried a more recent version of g++ or
>>>> several compiler options to force the use of C++11 [1] but with no success.
>>>>> Cheers, Andreas
>>>> Cheers,
>>>> François
>>>> 
>>>> [1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2347.pdf
>>>>>>> On 03/15/2017 02:14 PM, Patrick Farrell wrote:
>>>>>>> It looks like your compiler is being fussier than the C compiler.
>>>>>>> 
>>>>>>> Specifically, the problem appears to be with the enum type.  The C compiler is happy to let pass using a short (cr_flags) where an enum is called for (argument to changelog_rec_offset).  In C, I think an enum is an int (so passing in a short like this is always fine).  I guess in C++ either enum is not an int, or it's just fussier.
>>>>>>> 
>>>>>>> There might be a compiler flag to make it not error on this?  I am not familiar with icpc, so I can't help with specifics.
>>>>>>> 
>>>>>>> You might also try a different C++ compiler, to see if it has a different attitude towards that error.
>>>>>>> 
>>>>>>> One further thought, though:
>>>>>>> This is a C header.  Presumably, it is not intended to be included directly in a C++ project?
>>>>>>> 
>>>>>>> - Patrick
>>>>>>> From: lustre-discuss <lustre-discuss-bounces at lists.lustre.org> on behalf of François Tessier <ftessier at anl.gov>
>>>>>>> Sent: Wednesday, March 15, 2017 2:00:31 PM
>>>>>>> To: lustre-discuss at lists.lustre.org
>>>>>>> Subject: [lustre-discuss] Compile a C++ app. using the Lustre API
>>>>>>> 
>>>>>>> Hi All,
>>>>>>> 
>>>>>>> I'm working on a piece of code using the Lustre API. To do so, I include
>>>>>>> lustreapi.h. When I compile my code with a C compiler (icc), everything
>>>>>>> is fine. However, when I compile it with a C++ compiler (icpc), I get
>>>>>>> these errors:
>>>>>>> 
>>>>>>> ---------------------------------
>>>>>>> 
>>>>>>> In file included from /usr/include/lustre/lustreapi.h(47),
>>>>>>>                from topo.c(5):
>>>>>>> /usr/include/lustre/lustre_user.h(914): error: argument of type "__u16={unsigned short}" is incompatible with parameter of type "changelog_rec_flags"
>>>>>>>        return changelog_rec_offset(rec->cr_flags);
>>>>>>>                                    ^
>>>>>>> 
>>>>>>> In file included from /usr/include/lustre/lustreapi.h(47),
>>>>>>>                from topo.c(5):
>>>>>>> /usr/include/lustre/lustre_user.h(925): error: a value of type "int" cannot be used to initialize an entity of type "changelog_rec_flags"
>>>>>>>        enum changelog_rec_flags crf = rec->cr_flags & CLF_VERSION;
>>>>>>>                                       ^
>>>>>>> 
>>>>>>> In file included from /usr/include/lustre/lustreapi.h(47),
>>>>>>>                from topo.c(5):
>>>>>>> /usr/include/lustre/lustre_user.h(935): error: a value of type "int" cannot be used to initialize an entity of type "changelog_rec_flags"
>>>>>>>        enum changelog_rec_flags crf = rec->cr_flags &
>>>>>>>                                       ^
>>>>>>> 
>>>>>>> In file included from /usr/include/lustre/lustreapi.h(47),
>>>>>>>                from topo.c(5):
>>>>>>> /usr/include/lustre/lustre_user.h(945): error: argument of type "int" is incompatible with parameter of type "changelog_rec_flags"
>>>>>>>        return (char *)rec + changelog_rec_offset(rec->cr_flags &
>>>>>>>                                                  ^
>>>>>>> 
>>>>>>> In file included from /usr/include/lustre/lustreapi.h(47),
>>>>>>>                from topo.c(5):
>>>>>>> /usr/include/lustre/lustre_user.h(986): error: this operation on an enumerated type requires an applicable user-defined operator function
>>>>>>>        crf_wanted &= CLF_SUPPORTED;
>>>>>>>                   ^
>>>>>>> 
>>>>>>> In file included from /usr/include/lustre/lustreapi.h(47),
>>>>>>>                from topo.c(5):
>>>>>>> /usr/include/lustre/lustre_user.h(997): error: argument of type "int" is incompatible with parameter of type "changelog_rec_flags"
>>>>>>>                  changelog_rec_offset(crf_wanted & ~CLF_JOBID);
>>>>>>>                                       ^
>>>>>>> 
>>>>>>> In file included from /usr/include/lustre/lustreapi.h(47),
>>>>>>>                from topo.c(5):
>>>>>>> /usr/include/lustre/lustre_user.h(999): error: argument of type "int" is incompatible with parameter of type "changelog_rec_flags"
>>>>>>>                  changelog_rec_offset(crf_wanted & ~(CLF_JOBID | CLF_RENAME));
>>>>>>>                                       ^
>>>>>>> 
>>>>>>> Makefile:10: recipe for target 'topo' failed
>>>>>>> make: *** [topo] Error 2
>>>>>>> 
>>>>>>> ---------------------------------
>>>>>>> 
>>>>>>> It's probably more a compiler issue than a Lustre one but a solution
>>>>>>> could help other users or Lustre developers.
>>>>>>> 
>>>>>>> Any idea?
>>>>>>> 
>>>>>>> Thanks,
>>>>>>> 
>>>>>>> François
>>>>>>> 
>>>>>>> 
>>>>>>> -- 
>>>>>>> --
>>>>>>> François TESSIER, Ph.D.
>>>>>>> Postdoctoral Appointee
>>>>>>> Argonne National Laboratory
>>>>>>> LCF Division - Bldg 240, 4E 19
>>>>>>> Tel : +1 (630)-252-5068
>>>>>>> http://www.francoistessier.info
>>>>>>> 
>>>>>>> _______________________________________________
>>>>>>> lustre-discuss mailing list
>>>>>>> lustre-discuss at lists.lustre.org
>>>>>>> http://lists.lustre.org/listinfo.cgi/lustre-discuss-lustre.org
>>>>>> _______________________________________________
>>>>>> lustre-discuss mailing list
>>>>>> lustre-discuss at lists.lustre.org
>>>>>> http://lists.lustre.org/listinfo.cgi/lustre-discuss-lustre.org
>>>>> Cheers, Andreas
>>>>> --
>>>>> Andreas Dilger
>>>>> Lustre Principal Architect
>>>>> Intel Corporation
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>> _______________________________________________
>>>> lustre-discuss mailing list
>>>> lustre-discuss at lists.lustre.org
>>>> http://lists.lustre.org/listinfo.cgi/lustre-discuss-lustre.org
>>> <lustre_user_cxx.patch>
>>> _______________________________________________
>>> lustre-discuss mailing list
>>> lustre-discuss at lists.lustre.org
>>> http://lists.lustre.org/listinfo.cgi/lustre-discuss-lustre.org
> 
> <lustre_user_cxx.patch>

Cheers, Andreas
--
Andreas Dilger
Lustre Principal Architect
Intel Corporation









More information about the lustre-discuss mailing list