Problem with Lammps/Example/Couple/Simple

Hi Axel,
Thanks for the swift reply I appreciate that you took the time to look at my problem.
So I am still having problems with simple function to compile properly. I reinstalled lammps, and built lammps as a library as is required for both python and for this case.

Here is a list of the executables in my directory:

drwxr-xr-x 2 conor conor 57344 Jul 4 14:52 Obj_shared_mpi
-rwxr-xr-x 1 root root 93840720 Jul 4 14:52 liblammps_mpi.so
lrwxrwxrwx 1 root root 16 Jul 4 14:52 liblammps.so -> liblammps_mpi.so
drwxr-xr-x 2 conor conor 45056 Jul 4 14:52 Obj_mpi
-rw-r–r-- 1 conor conor 238742626 Jul 4 14:52 liblammps_mpi.a
lrwxrwxrwx 1 root root 15 Jul 4 14:52 liblammps.a -> liblammps_mpi.a
-rw-r–r-- 1 root root 6496 Jul 4 15:44 simple.o

*This command was then run from ~/Lammps/examples/COUPLE/*simple

mpicc -c -I/home/Lammps/src/ -I/usr/include/mpi/ simple.c

The output message was as follows:
simple.c:26:10: fatal error: library.h: No such file or directory
#include “library.h” /* this is a LAMMPS include file */
^~~~~~~~~~~
compilation terminated.

I then tried putting simple.c in the src directory, where the library.h is located.

mpicc -c -I/home/Lammps/src/ -I/usr/include/mpi/ simple.c

was then run again and completed.

However when the next command in the readme was run:

mpicc -L/home/Lammps/src/library.h simple.o -o simpleC

simple.o: In function main': simple.c:(.text+0x1ad): undefined reference to lammps_open’
simple.c:(.text+0x293): undefined reference to lammps_command' simple.c:(.text+0x2d2): undefined reference to lammps_command’
simple.c:(.text+0x2e1): undefined reference to lammps_get_natoms' simple.c:(.text+0x336): undefined reference to lammps_gather_atoms’
simple.c:(.text+0x385): undefined reference to lammps_gather_atoms' simple.c:(.text+0x3dd): undefined reference to lammps_scatter_atoms’
simple.c:(.text+0x3f3): undefined reference to lammps_command' simple.c:(.text+0x416): undefined reference to lammps_extract_atom’
simple.c:(.text+0x467): undefined reference to lammps_extract_variable' simple.c:(.text+0x4c8): undefined reference to lammps_commands_string’
simple.c:(.text+0x508): undefined reference to lammps_commands_list' simple.c:(.text+0x52f): undefined reference to lammps_get_natoms’
simple.c:(.text+0x5a7): undefined reference to lammps_command' simple.c:(.text+0x5e3): undefined reference to lammps_create_atoms’
simple.c:(.text+0x5fd): undefined reference to lammps_command' simple.c:(.text+0x657): undefined reference to lammps_close’
collect2: error: ld returned 1 exit status

I also repeated all the above as sudo user. I am using Ubuntu latest release and a march 2018 release of lammps.

Kind Regards,
Conor O’Donnell

two comments:

  1. please spend some time to study documentation or tutorials on the meaning of the -L, -I, and -l flags of the gcc compiler. after that it should be obvious where your problem is. for what you seem to be trying to do, this is essential knowledge.
  2. please stop the abuse of the “sudo” command. when you have a problem, it is rarely a solution, often it has no effect, but it has the potential to make matters much worse. if you don’t understand a problem/error, it won’t help to use sudo. you will have to understand the problem first.

axel.

Axel,
While your general advice regarding what one should study might be helpful, it is not clear that it addresses the specific problem. Indeed, it is entirely possible that the difficulties Connor had, may be due to errors in the simple codes, unless of course, you know to the contrary.

In my case, using an older version of lammps (LAMMPS (17 Dec 2016)I get a different error message which I list below. The error is because the code simple assumes that the function lammps_create_atoms has 6 arguments, whereas that declared in lammps.h has 8 arguments. The simplest explanation of the error is that at least some of the functions in COUPLE were not updated with the core part of lammps. While it should be simple enough to fix how lammps_create_atoms is called in simple.c, it is a bit worrisome, and the March 2018 version of lammps may have different inconsistencies in the context of functions like simple.

Regards,

Donal

cc -I /media/3c0ee629-3374-4804-9313-1e7ca23c54a9/dmack/MYLAMMPS/lammps
/src -I/usr/include/mpi -c simple.c
simple.c: In function ‘main’:
simple.c:148:5: error: too few arguments to function ‘lammps_create_atoms’
lammps_create_atoms(lmp,natoms,NULL,type,x,v);
^~~~~~~~~~~~~~~~~~~
In file included from simple.c:26:0:
/media/3c0ee629-3374-4804-9313-1e7ca23c54a9/dmack/MYLAMMPS/lammps/src/library.h:62:6: note: declared here
void lammps_create_atoms(void *, int, int *, int *,

Axel,
While your general advice regarding what one should study might be helpful, it is not clear that it addresses the specific problem.

​it is very clear to me.​ i am giving lectures at HPC workshops and other related occasions on how compilers work and what the meaning of the various flags are for over 10 years now.

Indeed, it is entirely possible that the difficulties Connor had, may be due to errors in the simple codes, unless of course, you know to the contrary.

​if you review the other ongoing e-mail thread about using the LAMMPS library int​erface, you should have seen, that i have used, tested, and even suggested additional code using the interface examples.

In my case, using an older version of lammps (LAMMPS (17 Dec 2016)I get a different error message which I list below. The error is because the code simple assumes that the function lammps_create_atoms has 6 arguments, whereas that declared in lammps.h has 8 arguments. The simplest explanation of the error is that at least some of the functions in COUPLE were not updated with the core part of lammps. While it should be simple enough to fix how lammps_create_atoms is called in simple.c, it is a bit worrisome, and the March 2018 version of lammps may have different inconsistencies in the context of functions like simple.

please note, ​the error messages resulting from mismatched function prototypes are very different from those resulting from using the wrong flags (or skipping them) to find libraries or include files.

while it (regrettably) occasionally happens, that there are mismatches, please keep in mind that the files in examples/COUPLE are examples. inconsistencies with any of the examples in the examples tree happen occasionally. we try to eliminate these through automated integration and regression testing (which is why you should not work with such an old version of LAMMPS), but the coverage of those tests is limited and growing only slowly. we are only a small number of people, that do development and maintenance of LAMMPS and LAMMPS is a big package. for some of us working on LAMMPS is mostly a hobby. in my case, for example, exactly 4% of my salary pays directly for my work on LAMMPS (i.e. about 2h/week).
what matters in this context is, that the files library.h and library.cpp are consistent and correct, which is being tested. if they are, you will get an error message (and as you noticed, one that makes this issue easy to understand and correct). i don’t consider this worrisome at all. in my 20+ years in the “business” of scientific computing, i’ve seen much, much worse. even in highly regarded software packages.

axel.

Thank you Axel for pointing out that the simple codes are fine. That should allow us to narrow down the source of the error which must, therefore, be on our side. As lammps was compiled as a library and allows lammps to be called under python, the error must somehow be in the compilation and/or linking that was used for simple.

My point regarding the error/ mismatch in an earlier version of was to illustrate that automated regression testing must not take place for the non-core part of lammps, otherwise, it would have been flagged, and would be reasonable given the size of the code.

I am actually a fan of lammps for over ten years now - because it is excellent, powerful, adaptable, and one can actually understand the source code if one makes a reasonable effort. That is a testament to the vision of a very small set of core developers - including you, which the much larger community has been able to engage constructively to create a much larger code.

I am very keen that our summer students have a good experience with it. They will no doubt have a very close look at the other thread of discussion on the use of the interface.

Best Regards,

Donal