mcodev31 / libmsym

molecular point group symmetry lib
MIT License
75 stars 32 forks source link

Is there any way to use the function in src/rsh.h ? #23

Closed FreemanTheMaverick closed 2 years ago

FreemanTheMaverick commented 2 years ago

Hi! I want to use the function in src/rsh.h for basis function transformation matrices, but it does not seem to be included in msym.h. Although I can copy all related codes into another file and recompile it, I wonder if there is a more convenient way to achieve the goal. Thank you!

mcodev31 commented 2 years ago

This depends. I'd say there is no convenient way if you only have a .so. This since generateRSHRepresentations won't be in the external symbols table (the symbols are still there so technically it should be possible to call the function).

The only use of this data structure is allocated and freed within the same function and not exposed externally so you can't really access it using the standard API either.

If you are just building statically you don't really need to copy the code, you can just include it in your Makefile/build system (and include the header in your .c/cpp file).

FreemanTheMaverick commented 2 years ago

What if I build libmsym statically (with -DBUILD_SHARED_LIBS:BOOL=OFF)? In that case, can I use that function as I want to? What did you mean by "include it in your Makefile/build system"? Thanks.

FreemanTheMaverick commented 2 years ago

OK. I have figured it out myself. The key is putting

msym_error_t MSYM_EXPORT msymGenerateBasisRepresentations(int n, int sopsl, msym_symmetry_operation_t sops[sopsl], int lmax, rsh_representations_t *lrsh);

and moving the definition of rsh_representations_t into msym.h,

msym_error_t msymGenerateBasisRepresentations(int n, int sopsl, msym_symmetry_operation_t sops[sopsl], int lmax, rsh_representations_t *lrsh){
        msym_error_t ret=generateBasisRepresentations(n,sopsl,sops,lmax,lrsh);
        return ret;
}

into msym.c and

msym_error_t generateBasisRepresentations(int n, int sopsl, msym_symmetry_operation_t sops[sopsl], int lmax, rsh_representations_t *lrsh);

into subspace.h. In this way, I wrap generateBasisRepresentations with another function msymGenerateBasisRepresentations and make the latter one callable to external main.c.

mcodev31 commented 2 years ago

Ok, I thought you were trying to avoid editing the code itself, but sure, that will work.