Fixing eeshow library lookup (not found)

Just wanted to document this: I have built eeshow according to Building eeshow on Ubuntu 14.04. Then I had a problem - no matter what project I opened, I couldn’t get symbols found in libraries; pretty much every symbol referenced in schematic resulted with e.g. "device:LED" not found and so on.

First of all, the KiCad version I use (which produced the projects) is:

Application: kicad
Version: (2017-11-13 revision d98fc85)-master, release build
Libraries:
    wxWidgets 3.0.2
    libcurl/7.35.0 OpenSSL/1.0.1f zlib/1.2.8 libidn/1.28 librtmp/2.3
Platform: Linux 4.4.0-109-generic i686, 32 bit, Little endian, wxGTK
Build Info:
    wxWidgets: 3.0.2 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
    Boost: 1.54.0
    Curl: 7.35.0
    Compiler: GCC 4.8.4 with C++ ABI 1002

Build settings:
    USE_WX_GRAPHICS_CONTEXT=OFF
    USE_WX_OVERLAY=OFF
    KICAD_SCRIPTING=ON
    KICAD_SCRIPTING_MODULES=ON
    KICAD_SCRIPTING_WXPYTHON=ON
    KICAD_SCRIPTING_ACTION_MENU=ON
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=OFF
    KICAD_SPICE=OFF

So, by comparing http://neo900.org/git/ee projects with mine, I found that:

  1. The .pro project file generated by this version of KiCad does not create a [eeschema/libraries] section, which is what is apparently used by eeshow to determine libraries
  2. The eeshow code does not take into account symbol names prefixed by the library with a colon, such as device:LED

Regarding 1), I had to manually add lines for the [eeschema/libraries] in the .pro file:

...
[cvpcb]
version=1
NetIExt=net
[eeschema]
version=1
LibDir=
[eeschema/libraries]
LibName1=myproject-cache
LibName2=/path/to/kicad/usr/local/share/kicad/library/device.lib

I have to refer both the -cache.lib, and since I run KiCad from an external folder (that is, “portable”, as KiCad is not installed in system locations), I have to have a full path reference to that device.lib as well.

For the second problem, a hack is required where the entire symbol name is split at colon :, and then that is used for the comparison - it can be found in the patch file below (which also contains extra print statements for debugging, which you’ll probably want to comment):

diff --git a/file/file.c b/file/file.c
index 4690ebc..248e5f5 100644
--- a/file/file.c
+++ b/file/file.c
@@ -293,6 +293,7 @@ bool file_read(struct file *file,
 {
     char *nl;
 
+    error(" file_read: %s", file->name);
     if (file->vcs)
         return vcs_read(file->vcs, file, parse, user);
     while (getline(&getline_buf, &getline_n, file->file) > 0) {
diff --git a/gui/gui.c b/gui/gui.c
index 834bd74..e5b5b76 100644
--- a/gui/gui.c
+++ b/gui/gui.c
@@ -285,6 +285,7 @@ static const struct sheet *parse_files(struct gui_hist *hist,
         leader = &sch_file;
 
     struct file lib_files[fn->n_libs];
+    error(" parse_files: n_libs: %d", fn->n_libs);
 
     lib_init(&hist->lib);
     libs_open = 0;
diff --git a/kicad/ext.c b/kicad/ext.c
index 13f244d..36c2357 100644
--- a/kicad/ext.c
+++ b/kicad/ext.c
@@ -63,6 +63,7 @@ static void do_classify_files_ab(struct file_names *a, struct file_names *b,
     fn = a;
 
     for (i = 0; i != n_args; i++) {
+        error(" do_classify_files_ab: %d %s", i, args[i]);
         ext = identify(args[i]);
         switch (ext) {
         case ext_unknown:
diff --git a/kicad/lib-parse.c b/kicad/lib-parse.c
index 38f4a1b..20c40d3 100644
--- a/kicad/lib-parse.c
+++ b/kicad/lib-parse.c
@@ -396,6 +396,7 @@ bool lib_parse(struct lib *lib, const char *name, const struct file *related)
 static bool do_find_file(struct file *file, const char *name,
     const struct file_names *fn, const struct file *related)
 {
+    error(" do_find_file %s", name);
     if (file_open(file, name, related))
         return 1;
     if (file_search(file, name, fn->search, fn->n_search, related))
diff --git a/kicad/lib-render.c b/kicad/lib-render.c
index 17e6c78..f732bd5 100644
--- a/kicad/lib-render.c
+++ b/kicad/lib-render.c
@@ -716,12 +716,25 @@ const struct comp *lib_find(const struct lib *lib, const char *name)
     const struct comp *comp;
     const struct comp_alias *alias;
 
+    error(" lib_find name %s comps %p", name, lib->comps);
     for (comp = lib->comps; comp; comp = comp->next) {
+        error(" lib_find comp: '%s' '%s'", comp->name, name);
         if (!strcmp(comp->name, name))
             return comp;
-        for (alias = comp->aliases; alias; alias = alias->next)
+        // try without the : (for comparison 'LED' 'device:LED')
+        char *name_no_colon = strrchr(name, ':');
+        if (name_no_colon != NULL) {
+            name_no_colon++; // we want to look at what's _after_ the ':'
+            error(" lib_find comp no colon: '%s' '%s'", comp->name, name_no_colon);
+            if (!strcmp(comp->name, name_no_colon))
+                return comp;
+        }
+        error(" lib_find comp->aliases %p", comp->aliases);
+        for (alias = comp->aliases; alias; alias = alias->next) {
+            error(" lib_find alias: '%s' '%s'", alias->name, name);
             if (!strcmp(alias->name, name))
                 return comp;
+        }
     }
     error("\"%s\" not found", name);
     return NULL;

Well, that helped me finally open my schematic projects in eeshow - now just to find the similar facilities to export PCB to PDF from the command line.

These changes are due to the new symbol library table method in v5. I guess that a lot of third-party code that processes schematics is likely to need modification.

eeshow looks very neat, thanks tor the tip :slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.