problem in recognizing libEM libraries

4 views
Skip to first unread message

luca lusnig

unread,
Feb 21, 2019, 8:27:15 AM2/21/19
to EMAN2 and SPARX Development
Hi,
I'm trying to write a small script for testing purpose but i cannot create an EMAN::EMData() object.
The script seems to be able to recognize the "libEM" library but when I try to create an object I'm tackling the following error:

############
/tmp/cci17P4z.o: In function `main':
main.cpp:(.text+0x1c): undefined reference to `EMAN::EMData::EMData()'
collect2: error: ld returned 1 exit status
############

1) my code is the following:

#include "emdata.h"                
int main()
{
    //EMAN::EMData b() ;                    // No error is spawned
    EMAN::EMData *a = new EMAN::EMData();    // Error
}



2) I run it with the following command:
g++ main.cpp  -I/home/EMAN2/eman2/libEM


3) The "emdata.h" is in the folder:
$ls /home/EMAN2/eman2/libEM/emdata.h
/home/EMAN2/eman2/libEM/emdata.h


Is there someone, who can give me some clues to how fix it?

Thanks in advance for any help!

Best,
Luca

Steve Ludtke

unread,
Feb 21, 2019, 8:48:20 AM2/21/19
to eman2-de...@googlegroups.com
I guess there is a reason you need to write the program in C++ rather than Python?  
Do you have EMAN2 built from source, or are you trying to build this from a binary install environment?  

None of the end-user programs in EMAN2 are written in C++. The core libraries are in C++, which are then wrapped in Python, which is used for all actual programs. Adding new capabilities to the system at the C++ level is normally handled by adding them to the existing libraries at build time. The system is completely modular, so there are standard methods for quickly adding new algorithms of the following types:
processors, cmps, aligners, averagers, projectors, reconstructors, analyzers, symmetries

While compiling a standalone C++ program using the EMAN2 libraries should certainly be possible, you will need to add a lot more options to your command-line, and make sure you are using the c++ compiler distributed with Anaconda for compatibility. You can get some tips by compiling EMAN2 from source and looking at the command-lines used there.

However, if you don't mind sharing, if you let us know what you are trying to accomplish, we might be able to suggest a better strategy which fits with the design of the system...

--------------------------------------------------------------------------------------
Steven Ludtke, Ph.D. <slu...@bcm.edu>                      Baylor College of Medicine 
Charles C. Bell Jr., Professor of Structural Biology
Dept. of Biochemistry and Molecular Biology                      (www.bcm.edu/biochem)
Academic Director, CryoEM Core                                        (cryoem.bcm.edu)
Co-Director CIBR Center                                    (www.bcm.edu/research/cibr)



--
You received this message because you are subscribed to the Google Groups "EMAN2 and SPARX Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to eman2-develope...@googlegroups.com.
To post to this group, send email to eman2-de...@googlegroups.com.
Visit this group at https://groups.google.com/group/eman2-developers.
For more options, visit https://groups.google.com/d/optout.

luca lusnig

unread,
Feb 22, 2019, 2:54:48 AM2/22/19
to eman2-de...@googlegroups.com
Hi Steve,
Thx for your quick answer. I built EMAN2 from source.

My task is to implement unittests for the sphire library.

To do that sometimes I have to create some variables from scratch.
Since I'm a new member of this community and at the moment I do not know the code in detail I'm creating them almost with random values.
This situation leads my unittests to get some errors in the c++ code, I'm trying to write a small script in C++ to help me to create these python variables in the correct way and in the meantime to understand deeply the code.

For example in one of my test I got an error in the "extract_plane" function in the "libpyEMData2.py" file:
"  File "/home/EMAN2/eman2/sphire/libpy/sparx_projection.py", line 116, in prgs
    temp = volft.extract_plane(R,kb)
RuntimeError: ImageDimensionException at /home/EMAN2/eman2/libEM/sparx/emdata_sparx.cpp:5046: 'extractplane requires ny == nx == nz' caught"

Since I cannot debug this C++ function in my python IDE (maybe  you know: how can I do that without using the gdb?), I was triyng to write a small script in C++ to better understand the problem.

Anyway if to build a working C++ environment takes too time I think that I'll change approch.

thx
Luca
--
Luca Lusnig, Dipl. -Ing., Informatik
__

"We cannot solve our problems with the same thinking we used when we created them." Albert Einstein


Steve Ludtke

unread,
Feb 22, 2019, 7:37:57 AM2/22/19
to eman2-de...@googlegroups.com
Hi Luca,
thanks for the explanation, that helps. It is quite possible to use GDB with the Python-wrapped libraries. When you run ccmake to configure the system for building, turn on debugging and recompile everything. After that, just run python with gdb. While you will ostensibly be debugging the python interpreter itself, you can still set breakpoints and do other actions within the C++ libraries loaded by the Python interpreter. 

Having said that, in cases like the error you show below, it should be pretty obvious the problem is that you didn't create a cubic (nx == ny == nz) volume before trying to use a function which requires cubic volumes. It even gives you the line number in the C++ code where the error occurred. Not sure why you would need to use a debugger in this situation...

--------------------------------------------------------------------------------------
Steven Ludtke, Ph.D. <slu...@bcm.edu>                      Baylor College of Medicine 
Charles C. Bell Jr., Professor of Structural Biology
Dept. of Biochemistry and Molecular Biology                      (www.bcm.edu/biochem)
Academic Director, CryoEM Core                                        (cryoem.bcm.edu)
Co-Director CIBR Center                                    (www.bcm.edu/research/cibr)


Paul Penczek

unread,
Feb 22, 2019, 7:53:02 AM2/22/19
to eman2-de...@googlegroups.com
Hi

Steve is correct. The way system is set up there is no need for debugging in vast majority of cases. Even if it is not fully informative (which in this particular case it is) it is much faster to insert control printouts in python rather than dig in lengthy debug output. 

There are actually debuggers for python/C combos and I saw people in my group using them. Inadvertently that left them utterly confused. Reading and analyzing the code is always a better option. 

Regards,
Pawel
Reply all
Reply to author
Forward
0 new messages