[lammps-users] questions about liblammps.a

Hi, lammps-users

I am a postdoc in sustech university, China. Recently, I have tried to use lammps as a c++ lib.
Unluckly, I have some questions about read_data or create_atoms when using liblammps.a.

If I use the following codes to convert atomic data to lammps by read_data command, all is ok.


Some comments about your email.
a) you are not using the C++ interface but the C library interface of LAMMPS
b) the problem seems to be more in your C++ programming than in how you use LAMMPS. Specifically the commented out pieces show a gross disregard for rather elementary properties of C++
c) some of the code fragments cannot work as reported since memory used is not allocated, variables used not declared or initialized and in general some of the steps make no sense. it is impossible to give meaningful advice on such incomplete/incorrect code fragments.
d) there are more suitable APIs for what you seem to be interested to do
e) since you get the segmentation fault after you “closed” LAMMPS the problem cannot be within the LAMMPS code but has to be due the memory management within your code.
f) the location and details of this kind of error are next to impossible to detect from remote, especially given the limited information you provide, but are easy to track down with standard debugging tools like gdb or valgrind. for an example in detecting the location of a memory issue inside of LAMMPS please see: https://docs.lammps.org/latest/Errors_debug.html . Of course this also works for non-LAMMPS source code.

one request. in the future, please be more precise and do not provide example code that is incorrect/incomplete. the more detailed and comprehensive your emails are, the better help you can get. but please also make certain that you have your C++ programming basics straight, so that when reporting issues with LAMMPS they are actually really issues within LAMMPS.

thanks in advance,